diff options
Diffstat (limited to '')
| -rw-r--r-- | src/exe.zig | 2 | ||||
| -rw-r--r-- | src/fs.zig | 21 | ||||
| -rw-r--r-- | src/gen.zig | 2 |
3 files changed, 12 insertions, 13 deletions
diff --git a/src/exe.zig b/src/exe.zig index 06e7a4d..5776538 100644 --- a/src/exe.zig +++ b/src/exe.zig @@ -46,7 +46,7 @@ fn pandocWorker(ctx: *Context, page: []const u8) !void { ); // get mtime of the source document - const mtime = try fs.getMtime(ctx.allocator(), source_path); + const mtime = try fs.getMtime(source_path); const mtime_str = try fs.formatMtime(ctx.allocator(), mtime, "%s"); defer ctx.allocator().free(mtime_str); diff --git a/src/fs.zig b/src/fs.zig index d29ee05..2a141d1 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -100,22 +100,21 @@ pub fn joinPathAndFilename(alloc: std.mem.Allocator, paths: []const []const u8, return try std.fs.path.join(alloc, paths2); } -pub fn getMtime(alloc: std.mem.Allocator, path: []const u8) !std.os.linux.timespec { - const attr = try alloc.create(std.os.linux.Stat); - defer alloc.destroy(attr); +pub fn getMtime(path: []const u8) !std.posix.timespec { + const fd = try std.fs.cwd().openFile(path, .{ .mode = .read_only }); + defer fd.close(); - const pathZ = try alloc.dupeZ(u8, path); - defer alloc.free(pathZ); + const meta = try fd.metadata(); + const mtime = meta.modified(); - // use stat to get mtime - const rc = std.os.linux.stat(pathZ, attr); - if (rc < 0) return error.UnknownStatError; - - return attr.mtime(); + return .{ + .sec = std.math.cast(isize, @divFloor(mtime, std.time.ns_per_s)) orelse std.math.maxInt(isize), + .nsec = std.math.cast(isize, @mod(mtime, std.time.ns_per_s)) orelse std.math.maxInt(isize), + }; } // use libc strftime to format time string -pub fn formatMtime(alloc: std.mem.Allocator, mtime: std.os.linux.timespec, fmt: [*c]const u8) ![]const u8 { +pub fn formatMtime(alloc: std.mem.Allocator, mtime: std.posix.timespec, fmt: [*c]const u8) ![]const u8 { const mtime_str = try alloc.alloc(u8, std.os.linux.PATH_MAX); var tm: c.struct_tm = undefined; _ = c.localtime_r(&mtime.sec, &tm); diff --git a/src/gen.zig b/src/gen.zig index 0504d39..a02503b 100644 --- a/src/gen.zig +++ b/src/gen.zig @@ -109,7 +109,7 @@ fn genSite(ctx: *Context) !void { // build a single html file fn build(allocator: std.mem.Allocator, w: std.io.AnyWriter, page_name: []const u8, srcpath: []const u8) !void { - const mtime = try fs.getMtime(allocator, srcpath); + const mtime = try fs.getMtime(srcpath); const mtime_str = try fs.formatMtime(allocator, mtime, "%F"); defer allocator.free(mtime_str); |