Skip to content

Commit

Permalink
Always use kernel_timespec as timespec
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
The-King-of-Toasters committed Sep 29, 2024
1 parent d136355 commit 5c7cbcf
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/std/os/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7541,15 +7541,22 @@ pub const POSIX_FADV = switch (native_arch) {
};

/// The timespec struct used by the kernel.
pub const kernel_timespec = extern struct {
pub const timespec = extern struct {
/// Seconds.
sec: i64,
/// Nanoseconds.
nsec: i64,
};

// https://github.com/ziglang/zig/issues/4726#issuecomment-2190337877
pub const timespec = if (native_arch == .riscv32) kernel_timespec else extern struct {
sec: isize,
nsec: isize,
pub fn makeTimespec(sec: anytype, nsec: anytype) timespec {
comptime {
const si = @typeInfo(@TypeOf(sec));
assert(si == .int and (si.int.bits == 32 or si.int.bits == 64));
const nsi = @typeInfo(@TypeOf(sec));
assert(nsi == .int and (nsi.int.bits == 32 or nsi.int.bits == 64));
}

return .{ .sec = @intCast(sec), .nsec = @intCast(nsec) };
}
};

pub const XDP = struct {
Expand Down

0 comments on commit 5c7cbcf

Please sign in to comment.