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 --- bin/rdsquashfs/src/restore_fstree.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/rdsquashfs/src/restore_fstree.c b/bin/rdsquashfs/src/restore_fstree.c index ea9d4f1..d80d24b 100644 --- a/bin/rdsquashfs/src/restore_fstree.c +++ b/bin/rdsquashfs/src/restore_fstree.c @@ -20,7 +20,10 @@ static int create_node(const sqfs_tree_node_t *n, const char *name, int flags) switch (n->inode->base.mode & S_IFMT) { case S_IFDIR: if (!CreateDirectoryW(wpath, NULL)) { - if (GetLastError() != ERROR_ALREADY_EXISTS) + os_error_t err = get_os_error_state(); + set_os_error_state(err); + + if (err.w32_errno != ERROR_ALREADY_EXISTS) goto fail; } break; @@ -41,12 +44,12 @@ static int create_node(const sqfs_tree_node_t *n, const char *name, int flags) free(wpath); return 0; fail: { - DWORD err = GetLastError(); + os_error_t err = get_os_error_state(); free(wpath); - SetLastError(err); + set_os_error_state(err); w32_perror(name); - if (err == ERROR_FILE_EXISTS) { + if (err.w32_errno == ERROR_FILE_EXISTS) { fputs("\nHINT: this could be caused by case " "sensitivity on Windows.\n", stderr); } -- cgit v1.2.3