| author | |
| committer | |
| log | 1042cbe0100ba0fbd8265f975c49356d31e4bd91 |
| tree | 2e57b2320cdaf9764ca85c48a22707c397ecc193 |
| parent | be07f95cd7e543abdcc06292892eb57ee1b83153 |
Also reduce the amount of unnecessary allocations, since one buffer can be used for appending all supported PATHEXT extensions
Fixes #356682 files changed, 15 insertions(+), 2 deletions(-)
lib/std/Build.zig+6-1| ... | ... | @@ -1836,10 +1836,14 @@ fn tryFindProgram(b: *Build, full_path: []const u8) ?[]const u8 { |
| 1836 | 1836 | if (b.graph.environ_map.get("PATHEXT")) |PATHEXT| { |
| 1837 | 1837 | var it = mem.tokenizeScalar(u8, PATHEXT, fs.path.delimiter); |
| 1838 | 1838 | |
| 1839 | const extended_path_buf = arena.alloc(u8, full_path.len + 1 + std.process.WindowsExtension.max_len) catch @panic("OOM"); | |
| 1840 | @memcpy(extended_path_buf[0..full_path.len], full_path); | |
| 1841 | ||
| 1839 | 1842 | while (it.next()) |ext| { |
| 1840 | 1843 | if (!supportedWindowsProgramExtension(ext)) continue; |
| 1841 | 1844 | |
| 1842 | const extended_path = try mem.concat(arena, u8, &.{ full_path, ext }); | |
| 1845 | @memcpy(extended_path_buf[full_path.len..][0..ext.len], ext); | |
| 1846 | const extended_path = extended_path_buf[0 .. full_path.len + ext.len]; | |
| 1843 | 1847 | |
| 1844 | 1848 | if (Io.Dir.cwd().access(io, extended_path, .{ .execute = true })) |_| { |
| 1845 | 1849 | return extended_path; |
| ... | ... | @@ -2708,4 +2712,5 @@ test { |
| 2708 | 2712 | _ = Cache; |
| 2709 | 2713 | _ = Step; |
| 2710 | 2714 | _ = Configuration; |
| 2715 | _ = &findProgram; | |
| 2711 | 2716 | } |
lib/std/process.zig+9-1| ... | ... | @@ -315,7 +315,15 @@ pub fn replacePath(io: Io, dir: Io.Dir, options: ReplaceOptions) ReplaceError { |
| 315 | 315 | pub const ArgExpansion = enum { expand, no_expand }; |
| 316 | 316 | |
| 317 | 317 | /// File name extensions supported natively by `CreateProcess()` on Windows. |
| 318 | pub const WindowsExtension = enum { bat, cmd, com, exe }; | |
| 318 | pub const WindowsExtension = enum { | |
| 319 | bat, | |
| 320 | cmd, | |
| 321 | com, | |
| 322 | exe, | |
| 323 | ||
| 324 | /// Length of the longest supported extension (in ASCII characters) | |
| 325 | pub const max_len = 3; | |
| 326 | }; | |
| 319 | 327 | |
| 320 | 328 | pub const SpawnError = error{ |
| 321 | 329 | /// The operating system does not support creating child processes. |