zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7a4ed10981cf7ac5bed93b2c9bad280ad31c50cf (tree)
parent 28873e762295d0e03bf913d45d5317aae8d57bcd
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 31 Jan 2019 18:47:45 -0500

darwin: fix incorrect timeval struct type

closes #1648

I also added some more extern functions for darwin time functions,
although nothing depends on them currently.

Diffstat:
Mstd/c/darwin.zig | 22++++++++++++++++++++--
Mstd/c/index.zig | 2+-
Mstd/os/time.zig | 2--
3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/std/c/darwin.zig b/std/c/darwin.zig @@ -73,8 +73,8 @@ pub const sockaddr_in6 = extern struct { }; pub const timeval = extern struct { - tv_sec: isize, - tv_usec: isize, + tv_sec: c_long, + tv_usec: i32, }; pub const timezone = extern struct { @@ -176,6 +176,24 @@ pub const kevent64_s = extern struct { ext: [2]u64, }; +pub const mach_port_t = c_uint; +pub const clock_serv_t = mach_port_t; +pub const clock_res_t = c_int; +pub const mach_port_name_t = natural_t; +pub const natural_t = c_uint; +pub const mach_timespec_t = extern struct { + tv_sec: c_uint, + tv_nsec: clock_res_t, +}; +pub const kern_return_t = c_int; +pub const host_t = mach_port_t; +pub const CALENDAR_CLOCK = 1; + +pub extern fn mach_host_self() mach_port_t; +pub extern fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t; +pub extern fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clock_serv: ?[*]clock_serv_t) kern_return_t; +pub extern fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; + // sys/types.h on macos uses #pragma pack() so these checks are // to make sure the struct is laid out the same. These values were // produced from C code using the offsetof macro. diff --git a/std/c/index.zig b/std/c/index.zig @@ -44,7 +44,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int; pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize; pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8; pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int; -pub extern "c" fn gettimeofday(tv: ?*timeval, tz: ?*timezone) c_int; +pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; diff --git a/std/os/time.zig b/std/os/time.zig @@ -79,8 +79,6 @@ fn milliTimestampWindows() u64 { } fn milliTimestampDarwin() u64 { - //Sources suggest MacOS 10.12 has support for - // posix clock_gettime. var tv: darwin.timeval = undefined; var err = darwin.gettimeofday(&tv, null); debug.assert(err == 0);