aboutsummaryrefslogtreecommitdiff
path: root/lib/fstream/win32
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-11-28 00:05:24 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-12-05 10:29:36 +0100
commit2b8eb19a4de81db470f7ff5021a8a4822cc8c80d (patch)
treefe757fe44f96ccfbf49f7554ac2df3647490aea9 /lib/fstream/win32
parent4a4dbe027a082e546512b5ccb2999753651a9a28 (diff)
Fix: consistently use the widechar file API on Windows
When opening files on windows, use the widechar versions and convert from (assumed) UTF-8 to UTF-16 as needed. Since the broken, code-page-random API may acutall be intended in some use cases, leave that option in through an additional flag. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstream/win32')
-rw-r--r--lib/fstream/win32/istream.c10
-rw-r--r--lib/fstream/win32/ostream.c12
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/fstream/win32/istream.c b/lib/fstream/win32/istream.c
index 96c9f1c..36d7c42 100644
--- a/lib/fstream/win32/istream.c
+++ b/lib/fstream/win32/istream.c
@@ -69,19 +69,24 @@ istream_t *istream_open_file(const char *path)
file_istream_t *file = calloc(1, sizeof(*file));
sqfs_object_t *obj = (sqfs_object_t *)file;
istream_t *strm = (istream_t *)file;
+ WCHAR *wpath = NULL;
if (file == NULL) {
perror(path);
return NULL;
}
+ wpath = path_to_windows(path);
+ if (wpath == NULL)
+ goto fail_free;
+
file->path = strdup(path);
if (file->path == NULL) {
perror(path);
goto fail_free;
}
- file->hnd = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL,
+ file->hnd = CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (file->hnd == INVALID_HANDLE_VALUE) {
@@ -89,6 +94,8 @@ istream_t *istream_open_file(const char *path)
goto fail_path;
}
+ free(wpath);
+
strm->buffer = file->buffer;
strm->precache = file_precache;
strm->get_filename = file_get_filename;
@@ -97,6 +104,7 @@ istream_t *istream_open_file(const char *path)
fail_path:
free(file->path);
fail_free:
+ free(wpath);
free(file);
return NULL;
}
diff --git a/lib/fstream/win32/ostream.c b/lib/fstream/win32/ostream.c
index 7b5bd3e..61dae37 100644
--- a/lib/fstream/win32/ostream.c
+++ b/lib/fstream/win32/ostream.c
@@ -128,12 +128,17 @@ ostream_t *ostream_open_file(const char *path, int flags)
sqfs_object_t *obj = (sqfs_object_t *)file;
ostream_t *strm = (ostream_t *)file;
int access_flags, creation_mode;
+ WCHAR *wpath = NULL;
if (file == NULL) {
perror(path);
return NULL;
}
+ wpath = path_to_windows(path);
+ if (wpath == NULL)
+ goto fail_free;
+
file->path = strdup(path);
if (file->path == NULL) {
perror(path);
@@ -148,14 +153,16 @@ ostream_t *ostream_open_file(const char *path, int flags)
creation_mode = CREATE_NEW;
}
- file->hnd = CreateFile(path, access_flags, 0, NULL, creation_mode,
- FILE_ATTRIBUTE_NORMAL, NULL);
+ file->hnd = CreateFileW(wpath, access_flags, 0, NULL, creation_mode,
+ FILE_ATTRIBUTE_NORMAL, NULL);
if (file->hnd == INVALID_HANDLE_VALUE) {
w32_perror(path);
goto fail_path;
}
+ free(wpath);
+
if (flags & OSTREAM_OPEN_SPARSE)
strm->append_sparse = file_append_sparse;
@@ -168,6 +175,7 @@ fail_path:
free(file->path);
fail_free:
free(file);
+ free(wpath);
return NULL;
}