Skip to content

[Waiting on other PRs] Add the no-extension case to windows program search #2770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion std/child_process.zig
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ pub const ChildProcess = struct {

var it = mem.tokenize(PATH, ";");
retry: while (it.next()) |search_path| {
var ext_it = mem.tokenize(PATHEXT, ";");
var ext_it = Chain(OneItemIterator([]u8), @typeOf(mem.tokenize).ReturnType).init(
OneItemIterator([]u8).init(""), mem.tokenize(PATHEXT, ";"));
while (ext_it.next()) |app_ext| {
const app_basename = try mem.concat(self.allocator, u8, [_][]const u8{app_name[0..app_name.len - 1], app_ext});
defer self.allocator.free(app_basename);
Expand Down Expand Up @@ -768,3 +769,47 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap)
i += 1;
return allocator.shrink(result, i);
}

// TODO: does this already exist somewhere?
fn Chain(comptime T: type, comptime U: type) type {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this (and the OneItemIterator) should either be moved somewhere else before merging, or they need to be removed if there is something else in the standard library that already provides this.

I'm not familiar enough with the standard library to know if these already exist somewhere in some form.

return struct {
t: T,
u: U,
onU: bool,
pub fn init(t: T, u: U) @This() {
return @This() {
.t = t,
.u = u,
.onU = false,
};
}
pub fn next(self: *@This()) @typeOf(T.next).ReturnType {
if (!self.onU) {
if (self.t.next()) |tvalue| {
return tvalue;
}
self.onU = true;
}
return self.u.next();
}
};
}

// TODO: does this already exist?
fn OneItemIterator(comptime T: type) type {
return struct {
t: ?T,
pub fn init(t: T) @This() {
return @This() {
.t = t,
};
}
pub fn next(self: *@This()) ?T {
if (self.t) |tvalue| {
self.t = null;
return tvalue;
}
return null;
}
};
}