| ... | @@ -121,6 +121,7 @@ pub const blkcnt_t = system.blkcnt_t; | ... | @@ -121,6 +121,7 @@ pub const blkcnt_t = system.blkcnt_t; |
| 121 | pub const blksize_t = system.blksize_t; | 121 | pub const blksize_t = system.blksize_t; |
| 122 | pub const clock_t = system.clock_t; | 122 | pub const clock_t = system.clock_t; |
| 123 | pub const clockid_t = system.clockid_t; | 123 | pub const clockid_t = system.clockid_t; |
| | 124 | pub const timerfd_clockid_t = system.timerfd_clockid_t; |
| 124 | pub const cpu_set_t = system.cpu_set_t; | 125 | pub const cpu_set_t = system.cpu_set_t; |
| 125 | pub const dev_t = system.dev_t; | 126 | pub const dev_t = system.dev_t; |
| 126 | pub const dl_phdr_info = system.dl_phdr_info; | 127 | pub const dl_phdr_info = system.dl_phdr_info; |
| ... | @@ -155,6 +156,7 @@ pub const socklen_t = system.socklen_t; | ... | @@ -155,6 +156,7 @@ pub const socklen_t = system.socklen_t; |
| 155 | pub const stack_t = system.stack_t; | 156 | pub const stack_t = system.stack_t; |
| 156 | pub const time_t = system.time_t; | 157 | pub const time_t = system.time_t; |
| 157 | pub const timespec = system.timespec; | 158 | pub const timespec = system.timespec; |
| | 159 | pub const timestamp_t = system.timestamp_t; |
| 158 | pub const timeval = system.timeval; | 160 | pub const timeval = system.timeval; |
| 159 | pub const timezone = system.timezone; | 161 | pub const timezone = system.timezone; |
| 160 | pub const ucontext_t = system.ucontext_t; | 162 | pub const ucontext_t = system.ucontext_t; |
| ... | @@ -5653,13 +5655,13 @@ pub fn dl_iterate_phdr( | ... | @@ -5653,13 +5655,13 @@ pub fn dl_iterate_phdr( |
| 5653 | | 5655 | |
| 5654 | pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError; | 5656 | pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError; |
| 5655 | | 5657 | |
| 5656 | /// TODO: change this to return the timespec as a return value | 5658 | pub fn clock_gettime(clock_id: clockid_t) ClockGetTimeError!timespec { |
| 5657 | pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void { | 5659 | var tp: timespec = undefined; |
| 5658 | if (native_os == .wasi and !builtin.link_libc) { | 5660 | if (native_os == .wasi and !builtin.link_libc) { |
| 5659 | var ts: wasi.timestamp_t = undefined; | 5661 | var ts: timestamp_t = undefined; |
| 5660 | switch (system.clock_time_get(clock_id, 1, &ts)) { | 5662 | switch (system.clock_time_get(clock_id, 1, &ts)) { |
| 5661 | .SUCCESS => { | 5663 | .SUCCESS => { |
| 5662 | tp.* = .{ | 5664 | tp = .{ |
| 5663 | .sec = @intCast(ts / std.time.ns_per_s), | 5665 | .sec = @intCast(ts / std.time.ns_per_s), |
| 5664 | .nsec = @intCast(ts % std.time.ns_per_s), | 5666 | .nsec = @intCast(ts % std.time.ns_per_s), |
| 5665 | }; | 5667 | }; |
| ... | @@ -5667,7 +5669,7 @@ pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void | ... | @@ -5667,7 +5669,7 @@ pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void |
| 5667 | .INVAL => return error.UnsupportedClock, | 5669 | .INVAL => return error.UnsupportedClock, |
| 5668 | else => |err| return unexpectedErrno(err), | 5670 | else => |err| return unexpectedErrno(err), |
| 5669 | } | 5671 | } |
| 5670 | return; | 5672 | return tp; |
| 5671 | } | 5673 | } |
| 5672 | if (native_os == .windows) { | 5674 | if (native_os == .windows) { |
| 5673 | if (clock_id == .REALTIME) { | 5675 | if (clock_id == .REALTIME) { |
| ... | @@ -5676,19 +5678,19 @@ pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void | ... | @@ -5676,19 +5678,19 @@ pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void |
| 5676 | // FileTime has a granularity of 100 nanoseconds and uses the NTFS/Windows epoch. | 5678 | // FileTime has a granularity of 100 nanoseconds and uses the NTFS/Windows epoch. |
| 5677 | const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime; | 5679 | const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime; |
| 5678 | const ft_per_s = std.time.ns_per_s / 100; | 5680 | const ft_per_s = std.time.ns_per_s / 100; |
| 5679 | tp.* = .{ | 5681 | tp = .{ |
| 5680 | .sec = @as(i64, @intCast(ft64 / ft_per_s)) + std.time.epoch.windows, | 5682 | .sec = @as(i64, @intCast(ft64 / ft_per_s)) + std.time.epoch.windows, |
| 5681 | .nsec = @as(c_long, @intCast(ft64 % ft_per_s)) * 100, | 5683 | .nsec = @as(c_long, @intCast(ft64 % ft_per_s)) * 100, |
| 5682 | }; | 5684 | }; |
| 5683 | return; | 5685 | return tp; |
| 5684 | } else { | 5686 | } else { |
| 5685 | // TODO POSIX implementation of CLOCK.MONOTONIC on Windows. | 5687 | // TODO POSIX implementation of CLOCK.MONOTONIC on Windows. |
| 5686 | return error.UnsupportedClock; | 5688 | return error.UnsupportedClock; |
| 5687 | } | 5689 | } |
| 5688 | } | 5690 | } |
| 5689 | | 5691 | |
| 5690 | switch (errno(system.clock_gettime(clock_id, tp))) { | 5692 | switch (errno(system.clock_gettime(clock_id, &tp))) { |
| 5691 | .SUCCESS => return, | 5693 | .SUCCESS => return tp, |
| 5692 | .FAULT => unreachable, | 5694 | .FAULT => unreachable, |
| 5693 | .INVAL => return error.UnsupportedClock, | 5695 | .INVAL => return error.UnsupportedClock, |
| 5694 | else => |err| return unexpectedErrno(err), | 5696 | else => |err| return unexpectedErrno(err), |
| ... | @@ -5697,7 +5699,7 @@ pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void | ... | @@ -5697,7 +5699,7 @@ pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void |
| 5697 | | 5699 | |
| 5698 | pub fn clock_getres(clock_id: clockid_t, res: *timespec) ClockGetTimeError!void { | 5700 | pub fn clock_getres(clock_id: clockid_t, res: *timespec) ClockGetTimeError!void { |
| 5699 | if (native_os == .wasi and !builtin.link_libc) { | 5701 | if (native_os == .wasi and !builtin.link_libc) { |
| 5700 | var ts: wasi.timestamp_t = undefined; | 5702 | var ts: timestamp_t = undefined; |
| 5701 | switch (system.clock_res_get(@bitCast(clock_id), &ts)) { | 5703 | switch (system.clock_res_get(@bitCast(clock_id), &ts)) { |
| 5702 | .SUCCESS => res.* = .{ | 5704 | .SUCCESS => res.* = .{ |
| 5703 | .sec = @intCast(ts / std.time.ns_per_s), | 5705 | .sec = @intCast(ts / std.time.ns_per_s), |
| ... | @@ -5910,8 +5912,7 @@ pub fn res_mkquery( | ... | @@ -5910,8 +5912,7 @@ pub fn res_mkquery( |
| 5910 | q[i + 3] = class; | 5912 | q[i + 3] = class; |
| 5911 | | 5913 | |
| 5912 | // Make a reasonably unpredictable id | 5914 | // Make a reasonably unpredictable id |
| 5913 | var ts: timespec = undefined; | 5915 | const ts = clock_gettime(.REALTIME) catch unreachable; |
| 5914 | clock_gettime(.REALTIME, &ts) catch {}; | | |
| 5915 | const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.nsec))); | 5916 | const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.nsec))); |
| 5916 | const unsec: UInt = @bitCast(ts.nsec); | 5917 | const unsec: UInt = @bitCast(ts.nsec); |
| 5917 | const id: u32 = @truncate(unsec + unsec / 65536); | 5918 | const id: u32 = @truncate(unsec + unsec / 65536); |
| ... | @@ -7293,7 +7294,7 @@ pub const TimerFdCreateError = error{ | ... | @@ -7293,7 +7294,7 @@ pub const TimerFdCreateError = error{ |
| 7293 | pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError; | 7294 | pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError; |
| 7294 | pub const TimerFdSetError = TimerFdGetError || error{Canceled}; | 7295 | pub const TimerFdSetError = TimerFdGetError || error{Canceled}; |
| 7295 | | 7296 | |
| 7296 | pub fn timerfd_create(clock_id: clockid_t, flags: system.TFD) TimerFdCreateError!fd_t { | 7297 | pub fn timerfd_create(clock_id: system.timerfd_clockid_t, flags: system.TFD) TimerFdCreateError!fd_t { |
| 7297 | const rc = system.timerfd_create(clock_id, @bitCast(flags)); | 7298 | const rc = system.timerfd_create(clock_id, @bitCast(flags)); |
| 7298 | return switch (errno(rc)) { | 7299 | return switch (errno(rc)) { |
| 7299 | .SUCCESS => @intCast(rc), | 7300 | .SUCCESS => @intCast(rc), |