feature. See also
. The project being documented here (as the example) is the Zig library itself.
c.timespec
pub const timespec = switch (native_os)
File
Code
pub const timespec = switch (native_os) {
.linux => linux.timespec,
.emscripten => emscripten.timespec,
.wasi => extern struct {
sec: time_t,
nsec: c_long,
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));
}
},
.dragonfly, .freebsd, .netbsd, .openbsd, .illumos, .haiku, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => extern struct {
sec: time_t,
nsec: c_long,
},
else => void,
}