From 6b83fc6b57f79f34ad0cc078fef6a9d100645392 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 5 Mar 2021 13:18:54 +0100
Subject: [PATCH] win32/HResult: un-inline FormatHResultError()

Reduce header dependencies.
---
 src/win32/HResult.cxx | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/win32/HResult.hxx | 20 ++------------------
 src/win32/meson.build |  1 +
 3 files changed, 45 insertions(+), 18 deletions(-)
 create mode 100644 src/win32/HResult.cxx

diff --git a/src/win32/HResult.cxx b/src/win32/HResult.cxx
new file mode 100644
index 000000000..4397a3650
--- /dev/null
+++ b/src/win32/HResult.cxx
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2020-2021 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "HResult.hxx"
+
+#include <cstdarg>
+#include <memory>
+
+std::system_error
+FormatHResultError(HRESULT result, const char *fmt, ...) noexcept
+{
+	std::va_list args1, args2;
+	va_start(args1, fmt);
+	va_copy(args2, args1);
+
+	const int size = vsnprintf(nullptr, 0, fmt, args1);
+	va_end(args1);
+	assert(size >= 0);
+
+	auto buffer = std::make_unique<char[]>(size + 1);
+	vsprintf(buffer.get(), fmt, args2);
+	va_end(args2);
+
+	return std::system_error(std::error_code(result, hresult_category()),
+				 std::string(buffer.get(), size));
+}
diff --git a/src/win32/HResult.hxx b/src/win32/HResult.hxx
index f58cf3cb9..8ec4b30d4 100644
--- a/src/win32/HResult.hxx
+++ b/src/win32/HResult.hxx
@@ -23,7 +23,6 @@
 #include "util/Compiler.h"
 
 #include <cassert>
-#include <cstdarg>
 #include <cstdio>
 #include <string_view>
 #include <system_error>
@@ -86,22 +85,7 @@ static inline const std::error_category &hresult_category() noexcept {
 	return hresult_category_instance;
 }
 
-gcc_printf(2, 3) static inline std::system_error
-	FormatHResultError(HRESULT result, const char *fmt, ...) noexcept {
-	std::va_list args1, args2;
-	va_start(args1, fmt);
-	va_copy(args2, args1);
-
-	const int size = vsnprintf(nullptr, 0, fmt, args1);
-	va_end(args1);
-	assert(size >= 0);
-
-	auto buffer = std::make_unique<char[]>(size + 1);
-	vsprintf(buffer.get(), fmt, args2);
-	va_end(args2);
-
-	return std::system_error(std::error_code(result, hresult_category()),
-				 std::string(buffer.get(), size));
-}
+gcc_printf(2, 3) std::system_error
+FormatHResultError(HRESULT result, const char *fmt, ...) noexcept;
 
 #endif
diff --git a/src/win32/meson.build b/src/win32/meson.build
index 786184a6d..30f059669 100644
--- a/src/win32/meson.build
+++ b/src/win32/meson.build
@@ -6,6 +6,7 @@ endif
 win32 = static_library(
   'win32',
   'ComWorker.cxx',
+  'HResult.cxx',
   include_directories: inc,
 )