diff --git a/src/main.zig b/src/main.zig index c40cc22..fef8da3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -135,8 +135,9 @@ pub fn main(init: std.process.Init) !void { var arena = std.heap.ArenaAllocator.init(init.gpa); defer arena.deinit(); - var sfb = std.heap.stackFallback(1 << 20, arena.allocator()); - const allocator = sfb.get(); + var bfa_buf: [1 << 20]u8 = undefined; + var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, arena.allocator()); + const allocator = bfa.allocator(); const stdout_file = Io.File.stdout(); @@ -1031,11 +1032,19 @@ fn onCompletion(io: *ourio.Ring, task: ourio.Task) anyerror!void { const dir: Io.Dir = .{ .handle = fd }; if (cmd.opts.useHyperlinks()) { - var proc_path_buf: [64]u8 = undefined; - const proc_path = try std.fmt.bufPrint(&proc_path_buf, "/proc/self/fd/{d}", .{fd}); var buf: [Io.Dir.max_path_bytes]u8 = undefined; - const n = try Io.Dir.readLinkAbsolute(cmd.std_io, proc_path, &buf); - cmd.current_directory = try cmd.arena.dupeZ(u8, buf[0..n]); + const resolved: []const u8 = if (builtin.os.tag == .macos) resolved: { + // macOS has no /proc; use fcntl(F_GETPATH) to resolve the fd to a path. + const rc = std.c.fcntl(fd, std.c.F.GETPATH, &buf); + if (rc != 0) return error.FileNotFound; + break :resolved std.mem.sliceTo(&buf, 0); + } else resolved: { + var proc_path_buf: [64]u8 = undefined; + const proc_path = try std.fmt.bufPrint(&proc_path_buf, "/proc/self/fd/{d}", .{fd}); + const n = try Io.Dir.readLinkAbsolute(cmd.std_io, proc_path, &buf); + break :resolved buf[0..n]; + }; + cmd.current_directory = try cmd.arena.dupeZ(u8, resolved); } var temp_results: std.ArrayListUnmanaged(MinimalEntry) = .empty;