diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2020-11-18 15:28:25 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2020-11-18 15:37:44 +0100 |
| commit | 663e112773f91ccbff9f9825147b1a2c0bb5e00c (patch) | |
| tree | 9e7082363288f53c015bcf73140819301648f440 /lib/std/os.zig | |
| parent | 64feae3ac35af700e5f3d2e36f9482d1b58496ef (diff) | |
| download | zig-663e112773f91ccbff9f9825147b1a2c0bb5e00c.tar.gz zig-663e112773f91ccbff9f9825147b1a2c0bb5e00c.zip | |
std: add chdir smoke test
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index 0967774318..6e57c59c17 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -2312,11 +2312,7 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { var utf16_dir_path: [windows.PATH_MAX_WIDE]u16 = undefined; const len = try std.unicode.utf8ToUtf16Le(utf16_dir_path[0..], dir_path); if (len > utf16_dir_path.len) return error.NameTooLong; - - windows.SetCurrentDirectory(utf16_dir_path[0..len]) catch |err| switch (err) { - error.NoDevice => return error.FileSystem, - else => |e| return e, - }; + return chdirW(utf16_dir_path[0..len]); } else { const dir_path_c = try toPosixPath(dir_path); return chdirZ(&dir_path_c); @@ -2328,7 +2324,10 @@ pub const chdirC = @compileError("deprecated: renamed to chdirZ"); /// Same as `chdir` except the parameter is null-terminated. pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { if (builtin.os.tag == .windows) { - return chdir(mem.spanZ(dir_path)); + var utf16_dir_path: [windows.PATH_MAX_WIDE]u16 = undefined; + const len = try std.unicode.utf8ToUtf16Le(utf16_dir_path[0..], dir_path); + if (len > utf16_dir_path.len) return error.NameTooLong; + return chdirW(utf16_dir_path[0..len]); } switch (errno(system.chdir(dir_path))) { 0 => return, @@ -2344,6 +2343,14 @@ pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { } } +/// Windows-only. Same as `chdir` except the paramter is WTF16 encoded. +pub fn chdirW(dir_path: []const u16) ChangeCurDirError!void { + windows.SetCurrentDirectory(dir_path) catch |err| switch (err) { + error.NoDevice => return error.FileSystem, + else => |e| return e, + }; +} + pub const FchdirError = error{ AccessDenied, NotDir, |
