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/util/src/mkdir_p.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/util') diff --git a/lib/util/src/mkdir_p.c b/lib/util/src/mkdir_p.c index 993d8ec..784e4ae 100644 --- a/lib/util/src/mkdir_p.c +++ b/lib/util/src/mkdir_p.c @@ -113,11 +113,11 @@ int mkdir_p(const char *path) } if (!CreateDirectoryW(wpath, NULL)) { - error = GetLastError(); + os_error_t err = get_os_error_state(); + set_os_error_state(err); - if (error != ERROR_ALREADY_EXISTS) { - fprintf(stderr, "Creating %s: %ld\n", - path, error); + if (err.w32_errno != ERROR_ALREADY_EXISTS) { + w32_perror(path); goto fail; } } -- cgit v1.2.3