From 8bff2715bfdfd2e6ce0c707f1310b169d4e454d0 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 15 Jun 2023 18:13:26 +0200 Subject: libcompat: Add a helper to get/set OS error state On Unix like OSes, this saves/restores errno, on Windows both errno and GetLastError state are saved/restored. This should make it simpler to preserve that across function calls. Additionally, while tracking down uses of GetLastError, some places where the error code was printed out directly where replaced with instances of w32_perror. Signed-off-by: David Oberhollenzer --- lib/compat/src/chdir.c | 3 +-- lib/compat/src/path_to_windows.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/compat/src') diff --git a/lib/compat/src/chdir.c b/lib/compat/src/chdir.c index f695e2a..17d814f 100644 --- a/lib/compat/src/chdir.c +++ b/lib/compat/src/chdir.c @@ -21,8 +21,7 @@ int chdir(const char *path) return -1; if (!SetCurrentDirectoryW(wpath)) { - fprintf(stderr, "Switching to directory '%s': %ld\n", - path, GetLastError()); + w32_perror(path); ret = -1; } else { ret = 0; diff --git a/lib/compat/src/path_to_windows.c b/lib/compat/src/path_to_windows.c index ff3a5d2..5a35f50 100644 --- a/lib/compat/src/path_to_windows.c +++ b/lib/compat/src/path_to_windows.c @@ -18,8 +18,7 @@ WCHAR *path_to_windows(const char *input) length = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0); if (length <= 0) { - fprintf(stderr, "Converting UTF-8 path to UTF-16: %ld\n", - GetLastError()); + w32_perror("Converting UTF-8 path to UTF-16"); return NULL; } -- cgit v1.2.3