Source
pub const timespec = switch (native_os) {
.linux => linux.timespec,
.emscripten => emscripten.timespec,
.wasi => extern struct {
sec: time_t,
nsec: isize,
pub fn fromTimestamp(tm: wasi.timestamp_t) timespec {
const sec: wasi.timestamp_t = tm / 1_000_000_000;
const nsec = tm - sec * 1_000_000_000;
return .{
.sec = @as(time_t, @intCast(sec)),
.nsec = @as(isize, @intCast(nsec)),
};
}
pub fn toTimestamp(ts: timespec) wasi.timestamp_t {
return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) +
@as(wasi.timestamp_t, @intCast(ts.nsec));
}
},
// https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20
.windows, .serenity => extern struct {
sec: time_t,
nsec: c_long,
},
.dragonfly, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
sec: isize,
nsec: isize,
},
.netbsd, .solaris, .illumos => extern struct {
sec: i64,
nsec: isize,
},
.openbsd, .haiku => extern struct {
sec: time_t,
nsec: isize,
},
else => void,
}