aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/src/win32/ostream.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-15 18:13:26 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-15 18:13:26 +0200
commit8bff2715bfdfd2e6ce0c707f1310b169d4e454d0 (patch)
tree50c4dfdb2e4daa5b8c94697261ff8081389b449c /lib/sqfs/src/win32/ostream.c
parentc9f37f069c6e294e58c64c9f5ad94f0bd3e2fd02 (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/src/win32/ostream.c')
-rw-r--r--lib/sqfs/src/win32/ostream.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/sqfs/src/win32/ostream.c b/lib/sqfs/src/win32/ostream.c
index 3ebeb8b..2f85c29 100644
--- a/lib/sqfs/src/win32/ostream.c
+++ b/lib/sqfs/src/win32/ostream.c
@@ -59,9 +59,9 @@ static int realize_sparse(file_ostream_t *file)
ret = write_data(file, buffer, diff);
if (ret) {
- DWORD temp = GetLastError();
+ os_error_t err = get_os_error_state();
free(buffer);
- SetLastError(temp);
+ set_os_error_state(err);
return ret;
}
@@ -157,10 +157,10 @@ int sqfs_ostream_open_handle(sqfs_ostream_t **out, const char *path,
GetCurrentProcess(), &file->hnd,
0, FALSE, DUPLICATE_SAME_ACCESS);
if (!ret) {
- DWORD temp = GetLastError();
+ os_error_t err = get_os_error_state();
free(file->path);
free(file);
- SetLastError(temp);
+ set_os_error_state(err);
return SQFS_ERROR_IO;
}
@@ -191,9 +191,9 @@ int sqfs_ostream_open_file(sqfs_ostream_t **out, const char *path,
ret = sqfs_ostream_open_handle(out, path, hnd, flags);
if (ret) {
- DWORD temp = GetLastError();
+ os_error_t err = get_os_error_state();
CloseHandle(hnd);
- SetLastError(temp);
+ set_os_error_state(err);
return SQFS_ERROR_IO;
}