aboutsummaryrefslogtreecommitdiff
path: root/lib/compat
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-04 18:26:16 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-16 09:34:35 +0200
commit1e255d0f6c472bb3c710aea1ea8dc5d27c0fba4a (patch)
tree0ba8dfc243a00ef955da973b1615a95498579525 /lib/compat
parentb96f0fc154feef531be76034bf6e38925636146f (diff)
Add stream I/O abstraction library
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/compat')
-rw-r--r--lib/compat/Makemodule.am1
-rw-r--r--lib/compat/w32_perror.c31
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/compat/Makemodule.am b/lib/compat/Makemodule.am
index 7137f2c..c1be522 100644
--- a/lib/compat/Makemodule.am
+++ b/lib/compat/Makemodule.am
@@ -2,5 +2,6 @@ libcompat_a_SOURCES = lib/compat/getline.c lib/compat/getsubopt.c
libcompat_a_SOURCES += lib/compat/strndup.c lib/compat/mockups.c
libcompat_a_SOURCES += lib/compat/chdir.c include/compat.h
libcompat_a_SOURCES += lib/compat/path_to_windows.c
+libcompat_a_SOURCES += lib/compat/w32_perror.c
noinst_LIBRARIES += libcompat.a
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 <goliath@infraroot.at>
+ */
+#include "config.h"
+#include "compat.h"
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+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