Commit 7a4ed10981

Andrew Kelley <andrew@ziglang.org>
2019-02-01 00:47:45
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.
1 parent 28873e7
Changed files (3)
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.
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;
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);