authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-31 18:47:45-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-31 18:57:53-05:00
log7a4ed10981cf7ac5bed93b2c9bad280ad31c50cf
treeaceb25ff45167ca9e827bf94442d5cf44ee3280c
parent28873e762295d0e03bf913d45d5317aae8d57bcd

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.

3 files changed, 21 insertions(+), 5 deletions(-)

std/c/darwin.zig+20-2
......@@ -73,8 +73,8 @@ pub const sockaddr_in6 = extern struct {
7373};
7474
7575pub const timeval = extern struct {
76 tv_sec: isize,
77 tv_usec: isize,
76 tv_sec: c_long,
77 tv_usec: i32,
7878};
7979
8080pub const timezone = extern struct {
......@@ -176,6 +176,24 @@ pub const kevent64_s = extern struct {
176176 ext: [2]u64,
177177};
178178
179pub const mach_port_t = c_uint;
180pub const clock_serv_t = mach_port_t;
181pub const clock_res_t = c_int;
182pub const mach_port_name_t = natural_t;
183pub const natural_t = c_uint;
184pub const mach_timespec_t = extern struct {
185 tv_sec: c_uint,
186 tv_nsec: clock_res_t,
187};
188pub const kern_return_t = c_int;
189pub const host_t = mach_port_t;
190pub const CALENDAR_CLOCK = 1;
191
192pub extern fn mach_host_self() mach_port_t;
193pub extern fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t;
194pub extern fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clock_serv: ?[*]clock_serv_t) kern_return_t;
195pub extern fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
196
179197// sys/types.h on macos uses #pragma pack() so these checks are
180198// to make sure the struct is laid out the same. These values were
181199// produced from C code using the offsetof macro.
std/c/index.zig+1-1
......@@ -44,7 +44,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
4444pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize;
4545pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8;
4646pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int;
47pub extern "c" fn gettimeofday(tv: ?*timeval, tz: ?*timezone) c_int;
47pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
4848pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
4949pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
5050pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
std/os/time.zig-2
......@@ -79,8 +79,6 @@ fn milliTimestampWindows() u64 {
7979}
8080
8181fn milliTimestampDarwin() u64 {
82 //Sources suggest MacOS 10.12 has support for
83 // posix clock_gettime.
8482 var tv: darwin.timeval = undefined;
8583 var err = darwin.gettimeofday(&tv, null);
8684 debug.assert(err == 0);