| author | |
| committer | |
| log | 7a4ed10981cf7ac5bed93b2c9bad280ad31c50cf |
| tree | aceb25ff45167ca9e827bf94442d5cf44ee3280c |
| parent | 28873e762295d0e03bf913d45d5317aae8d57bcd |
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 { | ... | @@ -73,8 +73,8 @@ pub const sockaddr_in6 = extern struct { |
| 73 | }; | 73 | }; |
| 74 | 74 | ||
| 75 | pub const timeval = extern struct { | 75 | pub const timeval = extern struct { |
| 76 | tv_sec: isize, | 76 | tv_sec: c_long, |
| 77 | tv_usec: isize, | 77 | tv_usec: i32, |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | pub const timezone = extern struct { | 80 | pub const timezone = extern struct { |
| ... | @@ -176,6 +176,24 @@ pub const kevent64_s = extern struct { | ... | @@ -176,6 +176,24 @@ pub const kevent64_s = extern struct { |
| 176 | ext: [2]u64, | 176 | ext: [2]u64, |
| 177 | }; | 177 | }; |
| 178 | 178 | ||
| 179 | pub const mach_port_t = c_uint; | ||
| 180 | pub const clock_serv_t = mach_port_t; | ||
| 181 | pub const clock_res_t = c_int; | ||
| 182 | pub const mach_port_name_t = natural_t; | ||
| 183 | pub const natural_t = c_uint; | ||
| 184 | pub const mach_timespec_t = extern struct { | ||
| 185 | tv_sec: c_uint, | ||
| 186 | tv_nsec: clock_res_t, | ||
| 187 | }; | ||
| 188 | pub const kern_return_t = c_int; | ||
| 189 | pub const host_t = mach_port_t; | ||
| 190 | pub const CALENDAR_CLOCK = 1; | ||
| 191 | |||
| 192 | pub extern fn mach_host_self() mach_port_t; | ||
| 193 | pub extern fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t; | ||
| 194 | pub extern fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clock_serv: ?[*]clock_serv_t) kern_return_t; | ||
| 195 | pub extern fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; | ||
| 196 | |||
| 179 | // sys/types.h on macos uses #pragma pack() so these checks are | 197 | // sys/types.h on macos uses #pragma pack() so these checks are |
| 180 | // to make sure the struct is laid out the same. These values were | 198 | // to make sure the struct is laid out the same. These values were |
| 181 | // produced from C code using the offsetof macro. | 199 | // 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; | ... | @@ -44,7 +44,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int; |
| 44 | pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize; | 44 | pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize; |
| 45 | pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8; | 45 | pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8; |
| 46 | pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int; | 46 | pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int; |
| 47 | pub extern "c" fn gettimeofday(tv: ?*timeval, tz: ?*timezone) c_int; | 47 | pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; |
| 48 | pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; | 48 | pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; |
| 49 | pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; | 49 | pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; |
| 50 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; | 50 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; |
std/os/time.zig-2| ... | @@ -79,8 +79,6 @@ fn milliTimestampWindows() u64 { | ... | @@ -79,8 +79,6 @@ fn milliTimestampWindows() u64 { |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | fn milliTimestampDarwin() u64 { | 81 | fn milliTimestampDarwin() u64 { |
| 82 | //Sources suggest MacOS 10.12 has support for | ||
| 83 | // posix clock_gettime. | ||
| 84 | var tv: darwin.timeval = undefined; | 82 | var tv: darwin.timeval = undefined; |
| 85 | var err = darwin.gettimeofday(&tv, null); | 83 | var err = darwin.gettimeofday(&tv, null); |
| 86 | debug.assert(err == 0); | 84 | debug.assert(err == 0); |