authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-06-15 16:15:10+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-06-15 16:15:10+03:00
log3b0b56b81a26d9ba4d42812843cf2e9407d6d2bc
treed6c297d905f9d40d51dda4ff9fad47e11eaf15cc
parent037c72fe6781df317a6c8cc04739d277cb96979f

Switched more Windows FS calls to their wide versions


1 files changed, 9 insertions(+), 5 deletions(-)

src/os.cpp+9-5
...@@ -776,7 +776,8 @@ Error os_fetch_file(FILE *f, Buf *out_buf) {...@@ -776,7 +776,8 @@ Error os_fetch_file(FILE *f, Buf *out_buf) {
776776
777Error os_file_exists(Buf *full_path, bool *result) {777Error os_file_exists(Buf *full_path, bool *result) {
778#if defined(ZIG_OS_WINDOWS)778#if defined(ZIG_OS_WINDOWS)
779 *result = GetFileAttributes(buf_ptr(full_path)) != INVALID_FILE_ATTRIBUTES;779 PathSpace path_space = slice_to_prefixed_file_w({ (uint8_t*)buf_ptr(full_path), buf_len(full_path) });
780 *result = GetFileAttributesW(&path_space.data.items[0]) != INVALID_FILE_ATTRIBUTES;
780 return ErrorNone;781 return ErrorNone;
781#else782#else
782 *result = access(buf_ptr(full_path), F_OK) != -1;783 *result = access(buf_ptr(full_path), F_OK) != -1;
...@@ -1333,7 +1334,9 @@ Error os_rename(Buf *src_path, Buf *dest_path) {...@@ -1333,7 +1334,9 @@ Error os_rename(Buf *src_path, Buf *dest_path) {
1333 return ErrorNone;1334 return ErrorNone;
1334 }1335 }
1335#if defined(ZIG_OS_WINDOWS)1336#if defined(ZIG_OS_WINDOWS)
1336 if (!MoveFileExA(buf_ptr(src_path), buf_ptr(dest_path), MOVEFILE_REPLACE_EXISTING)) {1337 PathSpace src_path_space = slice_to_prefixed_file_w({ (uint8_t*)buf_ptr(src_path), buf_len(src_path) });
1338 PathSpace dest_path_space = slice_to_prefixed_file_w({ (uint8_t*)buf_ptr(dest_path), buf_len(dest_path) });
1339 if (!MoveFileExW(&src_path_space.data.items[0], &dest_path_space.data.items[0], MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) {
1337 return ErrorFileSystem;1340 return ErrorFileSystem;
1338 }1341 }
1339#else1342#else
...@@ -2014,8 +2017,8 @@ Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {...@@ -2014,8 +2017,8 @@ Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {
20142017
2015Error os_file_open_rw(Buf *full_path, OsFile *out_file, OsFileAttr *attr, bool need_write, uint32_t mode) {2018Error os_file_open_rw(Buf *full_path, OsFile *out_file, OsFileAttr *attr, bool need_write, uint32_t mode) {
2016#if defined(ZIG_OS_WINDOWS)2019#if defined(ZIG_OS_WINDOWS)
2017 // TODO use CreateFileW2020 PathSpace path_space = slice_to_prefixed_file_w({ (uint8_t*)buf_ptr(full_path), buf_len(full_path) });
2018 HANDLE result = CreateFileA(buf_ptr(full_path),2021 HANDLE result = CreateFileW(&path_space.data.items[0],
2019 need_write ? (GENERIC_READ|GENERIC_WRITE) : GENERIC_READ,2022 need_write ? (GENERIC_READ|GENERIC_WRITE) : GENERIC_READ,
2020 need_write ? 0 : FILE_SHARE_READ,2023 need_write ? 0 : FILE_SHARE_READ,
2021 nullptr,2024 nullptr,
...@@ -2119,8 +2122,9 @@ Error os_file_open_w(Buf *full_path, OsFile *out_file, OsFileAttr *attr, uint32_...@@ -2119,8 +2122,9 @@ Error os_file_open_w(Buf *full_path, OsFile *out_file, OsFileAttr *attr, uint32_
21192122
2120Error os_file_open_lock_rw(Buf *full_path, OsFile *out_file) {2123Error os_file_open_lock_rw(Buf *full_path, OsFile *out_file) {
2121#if defined(ZIG_OS_WINDOWS)2124#if defined(ZIG_OS_WINDOWS)
2125 PathSpace path_space = slice_to_prefixed_file_w({ (uint8_t*)buf_ptr(full_path), buf_len(full_path) });
2122 for (;;) {2126 for (;;) {
2123 HANDLE result = CreateFileA(buf_ptr(full_path), GENERIC_READ | GENERIC_WRITE,2127 HANDLE result = CreateFileW(&path_space.data.items[0], GENERIC_READ | GENERIC_WRITE,
2124 0, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);2128 0, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
21252129
2126 if (result == INVALID_HANDLE_VALUE) {2130 if (result == INVALID_HANDLE_VALUE) {