diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 7e52f136567f575610e5262022fc3996893c38fa..3899af5adc487cbf5a22b551eb8baf03bce472b3 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -14242,8 +14242,8 @@ fn timestampToPosix(nanoseconds: i96) posix.timespec { pub fn setTimestampToPosix(set_ts: File.SetTimestamp) posix.timespec { return switch (set_ts) { - .unchanged => .OMIT, - .now => .NOW, + .unchanged => posix.UTIME.OMIT, + .now => posix.UTIME.NOW, .new => |t| timestampToPosix(t.nanoseconds), }; } diff --git a/lib/std/c.zig b/lib/std/c.zig index 3e1a2d28ca6473a6f77c707ac987808541046fa5..73c9ef0b13d72d95b531a25c3c9601ee81f34743 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -94,13 +94,36 @@ pub const off_t = switch (native_os) { else => i64, }; +/// For use with `utimensat` and `futimens`. +pub const UTIME = switch (native_os) { + .dragonfly, .freebsd, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .wasi => struct { + pub const NOW: timespec = .{ .sec = 0, .nsec = -1 }; + pub const OMIT: timespec = .{ .sec = 0, .nsec = -2 }; + }, + .emscripten => emscripten.UTIME, + .haiku => struct { + pub const NOW: timespec = .{ .sec = 0, .nsec = 1000000000 }; + pub const OMIT: timespec = .{ .sec = 0, .nsec = 1000000001 }; + }, + .linux => linux.UTIME, + .netbsd => struct { + pub const NOW: timespec = .{ .sec = 0, .nsec = 0x3fffffff }; + pub const OMIT: timespec = .{ .sec = 0, .nsec = 0x3ffffffe }; + }, + .openbsd, .serenity => struct { + pub const NOW: timespec = .{ .sec = 0, .nsec = -2 }; + pub const OMIT: timespec = .{ .sec = 0, .nsec = -1 }; + }, + else => void, +}; + pub const timespec = switch (native_os) { .linux => linux.timespec, .emscripten => emscripten.timespec, // lib/libc/include/wasm-wasi-musl/__struct_timespec.h .wasi => extern struct { sec: time_t, - nsec: isize, + nsec: c_long, pub fn fromTimestamp(tm: wasi.timestamp_t) timespec { const sec: wasi.timestamp_t = tm / 1_000_000_000; @@ -115,74 +138,12 @@ pub const timespec = switch (native_os) { return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) + @as(wasi.timestamp_t, @intCast(ts.nsec)); } - - // lib/libc/include/wasm-wasi-musl/__header_sys_stat.h - - /// For use with `utimensat` and `futimens`. - pub const NOW: timespec = .{ - .sec = 0, - .nsec = -1, - }; - - /// For use with `utimensat` and `futimens`. - pub const OMIT: timespec = .{ - .sec = 0, - .nsec = -2, - }; }, // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20 - .windows, .serenity => extern struct { + .dragonfly, .freebsd, .netbsd, .openbsd, .illumos, .haiku, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => extern struct { sec: time_t, nsec: c_long, }, - .dragonfly, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { - sec: isize, - nsec: isize, - - /// For use with `utimensat` and `futimens`. - pub const NOW: timespec = .{ - .sec = 0, - .nsec = -1, - }; - - /// For use with `utimensat` and `futimens`. - pub const OMIT: timespec = .{ - .sec = 0, - .nsec = -2, - }; - }, - .netbsd, .illumos => extern struct { - sec: i64, - nsec: isize, - - /// For use with `utimensat` and `futimens`. - pub const NOW: timespec = .{ - .sec = 0, - .nsec = 0x3fffffff, - }; - - /// For use with `utimensat` and `futimens`. - pub const OMIT: timespec = .{ - .sec = 0, - .nsec = 0x3ffffffe, - }; - }, - .openbsd, .haiku => extern struct { - sec: time_t, - nsec: isize, - - /// For use with `utimensat` and `futimens`. - pub const NOW: timespec = .{ - .sec = 0, // ignored - .nsec = -2, - }; - - /// For use with `utimensat` and `futimens`. - pub const OMIT: timespec = .{ - .sec = 0, // ignored - .nsec = -1, - }; - }, else => void, }; @@ -4128,7 +4089,7 @@ pub const in6_pktinfo = switch (native_os) { }; pub const itimerspec = switch (native_os) { .linux => linux.itimerspec, - .haiku => extern struct { + .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .windows, .wasi => extern struct { interval: timespec, value: timespec, }, @@ -7037,18 +6998,19 @@ pub const stack_t = switch (native_os) { }; pub const time_t = switch (native_os) { .linux => linux.time_t, + .dragonfly, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_long, .emscripten => emscripten.time_t, - .haiku, .dragonfly => isize, - // lib/libc/include/wasm-wasi-musl/__typedef_time_t.h + .freebsd, .haiku => if (native_arch == .x86) c_int else c_longlong, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L47 - else => i64, + // lib/libc/include/wasm-wasi-musl/__typedef_time_t.h + .netbsd, .openbsd, .serenity, .wasi => c_longlong, + else => void, }; pub const suseconds_t = switch (native_os) { + .dragonfly, .freebsd, .openbsd, .illumos => c_long, + .netbsd, .haiku, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_int, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L49 - .illumos, .serenity => i64, - .freebsd, .dragonfly => c_long, - .netbsd => c_int, - .haiku => i32, + .serenity, .wasi => c_longlong, else => void, }; @@ -7059,32 +7021,20 @@ pub const timeval = switch (native_os) { sec: c_long, usec: c_long, }, - .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { - sec: c_long, - usec: i32, - }, // https://github.com/SerenityOS/serenity/blob/6b6eca0631c893c5f8cfb8274cdfe18e2d0637c0/Kernel/API/POSIX/sys/time.h#L15-L18 - .dragonfly, .netbsd, .freebsd, .illumos, .serenity => extern struct { + .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .wasi => extern struct { /// seconds sec: time_t, /// microseconds usec: suseconds_t, }, - .openbsd => extern struct { - sec: time_t, - usec: c_long, - }, else => void, }; pub const timezone = switch (native_os) { .linux => linux.timezone, .emscripten => emscripten.timezone, - .openbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { - minuteswest: i32, - dsttime: i32, - }, // https://github.com/SerenityOS/serenity/blob/ba776390b5878ec0be1a9e595a3471a6cfe0a0cf/Userland/Libraries/LibC/sys/time.h#L19-L22 - .serenity => extern struct { + .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows, .wasi => extern struct { minuteswest: c_int, dsttime: c_int, }, diff --git a/lib/std/os/emscripten.zig b/lib/std/os/emscripten.zig index 648407b20cf187f44ccf74234ed1b0621d206039..ba4d9082a00093a73160242aad84fcf4feabdd58 100644 --- a/lib/std/os/emscripten.zig +++ b/lib/std/os/emscripten.zig @@ -730,7 +730,7 @@ pub const sockaddr = c.sockaddr; pub const blksize_t = i32; pub const nlink_t = u32; // https://github.com/emscripten-core/emscripten/blob/946ab574ae39401b51e75cd5257d894ae732ab54/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L140 -pub const time_t = i64; +pub const time_t = c_longlong; pub const mode_t = u32; pub const off_t = i64; pub const ino_t = u64; @@ -766,29 +766,22 @@ pub const stack_t = extern struct { size: usize, }; +/// For use with `utimensat` and `futimens`. +// https://github.com/emscripten-core/emscripten/blob/d72d7226f4733af8ff993dec70198cf09a24142d/system/lib/libc/musl/include/sys/stat.h#L77-L78 +pub const UTIME = struct { + pub const NOW: timespec = .{ .sec = 0, .nsec = 0x3fffffff }; + pub const OMIT: timespec = .{ .sec = 0, .nsec = 0x3ffffffe }; +}; + // https://github.com/emscripten-core/emscripten/blob/946ab574ae39401b51e75cd5257d894ae732ab54/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L284 pub const timespec = extern struct { sec: time_t, - nsec: isize, - - // https://github.com/emscripten-core/emscripten/blob/d72d7226f4733af8ff993dec70198cf09a24142d/system/lib/libc/musl/include/sys/stat.h#L77-L78 - - /// For use with `utimensat` and `futimens`. - pub const NOW: timespec = .{ - .sec = 0, - .nsec = 0x3fffffff, - }; - - /// For use with `utimensat` and `futimens`. - pub const OMIT: timespec = .{ - .sec = 0, - .nsec = 0x3ffffffe, - }; + nsec: c_long, }; pub const timezone = extern struct { - minuteswest: i32, - dsttime: i32, + minuteswest: c_int, + dsttime: c_int, }; pub const utsname = extern struct { diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 9cd050d8cda42b2a57e80bc3f3f704602f4fe196..12b3e482b51d41a48cfe836f5e45a1a4b1c368c0 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5950,11 +5950,6 @@ pub const S = struct { } }; -pub const UTIME = struct { - pub const NOW = 0x3fffffff; - pub const OMIT = 0x3ffffffe; -}; - const TFD_TIMER = packed struct(u32) { ABSTIME: bool = false, CANCEL_ON_SET: bool = false, @@ -8705,22 +8700,16 @@ pub const kernel_timespec = extern struct { }; }; +/// For use with `utimensat` and `futimens`. +pub const UTIME = struct { + pub const NOW: timespec = .{ .sec = 0, .nsec = 0x3fffffff }; + pub const OMIT: timespec = .{ .sec = 0, .nsec = 0x3ffffffe }; +}; + // https://github.com/ziglang/zig/issues/4726#issuecomment-2190337877 pub const timespec = if (native_arch == .hexagon or native_arch == .riscv32) kernel_timespec else extern struct { sec: isize, nsec: isize, - - /// For use with `utimensat` and `futimens`. - pub const NOW: timespec = .{ - .sec = 0, - .nsec = 0x3fffffff, - }; - - /// For use with `utimensat` and `futimens`. - pub const OMIT: timespec = .{ - .sec = 0, - .nsec = 0x3ffffffe, - }; }; pub const XDP = struct { diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 36e038c6414ecffa6a46ce694452bb01ae0cc7cb..39d226613733c20497b21ebecfacfed9481d6704 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -174,6 +174,7 @@ pub const timespec = system.timespec; pub const timestamp_t = system.timestamp_t; pub const timeval = system.timeval; pub const timezone = system.timezone; +pub const UTIME = system.UTIME; pub const uid_t = system.uid_t; pub const user_desc = system.user_desc; pub const utsname = system.utsname;