aboutsummaryrefslogtreecommitdiff
path: root/lib/io/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/io/src')
-rw-r--r--lib/io/src/unix/istream.c5
-rw-r--r--lib/io/src/unix/ostream.c9
-rw-r--r--lib/io/src/win32/istream.c15
-rw-r--r--lib/io/src/win32/ostream.c28
4 files changed, 12 insertions, 45 deletions
diff --git a/lib/io/src/unix/istream.c b/lib/io/src/unix/istream.c
index 39d570f..ca9a183 100644
--- a/lib/io/src/unix/istream.c
+++ b/lib/io/src/unix/istream.c
@@ -144,11 +144,10 @@ fail_free:
sqfs_istream_t *istream_open_file(const char *path)
{
+ sqfs_file_handle_t fd;
sqfs_istream_t *out;
- int fd;
- fd = open(path, O_RDONLY);
- if (fd < 0) {
+ if (sqfs_open_native_file(&fd, path, SQFS_FILE_OPEN_READ_ONLY)) {
perror(path);
return NULL;
}
diff --git a/lib/io/src/unix/ostream.c b/lib/io/src/unix/ostream.c
index 0e95167..52a566a 100644
--- a/lib/io/src/unix/ostream.c
+++ b/lib/io/src/unix/ostream.c
@@ -177,13 +177,12 @@ fail_free:
sqfs_ostream_t *ostream_open_file(const char *path, int flags)
{
+ sqfs_file_handle_t fd;
sqfs_ostream_t *out;
- int fd;
- if (flags & SQFS_FILE_OPEN_OVERWRITE) {
- fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
- } else {
- fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
+ if (sqfs_open_native_file(&fd, path, flags)) {
+ perror(path);
+ return NULL;
}
out = ostream_open_handle(path, fd, flags);
diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c
index e6cb266..7cc7144 100644
--- a/lib/io/src/win32/istream.c
+++ b/lib/io/src/win32/istream.c
@@ -154,25 +154,14 @@ fail_free:
sqfs_istream_t *istream_open_file(const char *path)
{
- WCHAR *wpath = NULL;
+ sqfs_file_handle_t hnd;
sqfs_istream_t *out;
- HANDLE hnd;
-
- wpath = path_to_windows(path);
- if (wpath == NULL)
- return NULL;
- hnd = CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
- if (hnd == INVALID_HANDLE_VALUE) {
+ if (sqfs_open_native_file(&hnd, path, SQFS_FILE_OPEN_READ_ONLY)) {
w32_perror(path);
- free(wpath);
return NULL;
}
- free(wpath);
-
out = istream_open_handle(path, hnd);
if (out == NULL)
CloseHandle(hnd);
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);