aboutsummaryrefslogtreecommitdiff
path: root/src/which.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-02-27 23:20:10 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-02-27 23:20:10 -0800
commit50560e169ca39c0b4ec163cb32897baf7620aa69 (patch)
tree83eb721bfd4a0318874c1f69d254a4fd9446512b /src/which.zig
parent36c249e9c1fc6e0000d23ae0055eed54a5437c74 (diff)
downloadbun-50560e169ca39c0b4ec163cb32897baf7620aa69.tar.gz
bun-50560e169ca39c0b4ec163cb32897baf7620aa69.tar.zst
bun-50560e169ca39c0b4ec163cb32897baf7620aa69.zip
WASM
Diffstat (limited to 'src/which.zig')
-rw-r--r--src/which.zig8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/which.zig b/src/which.zig
index 558abc389..a6009200c 100644
--- a/src/which.zig
+++ b/src/which.zig
@@ -1,6 +1,6 @@
const std = @import("std");
-
-fn isValid(buf: *[std.fs.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8) ?u16 {
+const _global = @import("./global.zig");
+fn isValid(buf: *[_global.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8) ?u16 {
std.mem.copy(u8, buf, segment);
buf[segment.len] = std.fs.path.sep;
std.mem.copy(u8, buf[segment.len + 1 ..], bin);
@@ -14,7 +14,7 @@ fn isValid(buf: *[std.fs.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8
// Like /usr/bin/which but without needing to exec a child process
// Remember to resolve the symlink if necessary
-pub fn which(buf: *[std.fs.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8, bin: []const u8) ?[:0]const u8 {
+pub fn which(buf: *[_global.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8, bin: []const u8) ?[:0]const u8 {
if (isValid(buf, std.mem.trimRight(u8, cwd, std.fs.path.sep_str), bin)) |len| {
return buf[0..len :0];
}
@@ -30,7 +30,7 @@ pub fn which(buf: *[std.fs.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8,
}
test "which" {
- var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
+ var buf: [_global.MAX_PATH_BYTES]u8 = undefined;
var realpath = std.os.getenv("PATH") orelse unreachable;
var whichbin = which(&buf, realpath, try std.process.getCwdAlloc(std.heap.c_allocator), "which");
try std.testing.expectEqualStrings(whichbin orelse return std.debug.assert(false), "/usr/bin/which");