| ... | @@ -11,6 +11,7 @@ | ... | @@ -11,6 +11,7 @@ |
| 11 | #include "error.hpp" | 11 | #include "error.hpp" |
| 12 | #include "util_base.hpp" | 12 | #include "util_base.hpp" |
| 13 | #include <stdint.h> | 13 | #include <stdint.h> |
| | 14 | #include <stdio.h> |
| 14 | | 15 | |
| 15 | #if defined(_WIN32) | 16 | #if defined(_WIN32) |
| 16 | | 17 | |
| ... | @@ -76,6 +77,7 @@ typedef SSIZE_T ssize_t; | ... | @@ -76,6 +77,7 @@ typedef SSIZE_T ssize_t; |
| 76 | #endif | 77 | #endif |
| 77 | | 78 | |
| 78 | #if defined(ZIG_OS_WINDOWS) | 79 | #if defined(ZIG_OS_WINDOWS) |
| | 80 | static void utf16le_ptr_to_utf8(Buf *out, WCHAR *utf16le); |
| 79 | static uint64_t windows_perf_freq; | 81 | static uint64_t windows_perf_freq; |
| 80 | #elif defined(__MACH__) | 82 | #elif defined(__MACH__) |
| 81 | static clock_serv_t macos_calendar_clock; | 83 | static clock_serv_t macos_calendar_clock; |
| ... | @@ -272,11 +274,13 @@ void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path) { | ... | @@ -272,11 +274,13 @@ void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path) { |
| 272 | | 274 | |
| 273 | Error os_path_real(Buf *rel_path, Buf *out_abs_path) { | 275 | Error os_path_real(Buf *rel_path, Buf *out_abs_path) { |
| 274 | #if defined(ZIG_OS_WINDOWS) | 276 | #if defined(ZIG_OS_WINDOWS) |
| 275 | buf_resize(out_abs_path, 4096); | 277 | PathSpace rel_path_space = slice_to_prefixed_file_w({ (uint8_t*)buf_ptr(rel_path), buf_len(rel_path) }); |
| 276 | if (_fullpath(buf_ptr(out_abs_path), buf_ptr(rel_path), buf_len(out_abs_path)) == nullptr) { | 278 | PathSpace out_abs_path_space; |
| 277 | zig_panic("_fullpath failed"); | 279 | |
| | 280 | if (_wfullpath(&out_abs_path_space.data.items[0], &rel_path_space.data.items[0], PATH_MAX_WIDE) == nullptr) { |
| | 281 | zig_panic("_wfullpath failed"); |
| 278 | } | 282 | } |
| 279 | buf_resize(out_abs_path, strlen(buf_ptr(out_abs_path))); | 283 | utf16le_ptr_to_utf8(out_abs_path, &out_abs_path_space.data.items[0]); |
| 280 | return ErrorNone; | 284 | return ErrorNone; |
| 281 | #elif defined(ZIG_OS_POSIX) | 285 | #elif defined(ZIG_OS_POSIX) |
| 282 | buf_resize(out_abs_path, PATH_MAX + 1); | 286 | buf_resize(out_abs_path, PATH_MAX + 1); |
| ... | @@ -1234,11 +1238,11 @@ Error os_fetch_file_path(Buf *full_path, Buf *out_contents) { | ... | @@ -1234,11 +1238,11 @@ Error os_fetch_file_path(Buf *full_path, Buf *out_contents) { |
| 1234 | | 1238 | |
| 1235 | Error os_get_cwd(Buf *out_cwd) { | 1239 | Error os_get_cwd(Buf *out_cwd) { |
| 1236 | #if defined(ZIG_OS_WINDOWS) | 1240 | #if defined(ZIG_OS_WINDOWS) |
| 1237 | char buf[4096]; | 1241 | PathSpace path_space; |
| 1238 | if (GetCurrentDirectory(4096, buf) == 0) { | 1242 | if (GetCurrentDirectoryW(PATH_MAX_WIDE, &path_space.data.items[0]) == 0) { |
| 1239 | zig_panic("GetCurrentDirectory failed"); | 1243 | zig_panic("GetCurrentDirectory failed"); |
| 1240 | } | 1244 | } |
| 1241 | buf_init_from_str(out_cwd, buf); | 1245 | utf16le_ptr_to_utf8(out_cwd, &path_space.data.items[0]); |
| 1242 | return ErrorNone; | 1246 | return ErrorNone; |
| 1243 | #elif defined(ZIG_OS_POSIX) | 1247 | #elif defined(ZIG_OS_POSIX) |
| 1244 | char buf[PATH_MAX]; | 1248 | char buf[PATH_MAX]; |
| ... | @@ -1538,18 +1542,13 @@ int os_init(void) { | ... | @@ -1538,18 +1542,13 @@ int os_init(void) { |
| 1538 | | 1542 | |
| 1539 | Error os_self_exe_path(Buf *out_path) { | 1543 | Error os_self_exe_path(Buf *out_path) { |
| 1540 | #if defined(ZIG_OS_WINDOWS) | 1544 | #if defined(ZIG_OS_WINDOWS) |
| 1541 | buf_resize(out_path, 256); | 1545 | PathSpace path_space; |
| 1542 | for (;;) { | 1546 | DWORD copied_amt = GetModuleFileNameW(nullptr, &path_space.data.items[0], PATH_MAX_WIDE); |
| 1543 | DWORD copied_amt = GetModuleFileName(nullptr, buf_ptr(out_path), buf_len(out_path)); | 1547 | if (copied_amt <= 0) { |
| 1544 | if (copied_amt <= 0) { | 1548 | return ErrorFileNotFound; |
| 1545 | return ErrorFileNotFound; | | |
| 1546 | } | | |
| 1547 | if (copied_amt < buf_len(out_path)) { | | |
| 1548 | buf_resize(out_path, copied_amt); | | |
| 1549 | return ErrorNone; | | |
| 1550 | } | | |
| 1551 | buf_resize(out_path, buf_len(out_path) * 2); | | |
| 1552 | } | 1549 | } |
| | 1550 | utf16le_ptr_to_utf8(out_path, &path_space.data.items[0]); |
| | 1551 | return ErrorNone; |
| 1553 | | 1552 | |
| 1554 | #elif defined(ZIG_OS_DARWIN) | 1553 | #elif defined(ZIG_OS_DARWIN) |
| 1555 | // How long is the executable's path? | 1554 | // How long is the executable's path? |