| ... | ... | @@ -15193,7 +15193,26 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro |
| 15193 | 15193 | defer arena_allocator.deinit(); |
| 15194 | 15194 | const arena = arena_allocator.allocator(); |
| 15195 | 15195 | |
| 15196 | | const cwd_w = if (options.cwd) |cwd| try std.unicode.wtf8ToWtf16LeAllocZ(arena, cwd) else null; |
| 15196 | const cwd_w = cwd_w: { |
| 15197 | if (options.cwd_dir) |cwd_dir| { |
| 15198 | var dir_path_buffer = try arena.alloc(u16, windows.PATH_MAX_WIDE + 1); |
| 15199 | // TODO move GetFinalPathNameByHandle logic into std.Io.Threaded and add cancel checks |
| 15200 | try Thread.checkCancel(); |
| 15201 | const dir_path = try windows.GetFinalPathNameByHandle( |
| 15202 | cwd_dir.handle, |
| 15203 | .{}, |
| 15204 | dir_path_buffer[0..windows.PATH_MAX_WIDE], |
| 15205 | ); |
| 15206 | dir_path_buffer[dir_path.len] = 0; |
| 15207 | // Shrink the allocation down to just the path buffer + sentinel |
| 15208 | dir_path_buffer = try arena.realloc(dir_path_buffer, dir_path.len + 1); |
| 15209 | break :cwd_w dir_path_buffer[0..dir_path.len :0]; |
| 15210 | } else if (options.cwd) |cwd| { |
| 15211 | break :cwd_w try std.unicode.wtf8ToWtf16LeAllocZ(arena, cwd); |
| 15212 | } else { |
| 15213 | break :cwd_w null; |
| 15214 | } |
| 15215 | }; |
| 15197 | 15216 | const cwd_w_ptr = if (cwd_w) |cwd| cwd.ptr else null; |
| 15198 | 15217 | |
| 15199 | 15218 | const maybe_envp_buf = if (options.environ_map) |environ_map| try environ_map.createBlockWindows(arena) else null; |
| ... | ... | @@ -15204,16 +15223,13 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro |
| 15204 | 15223 | |
| 15205 | 15224 | // The cwd provided by options is in effect when choosing the executable |
| 15206 | 15225 | // path to match POSIX semantics. |
| 15207 | | var cwd_path_w_needs_free = false; |
| 15208 | 15226 | const cwd_path_w = x: { |
| 15209 | 15227 | // If the app name is absolute, then we need to use its dirname as the cwd |
| 15210 | 15228 | if (app_name_is_absolute) { |
| 15211 | | cwd_path_w_needs_free = true; |
| 15212 | 15229 | const dir = Dir.path.dirname(app_name_wtf8).?; |
| 15213 | 15230 | break :x try std.unicode.wtf8ToWtf16LeAllocZ(arena, dir); |
| 15214 | | } else if (options.cwd) |cwd| { |
| 15215 | | cwd_path_w_needs_free = true; |
| 15216 | | break :x try std.unicode.wtf8ToWtf16LeAllocZ(arena, cwd); |
| 15231 | } else if (cwd_w) |cwd| { |
| 15232 | break :x cwd; |
| 15217 | 15233 | } else { |
| 15218 | 15234 | break :x &[_:0]u16{}; // empty for cwd |
| 15219 | 15235 | } |