Skip to content

Commit 5c7cbcf

Browse files
Always use kernel_timespec as timespec
The `timespec` structure is now defined to be the `__kernel_timespec` type, and all syscalls/ABI definitions that reference `timespec` withh either be modified to work or be altered to return a timespec from existing time components - see the new `makeTimespec` function for how this is done.
1 parent d136355 commit 5c7cbcf

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/std/os/linux.zig

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7541,15 +7541,22 @@ pub const POSIX_FADV = switch (native_arch) {
75417541
};
75427542

75437543
/// The timespec struct used by the kernel.
7544-
pub const kernel_timespec = extern struct {
7544+
pub const timespec = extern struct {
7545+
/// Seconds.
75457546
sec: i64,
7547+
/// Nanoseconds.
75467548
nsec: i64,
7547-
};
75487549

7549-
// https://github.com/ziglang/zig/issues/4726#issuecomment-2190337877
7550-
pub const timespec = if (native_arch == .riscv32) kernel_timespec else extern struct {
7551-
sec: isize,
7552-
nsec: isize,
7550+
pub fn makeTimespec(sec: anytype, nsec: anytype) timespec {
7551+
comptime {
7552+
const si = @typeInfo(@TypeOf(sec));
7553+
assert(si == .int and (si.int.bits == 32 or si.int.bits == 64));
7554+
const nsi = @typeInfo(@TypeOf(sec));
7555+
assert(nsi == .int and (nsi.int.bits == 32 or nsi.int.bits == 64));
7556+
}
7557+
7558+
return .{ .sec = @intCast(sec), .nsec = @intCast(nsec) };
7559+
}
75537560
};
75547561

75557562
pub const XDP = struct {

0 commit comments

Comments
 (0)