From 2694532a5479d157903b6c600d9b1d5c145a4e4c Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 12 Jun 2023 19:40:41 +0200 Subject: libio: replace OSTREAM_OPEN_* flags with SQFS_FILE_OPEN_* flags Signed-off-by: David Oberhollenzer --- lib/io/src/win32/istream.c | 3 ++- lib/io/src/win32/ostream.c | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'lib/io/src/win32') diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c index 46bed30..d140142 100644 --- a/lib/io/src/win32/istream.c +++ b/lib/io/src/win32/istream.c @@ -153,10 +153,11 @@ fail_free: istream_t *istream_open_file(const char *path) { - WCHAR *wpath = path_to_windows(path); + WCHAR *wpath = NULL; istream_t *out; HANDLE hnd; + wpath = path_to_windows(path); if (wpath == NULL) return NULL; diff --git a/lib/io/src/win32/ostream.c b/lib/io/src/win32/ostream.c index edbefc7..26d6f96 100644 --- a/lib/io/src/win32/ostream.c +++ b/lib/io/src/win32/ostream.c @@ -5,6 +5,7 @@ * Copyright (C) 2019 David Oberhollenzer */ #include "../internal.h" +#include "sqfs/io.h" #define WIN32_LEAN_AND_MEAN #include @@ -43,7 +44,7 @@ static int realize_sparse(file_ostream_t *file) if (file->sparse_count == 0) return 0; - if (file->flags & OSTREAM_OPEN_NO_SPARSE) { + if (file->flags & SQFS_FILE_OPEN_NO_SPARSE) { bufsz = file->sparse_count > 1024 ? 1024 : file->sparse_count; buffer = calloc(1, bufsz); @@ -175,24 +176,30 @@ fail_free: ostream_t *ostream_open_file(const char *path, int flags) { - WCHAR *wpath = path_to_windows(path); int access_flags, creation_mode; + WCHAR *wpath = NULL; ostream_t *out; HANDLE hnd; - if (wpath == NULL) - return NULL; - access_flags = GENERIC_WRITE; - if (flags & OSTREAM_OPEN_OVERWRITE) { + if (flags & SQFS_FILE_OPEN_OVERWRITE) { creation_mode = CREATE_ALWAYS; } else { creation_mode = CREATE_NEW; } - hnd = CreateFileW(wpath, access_flags, 0, NULL, creation_mode, - FILE_ATTRIBUTE_NORMAL, NULL); + if (flags & SQFS_FILE_OPEN_NO_CHARSET_XFRM) { + hnd = CreateFileA(path, access_flags, 0, NULL, creation_mode, + FILE_ATTRIBUTE_NORMAL, NULL); + } else { + wpath = path_to_windows(path); + if (wpath == NULL) + return NULL; + + hnd = CreateFileW(wpath, access_flags, 0, NULL, creation_mode, + FILE_ATTRIBUTE_NORMAL, NULL); + } if (hnd == INVALID_HANDLE_VALUE) { w32_perror(path); @@ -213,5 +220,5 @@ ostream_t *ostream_open_stdout(void) { HANDLE hnd = GetStdHandle(STD_OUTPUT_HANDLE); - return ostream_open_handle("stdout", hnd, OSTREAM_OPEN_NO_SPARSE); + return ostream_open_handle("stdout", hnd, SQFS_FILE_OPEN_NO_SPARSE); } -- cgit v1.2.3