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/io/src/win32/dir_iterator.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/io') diff --git a/lib/io/src/win32/dir_iterator.c b/lib/io/src/win32/dir_iterator.c index c99fd64..22b4870 100644 --- a/lib/io/src/win32/dir_iterator.c +++ b/lib/io/src/win32/dir_iterator.c @@ -58,11 +58,15 @@ static int dir_iterator_next(dir_iterator_t *it, dir_entry_t **out) if (w32->state == 0 && !w32->is_first) { if (!FindNextFileW(w32->dirhnd, &w32->ent)) { - if (GetLastError() == ERROR_NO_MORE_FILES) { + os_error_t err = get_os_error_state(); + + if (err.w32_errno == ERROR_NO_MORE_FILES) { w32->state = 1; } else { w32->state = SQFS_ERROR_IO; } + + set_os_error_state(err); } } -- cgit v1.2.3