| 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,10 +476,23 @@ pub const args = struct { |
| 476 | pub fn getCwd(allocator: &Allocator) -> %[]u8 { | 476 | pub fn getCwd(allocator: &Allocator) -> %[]u8 { |
| 477 | switch (builtin.os) { | 477 | switch (builtin.os) { |
| 478 | Os.windows => { | 478 | Os.windows => { |
| 479 | @panic("implement getCwd for windows"); | 479 | var buf = %return allocator.alloc(u8, 256); |
| 480 | //if (windows.GetCurrentDirectoryA(buf_len(out_cwd), buf_ptr(out_cwd)) == 0) { | 480 | %defer allocator.free(buf); |
| 481 | // zig_panic("GetCurrentDirectory failed"); | 481 | |
| 482 | //} | 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 | else => { | 497 | else => { |
| 485 | var buf = %return allocator.alloc(u8, 1024); | 498 | var buf = %return allocator.alloc(u8, 1024); |
std/os/path.zig+6-18| ... | @@ -176,25 +176,13 @@ test "os.path.networkShare" { | ... | @@ -176,25 +176,13 @@ test "os.path.networkShare" { |
| 176 | assert(networkShare("\\\\a\\") == null); | 176 | assert(networkShare("\\\\a\\") == null); |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | pub fn root(path: []const u8) -> []const u8 { | 179 | pub fn diskDesignator(path: []const u8) -> []const u8 { |
| 180 | if (is_windows) { | 180 | if (!is_windows) |
| 181 | return rootWindows(path); | 181 | return ""; |
| 182 | } else { | ||
| 183 | return rootPosix(path); | ||
| 184 | } | ||
| 185 | } | ||
| 186 | 182 | ||
| 187 | pub fn rootWindows(path: []const u8) -> []const u8 { | ||
| 188 | return drive(path) ?? (networkShare(path) ?? []u8{}); | 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 | // TODO ASCII is wrong, we actually need full unicode support to compare paths. | 186 | // TODO ASCII is wrong, we actually need full unicode support to compare paths. |
| 199 | fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool { | 187 | fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool { |
| 200 | const sep1 = ns1[0]; | 188 | const sep1 = ns1[0]; |
| ... | @@ -346,7 +334,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 | ... | @@ -346,7 +334,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 |
| 346 | mem.copy(u8, result, cwd); | 334 | mem.copy(u8, result, cwd); |
| 347 | result_index += cwd.len; | 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 | %defer allocator.free(result); | 339 | %defer allocator.free(result); |
| 352 | 340 | ||
| ... | @@ -362,7 +350,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 | ... | @@ -362,7 +350,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 |
| 362 | continue; | 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 | while (it.next()) |component| { | 354 | while (it.next()) |component| { |
| 367 | if (mem.eql(u8, component, ".")) { | 355 | if (mem.eql(u8, component, ".")) { |
| 368 | continue; | 356 | continue; |
| ... | @@ -517,7 +505,7 @@ pub fn dirnameWindows(path: []const u8) -> []const u8 { | ... | @@ -517,7 +505,7 @@ pub fn dirnameWindows(path: []const u8) -> []const u8 { |
| 517 | if (path.len == 0) | 505 | if (path.len == 0) |
| 518 | return path[0..0]; | 506 | return path[0..0]; |
| 519 | 507 | ||
| 520 | const root_slice = rootWindows(path); | 508 | const root_slice = diskDesignator(path); |
| 521 | if (path.len == root_slice.len) | 509 | if (path.len == root_slice.len) |
| 522 | return path; | 510 | return path; |
| 523 | 511 |
std/os/windows/index.zig+4-1| ... | @@ -13,6 +13,8 @@ pub extern "kernel32" stdcallcc fn GetCommandLine() -> LPTSTR; | ... | @@ -13,6 +13,8 @@ pub extern "kernel32" stdcallcc fn GetCommandLine() -> LPTSTR; |
| 13 | 13 | ||
| 14 | pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> bool; | 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 | /// Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. | 18 | /// Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. |
| 17 | /// Multiple threads do not overwrite each other's last-error code. | 19 | /// Multiple threads do not overwrite each other's last-error code. |
| 18 | pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD; | 20 | pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD; |
| ... | @@ -50,7 +52,7 @@ pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lp | ... | @@ -50,7 +52,7 @@ pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lp |
| 50 | pub const PROV_RSA_FULL = 1; | 52 | pub const PROV_RSA_FULL = 1; |
| 51 | 53 | ||
| 52 | pub const UNICODE = false; | 54 | pub const UNICODE = false; |
| 53 | pub const LPTSTR = if (unicode) LPWSTR else LPSTR; | 55 | pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR; |
| 54 | pub const LPWSTR = &WCHAR; | 56 | pub const LPWSTR = &WCHAR; |
| 55 | pub const LPSTR = &CHAR; | 57 | pub const LPSTR = &CHAR; |
| 56 | pub const CHAR = u8; | 58 | pub const CHAR = u8; |
| ... | @@ -59,6 +61,7 @@ pub const SIZE_T = usize; | ... | @@ -59,6 +61,7 @@ pub const SIZE_T = usize; |
| 59 | 61 | ||
| 60 | pub const BOOL = bool; | 62 | pub const BOOL = bool; |
| 61 | pub const BYTE = u8; | 63 | pub const BYTE = u8; |
| 64 | pub const WORD = u16; | ||
| 62 | pub const DWORD = u32; | 65 | pub const DWORD = u32; |
| 63 | pub const FLOAT = f32; | 66 | pub const FLOAT = f32; |
| 64 | pub const HANDLE = &c_void; | 67 | pub const HANDLE = &c_void; |