summaryrefslogtreecommitdiff
path: root/build/patches/ghostty_kitty.zig
blob: a86d62d3af78896bfd2661de7d0a6d891366e9e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/// pardes (build.zig): `path`, opened for reading only once it is known
/// to be a regular file. Elsewhere than Linux, a stat by path first.
fn pardesOpenRegular(io: std.Io, path: []const u8) !std.Io.File {
    if (comptime builtin.target.os.tag != .linux) {
        if ((try std.Io.Dir.cwd().statFile(io, path, .{})).kind != .file) return error.NotRegularFile;
        return std.Io.Dir.cwd().openFile(io, path, .{});
    }
    const probe = try std.Io.Dir.cwd().openFile(io, path, .{ .path_only = true });
    defer probe.close(io);
    const stat = try probe.stat(io);
    if (stat.kind != .file) return error.NotRegularFile;
    var buf: [32]u8 = undefined;
    const same = std.fmt.bufPrint(&buf, "/proc/self/fd/{d}", .{probe.handle}) catch unreachable;
    return std.Io.Dir.cwd().openFile(io, same, .{});
}