| ... | @@ -968,52 +968,41 @@ pub const ChildProcess = struct { | ... | @@ -968,52 +968,41 @@ pub const ChildProcess = struct { |
| 968 | windowsCreateProcess(app_path_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| { | 968 | windowsCreateProcess(app_path_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| { |
| 969 | if (no_path_err != error.FileNotFound) return no_path_err; | 969 | if (no_path_err != error.FileNotFound) return no_path_err; |
| 970 | | 970 | |
| 971 | var free_path = true; | 971 | const PATH: [:0]const u16 = std.os.getenvW(unicode.utf8ToUtf16LeStringLiteral("PATH")) orelse &[_:0]u16{}; |
| 972 | const PATH = process.getEnvVarOwned(self.allocator, "PATH") catch |err| switch (err) { | 972 | const PATHEXT: [:0]const u16 = std.os.getenvW(unicode.utf8ToUtf16LeStringLiteral("PATHEXT")) orelse &[_:0]u16{}; |
| 973 | error.EnvironmentVariableNotFound => blk: { | | |
| 974 | free_path = false; | | |
| 975 | break :blk ""; | | |
| 976 | }, | | |
| 977 | else => |e| return e, | | |
| 978 | }; | | |
| 979 | defer if (free_path) self.allocator.free(PATH); | | |
| 980 | | 973 | |
| 981 | var free_path_ext = true; | 974 | var path_buf = std.ArrayListUnmanaged(u16){}; |
| 982 | const PATHEXT = process.getEnvVarOwned(self.allocator, "PATHEXT") catch |err| switch (err) { | 975 | defer path_buf.deinit(self.allocator); |
| 983 | error.EnvironmentVariableNotFound => blk: { | | |
| 984 | free_path_ext = false; | | |
| 985 | break :blk ""; | | |
| 986 | }, | | |
| 987 | else => |e| return e, | | |
| 988 | }; | | |
| 989 | defer if (free_path_ext) self.allocator.free(PATHEXT); | | |
| 990 | | 976 | |
| 991 | const app_name = self.argv[0]; | 977 | const app_name = self.argv[0]; |
| | 978 | const app_name_trimmed_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, mem.trimLeft(u8, app_name, "\\/")); |
| | 979 | defer self.allocator.free(app_name_trimmed_w); |
| 992 | | 980 | |
| 993 | var it = mem.tokenize(u8, PATH, ";"); | 981 | var it = mem.tokenize(u16, PATH, &[_]u16{';'}); |
| 994 | retry: while (it.next()) |search_path| { | 982 | retry: while (it.next()) |search_path| { |
| 995 | const path_no_ext = try fs.path.join(self.allocator, &[_][]const u8{ search_path, app_name }); | 983 | path_buf.clearRetainingCapacity(); |
| 996 | defer self.allocator.free(path_no_ext); | 984 | const search_path_trimmed = mem.trimRight(u16, search_path, &[_]u16{ '\\', '/' }); |
| 997 | | 985 | try path_buf.appendSlice(self.allocator, search_path_trimmed); |
| 998 | const path_no_ext_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, path_no_ext); | 986 | try path_buf.append(self.allocator, fs.path.sep); |
| 999 | defer self.allocator.free(path_no_ext_w); | 987 | try path_buf.appendSlice(self.allocator, app_name_trimmed_w); |
| 1000 | | 988 | try path_buf.append(self.allocator, 0); |
| 1001 | if (windowsCreateProcess(path_no_ext_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| { | 989 | const path_no_ext = path_buf.items[0 .. path_buf.items.len - 1 :0]; |
| | 990 | |
| | 991 | if (windowsCreateProcess(path_no_ext.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| { |
| 1002 | break :retry; | 992 | break :retry; |
| 1003 | } else |err| switch (err) { | 993 | } else |err| switch (err) { |
| 1004 | error.FileNotFound, error.AccessDenied => {}, | 994 | error.FileNotFound, error.AccessDenied => {}, |
| 1005 | else => return err, | 995 | else => return err, |
| 1006 | } | 996 | } |
| 1007 | | 997 | |
| 1008 | var ext_it = mem.tokenize(u8, PATHEXT, ";"); | 998 | var ext_it = mem.tokenize(u16, PATHEXT, &[_]u16{';'}); |
| 1009 | while (ext_it.next()) |app_ext| { | 999 | while (ext_it.next()) |ext| { |
| 1010 | const ext_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, app_ext); | 1000 | path_buf.shrinkRetainingCapacity(path_no_ext.len); |
| 1011 | defer self.allocator.free(ext_w); | 1001 | try path_buf.appendSlice(self.allocator, ext); |
| 1012 | | 1002 | try path_buf.append(self.allocator, 0); |
| 1013 | const joined_path_w = try std.mem.concatWithSentinel(self.allocator, u16, &.{ path_no_ext_w, ext_w }, 0); | 1003 | const joined_path = path_buf.items[0 .. path_buf.items.len - 1 :0]; |
| 1014 | defer self.allocator.free(joined_path_w); | | |
| 1015 | | 1004 | |
| 1016 | if (windowsCreateProcess(joined_path_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| { | 1005 | if (windowsCreateProcess(joined_path.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| { |
| 1017 | break :retry; | 1006 | break :retry; |
| 1018 | } else |err| switch (err) { | 1007 | } else |err| switch (err) { |
| 1019 | error.FileNotFound => continue, | 1008 | error.FileNotFound => continue, |