diff options
| author | Robert Günzler <r@gnzler.io> | 2025-10-03 19:01:17 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2025-10-04 18:41:55 +0200 |
| commit | 4487d75818d36085e3540934f609a997d256f20c (patch) | |
| tree | 324938a906fac51e32ae9d518f211d070ec870b1 /src | |
| parent | fa17cbf6b3486c74305eec5c93f799a4263b7317 (diff) | |
| download | site-4487d75818d36085e3540934f609a997d256f20c.tar.gz | |
use thread-safe localtime_r
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'src')
| -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); } |