Skip to content

Commit fd936ef

Browse files
author
Marler
committed
Add the no-extension case to windows program search
1 parent 1ccf6a2 commit fd936ef

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

std/child_process.zig

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ pub const ChildProcess = struct {
548548

549549
var it = mem.tokenize(PATH, ";");
550550
retry: while (it.next()) |search_path| {
551-
var ext_it = mem.tokenize(PATHEXT, ";");
551+
var ext_it = Chain(OneItemIterator([]u8), @typeOf(mem.tokenize).ReturnType).init(
552+
OneItemIterator([]u8).init(""), mem.tokenize(PATHEXT, ";"));
552553
while (ext_it.next()) |app_ext| {
553554
const app_basename = try mem.concat(self.allocator, u8, [_][]const u8{app_name[0..app_name.len - 1], app_ext});
554555
defer self.allocator.free(app_basename);
@@ -768,3 +769,47 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap)
768769
i += 1;
769770
return allocator.shrink(result, i);
770771
}
772+
773+
// TODO: does this already exist somewhere?
774+
fn Chain(comptime T: type, comptime U: type) type {
775+
return struct {
776+
t: T,
777+
u: U,
778+
onU: bool,
779+
pub fn init(t: T, u: U) @This() {
780+
return @This() {
781+
.t = t,
782+
.u = u,
783+
.onU = false,
784+
};
785+
}
786+
pub fn next(self: *@This()) @typeOf(T.next).ReturnType {
787+
if (!self.onU) {
788+
if (self.t.next()) |tvalue| {
789+
return tvalue;
790+
}
791+
self.onU = true;
792+
}
793+
return self.u.next();
794+
}
795+
};
796+
}
797+
798+
// TODO: does this already exist?
799+
fn OneItemIterator(comptime T: type) type {
800+
return struct {
801+
t: ?T,
802+
pub fn init(t: T) @This() {
803+
return @This() {
804+
.t = t,
805+
};
806+
}
807+
pub fn next(self: *@This()) ?T {
808+
if (self.t) |tvalue| {
809+
self.t = null;
810+
return tvalue;
811+
}
812+
return null;
813+
}
814+
};
815+
}

0 commit comments

Comments
 (0)