From 1e255d0f6c472bb3c710aea1ea8dc5d27c0fba4a Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 4 Sep 2020 18:26:16 +0200 Subject: Add stream I/O abstraction library Signed-off-by: David Oberhollenzer --- lib/compat/w32_perror.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/compat/w32_perror.c (limited to 'lib/compat/w32_perror.c') diff --git a/lib/compat/w32_perror.c b/lib/compat/w32_perror.c new file mode 100644 index 0000000..1268501 --- /dev/null +++ b/lib/compat/w32_perror.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * w32_perror.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "compat.h" + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include + +void w32_perror(const char *str) +{ + DWORD nStatus = GetLastError(); + LPVOID msg = NULL; + + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, nStatus, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&msg, 0, NULL); + + fprintf(stderr, "%s: %s\n", str, (const char *)msg); + + if (msg != NULL) + LocalFree(msg); +} +#endif -- cgit v1.2.3