windows: use cross platform consts where available

This commit is contained in:
Will Pragnell
2023-09-15 16:01:33 -07:00
parent d700fb6fc7
commit 8f2ab46e1e
2 changed files with 10 additions and 9 deletions

View File

@@ -223,8 +223,6 @@ pub fn getData(self: Command, comptime DT: type) ?*DT {
/// Search for "cmd" in the PATH and return the absolute path. This will
/// always allocate if there is a non-null result. The caller must free the
/// resulting value.
///
/// TODO: windows
pub fn expandPath(alloc: Allocator, cmd: []const u8) !?[]u8 {
// If the command already contains a slash, then we return it as-is
// because it is assumed to be absolute or relative.
@@ -243,8 +241,7 @@ pub fn expandPath(alloc: Allocator, cmd: []const u8) !?[]u8 {
defer if (builtin.os.tag == .windows) alloc.free(PATH);
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const path_separator = if (builtin.os.tag == .windows) ";" else ":";
var it = std.mem.tokenize(u8, PATH, path_separator);
var it = std.mem.tokenize(u8, PATH, &[_]u8{std.fs.path.delimiter});
var seen_eacces = false;
while (it.next()) |search_path| {
// We need enough space in our path buffer to store this
@@ -253,7 +250,7 @@ pub fn expandPath(alloc: Allocator, cmd: []const u8) !?[]u8 {
// Copy in the full path
mem.copy(u8, &path_buf, search_path);
path_buf[search_path.len] = if (builtin.os.tag == .windows) '\\' else '/';
path_buf[search_path.len] = std.fs.path.sep;
mem.copy(u8, path_buf[search_path.len + 1 ..], cmd);
path_buf[path_len] = 0;
const full_path = path_buf[0..path_len :0];