| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const builtin = @import("builtin"); |
| 4 | 5 | |
| 5 | 6 | pub fn fmtByteCountIEC(alloc: std.mem.Allocator, b: u64) !string { |
| 6 | 7 | return try reduceNumber(alloc, b, 1024, "B", "KMGTPEZYRQ"); |
| ... | ... | @@ -833,3 +834,16 @@ pub fn RingBuffer(comptime T: type, comptime capacity: usize) type { |
| 833 | 834 | } |
| 834 | 835 | }; |
| 835 | 836 | } |
| 837 | |
| 838 | pub 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 | } |