aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/which.zig7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/which.zig b/src/which.zig
index 0b8e5f1f8..e6ec2c74d 100644
--- a/src/which.zig
+++ b/src/which.zig
@@ -6,8 +6,11 @@ fn isValid(buf: *[std.fs.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8
std.mem.copy(u8, buf[segment.len + 1 ..], bin);
buf[segment.len + 1 + bin.len ..][0] = 0;
const filepath = buf[0 .. segment.len + 1 + bin.len :0];
-
- std.os.accessZ(filepath, std.os.X_OK) catch return null;
+ var stat = std.mem.zeroes(std.os.Stat);
+ // we cannot use access() here even though all we want to do now here is check it is executable
+ // directories can be considered executable
+ if (std.c.stat(filepath, &stat) != 0) return null;
+ if (stat.mode & std.os.S_IXUSR == 0 or stat.mode & std.os.S_IFREG == 0) return null;
return @intCast(u16, filepath.len);
}