authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-01-02 00:55:05 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-01-02 00:55:05 -08:00
log905e29b6760035e63b7dc027a4c355ff392bb454
tree3119e659cf34f4578ff10534a83aba09b1afc9fe
parent1f7f862f7d7b4c7de5b61668a2b5c86db173275b

add fd_realpath


1 files changed, 14 insertions(+), 0 deletions(-)

src/lib.zig+14
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const string = []const u8;
33const assert = std.debug.assert;
4const builtin = @import("builtin");
45
56pub fn fmtByteCountIEC(alloc: std.mem.Allocator, b: u64) !string {
67 return try reduceNumber(alloc, b, 1024, "B", "KMGTPEZYRQ");
......@@ -833,3 +834,16 @@ pub fn RingBuffer(comptime T: type, comptime capacity: usize) type {
833834 }
834835 };
835836}
837
838pub fn fd_realpath(fd: std.os.fd_t) ![std.fs.MAX_PATH_BYTES:0]u8 {
839 switch (builtin.os.tag) {
840 .linux => {
841 var buf = std.mem.zeroes([64]u8);
842 var res = std.mem.zeroes([std.fs.MAX_PATH_BYTES:0]u8);
843 const str = try std.fmt.bufPrint(&buf, "/proc/self/fd/{d}", .{fd});
844 _ = try std.os.readlink(str, &res);
845 return res;
846 },
847 else => @compileError("not implemented!"),
848 }
849}