| author | |
| committer | |
| log | 9d5f15fe3da40813527d19c75b3633dcf2d00b0b |
| tree | 06cc475a5440708b2fd00fd1b0994dc39ca75a75 |
| parent | 7cfab2fb5f0f0dce81feab9dd8ad3d3e1b435044 |
3 files changed, 27 insertions(+), 23 deletions(-)
std/os/index.zig+17-4| ... | ... | @@ -476,10 +476,23 @@ pub const args = struct { |
| 476 | 476 | pub fn getCwd(allocator: &Allocator) -> %[]u8 { |
| 477 | 477 | switch (builtin.os) { |
| 478 | 478 | Os.windows => { |
| 479 | @panic("implement getCwd for windows"); | |
| 480 | //if (windows.GetCurrentDirectoryA(buf_len(out_cwd), buf_ptr(out_cwd)) == 0) { | |
| 481 | // zig_panic("GetCurrentDirectory failed"); | |
| 482 | //} | |
| 479 | var buf = %return allocator.alloc(u8, 256); | |
| 480 | %defer allocator.free(buf); | |
| 481 | ||
| 482 | while (true) { | |
| 483 | const result = windows.GetCurrentDirectoryA(windows.WORD(buf.len), buf.ptr); | |
| 484 | ||
| 485 | if (result == 0) { | |
| 486 | return error.Unexpected; | |
| 487 | } | |
| 488 | ||
| 489 | if (result > buf.len) { | |
| 490 | buf = %return allocator.realloc(u8, buf, result); | |
| 491 | continue; | |
| 492 | } | |
| 493 | ||
| 494 | return buf[0..result]; | |
| 495 | } | |
| 483 | 496 | }, |
| 484 | 497 | else => { |
| 485 | 498 | var buf = %return allocator.alloc(u8, 1024); |
std/os/path.zig+6-18| ... | ... | @@ -176,25 +176,13 @@ test "os.path.networkShare" { |
| 176 | 176 | assert(networkShare("\\\\a\\") == null); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | pub fn root(path: []const u8) -> []const u8 { | |
| 180 | if (is_windows) { | |
| 181 | return rootWindows(path); | |
| 182 | } else { | |
| 183 | return rootPosix(path); | |
| 184 | } | |
| 185 | } | |
| 179 | pub fn diskDesignator(path: []const u8) -> []const u8 { | |
| 180 | if (!is_windows) | |
| 181 | return ""; | |
| 186 | 182 | |
| 187 | pub fn rootWindows(path: []const u8) -> []const u8 { | |
| 188 | 183 | return drive(path) ?? (networkShare(path) ?? []u8{}); |
| 189 | 184 | } |
| 190 | 185 | |
| 191 | pub fn rootPosix(path: []const u8) -> []const u8 { | |
| 192 | if (path.len == 0 or path[0] != '/') | |
| 193 | return []u8{}; | |
| 194 | ||
| 195 | return path[0..1]; | |
| 196 | } | |
| 197 | ||
| 198 | 186 | // TODO ASCII is wrong, we actually need full unicode support to compare paths. |
| 199 | 187 | fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool { |
| 200 | 188 | const sep1 = ns1[0]; |
| ... | ... | @@ -346,7 +334,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 |
| 346 | 334 | mem.copy(u8, result, cwd); |
| 347 | 335 | result_index += cwd.len; |
| 348 | 336 | |
| 349 | root_slice = rootWindows(result[0..result_index]); | |
| 337 | root_slice = diskDesignator(result[0..result_index]); | |
| 350 | 338 | } |
| 351 | 339 | %defer allocator.free(result); |
| 352 | 340 | |
| ... | ... | @@ -362,7 +350,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 |
| 362 | 350 | continue; |
| 363 | 351 | } |
| 364 | 352 | } |
| 365 | var it = mem.split(p[rootWindows(p).len..], "/\\"); | |
| 353 | var it = mem.split(p[diskDesignator(p).len..], "/\\"); | |
| 366 | 354 | while (it.next()) |component| { |
| 367 | 355 | if (mem.eql(u8, component, ".")) { |
| 368 | 356 | continue; |
| ... | ... | @@ -517,7 +505,7 @@ pub fn dirnameWindows(path: []const u8) -> []const u8 { |
| 517 | 505 | if (path.len == 0) |
| 518 | 506 | return path[0..0]; |
| 519 | 507 | |
| 520 | const root_slice = rootWindows(path); | |
| 508 | const root_slice = diskDesignator(path); | |
| 521 | 509 | if (path.len == root_slice.len) |
| 522 | 510 | return path; |
| 523 | 511 |
std/os/windows/index.zig+4-1| ... | ... | @@ -13,6 +13,8 @@ pub extern "kernel32" stdcallcc fn GetCommandLine() -> LPTSTR; |
| 13 | 13 | |
| 14 | 14 | pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> bool; |
| 15 | 15 | |
| 16 | pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPTSTR) -> DWORD; | |
| 17 | ||
| 16 | 18 | /// Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. |
| 17 | 19 | /// Multiple threads do not overwrite each other's last-error code. |
| 18 | 20 | pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD; |
| ... | ... | @@ -50,7 +52,7 @@ pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lp |
| 50 | 52 | pub const PROV_RSA_FULL = 1; |
| 51 | 53 | |
| 52 | 54 | pub const UNICODE = false; |
| 53 | pub const LPTSTR = if (unicode) LPWSTR else LPSTR; | |
| 55 | pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR; | |
| 54 | 56 | pub const LPWSTR = &WCHAR; |
| 55 | 57 | pub const LPSTR = &CHAR; |
| 56 | 58 | pub const CHAR = u8; |
| ... | ... | @@ -59,6 +61,7 @@ pub const SIZE_T = usize; |
| 59 | 61 | |
| 60 | 62 | pub const BOOL = bool; |
| 61 | 63 | pub const BYTE = u8; |
| 64 | pub const WORD = u16; | |
| 62 | 65 | pub const DWORD = u32; |
| 63 | 66 | pub const FLOAT = f32; |
| 64 | 67 | pub const HANDLE = &c_void; |