From 89cdef0859259fdea0165b0d3918777d1ed42955 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 12 Jun 2023 23:17:49 +0200 Subject: libsquashfs: Add sqfs_open_native_file function Having a function to interpret the flags and open a native file handle simplifies the istream/ostream/file code which shares that decoding part, particularly on windows where the character set needs to be transformed. Signed-off-by: David Oberhollenzer --- lib/io/src/win32/ostream.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'lib/io/src/win32/ostream.c') diff --git a/lib/io/src/win32/ostream.c b/lib/io/src/win32/ostream.c index 5b099a4..5b584e5 100644 --- a/lib/io/src/win32/ostream.c +++ b/lib/io/src/win32/ostream.c @@ -176,39 +176,19 @@ fail_free: sqfs_ostream_t *ostream_open_file(const char *path, int flags) { - int access_flags, creation_mode; - WCHAR *wpath = NULL; + sqfs_file_handle_t hnd; sqfs_ostream_t *out; - HANDLE hnd; - - access_flags = GENERIC_WRITE; - - if (flags & SQFS_FILE_OPEN_OVERWRITE) { - creation_mode = CREATE_ALWAYS; - } else { - creation_mode = CREATE_NEW; - } - 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 (sqfs_open_native_file(&hnd, path, flags)) { + w32_perror(path); + return NULL; } if (hnd == INVALID_HANDLE_VALUE) { w32_perror(path); - free(wpath); return NULL; } - free(wpath); - out = ostream_open_handle(path, hnd, flags); if (out == NULL) CloseHandle(hnd); -- cgit v1.2.3