diff options
| -rw-r--r-- | src/fs.zig | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/fs.zig b/src/fs.zig index 49041e2..7a8717a 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -117,13 +117,17 @@ pub fn get_mtime(alloc: std.mem.Allocator, path: []const u8) !std.os.linux.times // use libc strftime to format time string pub fn format_mtime(alloc: std.mem.Allocator, mtime: std.os.linux.timespec, fmt: [*c]const u8) ![]const u8 { const mtime_str = try alloc.alloc(u8, std.os.linux.PATH_MAX); - const tm = c.localtime(&mtime.sec); - const n = c.strftime( + var tm: c.struct_tm = undefined; + _ = c.localtime_r(&mtime.sec, &tm); + const rc = c.strftime( mtime_str.ptr, mtime_str.len, fmt, - tm, + &tm, ); - if (n < 0) return error.UnknownStrftimeError; - return try alloc.realloc(mtime_str, n); + switch (std.posix.errno(rc)) { + .SUCCESS => {}, + else => |err| return std.posix.unexpectedErrno(err), + } + return try alloc.realloc(mtime_str, rc); } |