| ... | @@ -3111,8 +3111,10 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { | ... | @@ -3111,8 +3111,10 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { |
| 3111 | @compileError("WASI does not support os.chdir"); | 3111 | @compileError("WASI does not support os.chdir"); |
| 3112 | } else if (native_os == .windows) { | 3112 | } else if (native_os == .windows) { |
| 3113 | var wtf16_dir_path: [windows.PATH_MAX_WIDE]u16 = undefined; | 3113 | var wtf16_dir_path: [windows.PATH_MAX_WIDE]u16 = undefined; |
| 3114 | const len = try std.unicode.wtf8ToWtf16Le(wtf16_dir_path[0..], dir_path); | 3114 | if (try std.unicode.checkWtf8ToWtf16LeOverflow(dir_path, &wtf16_dir_path)) { |
| 3115 | if (len > wtf16_dir_path.len) return error.NameTooLong; | 3115 | return error.NameTooLong; |
| | 3116 | } |
| | 3117 | const len = try std.unicode.wtf8ToWtf16Le(&wtf16_dir_path, dir_path); |
| 3116 | return chdirW(wtf16_dir_path[0..len]); | 3118 | return chdirW(wtf16_dir_path[0..len]); |
| 3117 | } else { | 3119 | } else { |
| 3118 | const dir_path_c = try toPosixPath(dir_path); | 3120 | const dir_path_c = try toPosixPath(dir_path); |
| ... | @@ -3126,9 +3128,12 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { | ... | @@ -3126,9 +3128,12 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { |
| 3126 | /// On other platforms, `dir_path` is an opaque sequence of bytes with no particular encoding. | 3128 | /// On other platforms, `dir_path` is an opaque sequence of bytes with no particular encoding. |
| 3127 | pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { | 3129 | pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { |
| 3128 | if (native_os == .windows) { | 3130 | if (native_os == .windows) { |
| | 3131 | const dir_path_span = mem.span(dir_path); |
| 3129 | var wtf16_dir_path: [windows.PATH_MAX_WIDE]u16 = undefined; | 3132 | var wtf16_dir_path: [windows.PATH_MAX_WIDE]u16 = undefined; |
| 3130 | const len = try std.unicode.wtf8ToWtf16Le(wtf16_dir_path[0..], mem.span(dir_path)); | 3133 | if (try std.unicode.checkWtf8ToWtf16LeOverflow(dir_path_span, &wtf16_dir_path)) { |
| 3131 | if (len > wtf16_dir_path.len) return error.NameTooLong; | 3134 | return error.NameTooLong; |
| | 3135 | } |
| | 3136 | const len = try std.unicode.wtf8ToWtf16Le(&wtf16_dir_path, dir_path_span); |
| 3132 | return chdirW(wtf16_dir_path[0..len]); | 3137 | return chdirW(wtf16_dir_path[0..len]); |
| 3133 | } else if (native_os == .wasi and !builtin.link_libc) { | 3138 | } else if (native_os == .wasi and !builtin.link_libc) { |
| 3134 | return chdir(mem.span(dir_path)); | 3139 | return chdir(mem.span(dir_path)); |