| author | |
| committer | |
| log | 8b66dd8c7d2809c3ec86f1eec8acc0a1c184c8c2 |
| tree | 4f6724928de3809b98f448b15aa97f8059086aba |
| parent | c90f936eef81fce3355231c4d79ecfe40df84f7e |
9 files changed, 65 insertions(+), 45 deletions(-)
CMakeLists.txt+2| ... | @@ -507,6 +507,8 @@ set(ZIG_STD_FILES | ... | @@ -507,6 +507,8 @@ set(ZIG_STD_FILES |
| 507 | "os/linux/index.zig" | 507 | "os/linux/index.zig" |
| 508 | "os/linux/x86_64.zig" | 508 | "os/linux/x86_64.zig" |
| 509 | "os/path.zig" | 509 | "os/path.zig" |
| 510 | "os/time.zig" | ||
| 511 | "os/epoch.zig" | ||
| 510 | "os/windows/error.zig" | 512 | "os/windows/error.zig" |
| 511 | "os/windows/index.zig" | 513 | "os/windows/index.zig" |
| 512 | "os/windows/util.zig" | 514 | "os/windows/util.zig" |
std/c/darwin.zig+18| ... | @@ -3,10 +3,28 @@ pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int; | ... | @@ -3,10 +3,28 @@ pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int; |
| 3 | 3 | ||
| 4 | pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize; | 4 | pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize; |
| 5 | 5 | ||
| 6 | pub extern "c" fn mach_absolute_time() u64; | ||
| 7 | pub extern "c" fn mach_timebase_info(&mach_timebase_info_data) void; | ||
| 8 | |||
| 6 | pub use @import("../os/darwin_errno.zig"); | 9 | pub use @import("../os/darwin_errno.zig"); |
| 7 | 10 | ||
| 8 | pub const _errno = __error; | 11 | pub const _errno = __error; |
| 9 | 12 | ||
| 13 | pub const timeval = extern struct { | ||
| 14 | tv_sec: isize, | ||
| 15 | tv_usec: isize, | ||
| 16 | }; | ||
| 17 | |||
| 18 | pub const timezone = extern struct { | ||
| 19 | tz_minuteswest: i32, | ||
| 20 | tz_dsttime: i32, | ||
| 21 | }; | ||
| 22 | |||
| 23 | pub const mach_timebase_info_data = struct { | ||
| 24 | numer: u32, | ||
| 25 | denom: u32, | ||
| 26 | }; | ||
| 27 | |||
| 10 | /// Renamed to Stat to not conflict with the stat function. | 28 | /// Renamed to Stat to not conflict with the stat function. |
| 11 | pub const Stat = extern struct { | 29 | pub const Stat = extern struct { |
| 12 | dev: i32, | 30 | dev: i32, |
std/c/index.zig+1| ... | @@ -40,6 +40,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int; | ... | @@ -40,6 +40,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int; |
| 40 | pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize; | 40 | pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize; |
| 41 | pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8; | 41 | pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8; |
| 42 | pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int; | 42 | pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int; |
| 43 | pub extern "c" fn gettimeofday(&timeval, ?&timezone) c_int; | ||
| 43 | pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int; | 44 | pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int; |
| 44 | pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int; | 45 | pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int; |
| 45 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; | 46 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; |
std/fmt/index.zig+2-1| ... | @@ -86,7 +86,8 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), | ... | @@ -86,7 +86,8 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), |
| 86 | }, | 86 | }, |
| 87 | 's' => { | 87 | 's' => { |
| 88 | state = State.Buf; | 88 | state = State.Buf; |
| 89 | },'.' => { | 89 | }, |
| 90 | '.' => { | ||
| 90 | state = State.Float; | 91 | state = State.Float; |
| 91 | }, | 92 | }, |
| 92 | else => @compileError("Unknown format character: " ++ []u8{c}), | 93 | else => @compileError("Unknown format character: " ++ []u8{c}), |
std/os/darwin.zig+4| ... | @@ -251,6 +251,10 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) u | ... | @@ -251,6 +251,10 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) u |
| 251 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); | 251 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | pub fn gettimeofday(&timeval, ?&timezone) usize { | ||
| 255 | return errnoWrap(c.gettimeofday(timeval, timezone)); | ||
| 256 | } | ||
| 257 | |||
| 254 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { | 258 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { |
| 255 | return errnoWrap(c.nanosleep(req, rem)); | 259 | return errnoWrap(c.nanosleep(req, rem)); |
| 256 | } | 260 | } |
std/os/index.zig+1-44| ... | @@ -18,6 +18,7 @@ pub const posix = switch(builtin.os) { | ... | @@ -18,6 +18,7 @@ pub const posix = switch(builtin.os) { |
| 18 | pub const ChildProcess = @import("child_process.zig").ChildProcess; | 18 | pub const ChildProcess = @import("child_process.zig").ChildProcess; |
| 19 | pub const path = @import("path.zig"); | 19 | pub const path = @import("path.zig"); |
| 20 | pub const File = @import("file.zig").File; | 20 | pub const File = @import("file.zig").File; |
| 21 | pub const time = @import("time.zig"); | ||
| 21 | 22 | ||
| 22 | pub const FileMode = switch (builtin.os) { | 23 | pub const FileMode = switch (builtin.os) { |
| 23 | Os.windows => void, | 24 | Os.windows => void, |
| ... | @@ -1356,50 +1357,6 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) ![]u8 { | ... | @@ -1356,50 +1357,6 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) ![]u8 { |
| 1356 | } | 1357 | } |
| 1357 | } | 1358 | } |
| 1358 | 1359 | ||
| 1359 | pub fn sleep(seconds: usize, nanoseconds: usize) void { | ||
| 1360 | switch(builtin.os) { | ||
| 1361 | Os.linux, Os.macosx, Os.ios => { | ||
| 1362 | posixSleep(u63(seconds), u63(nanoseconds)); | ||
| 1363 | }, | ||
| 1364 | Os.windows => { | ||
| 1365 | const milliseconds = seconds * 1000 + nanoseconds / 1000000; | ||
| 1366 | windows.Sleep(windows.DWORD(milliseconds)); | ||
| 1367 | }, | ||
| 1368 | else => @compileError("Unsupported OS"), | ||
| 1369 | } | ||
| 1370 | } | ||
| 1371 | |||
| 1372 | const u63 = @IntType(false, 63); | ||
| 1373 | pub fn posixSleep(seconds: u63, nanoseconds: u63) void { | ||
| 1374 | var req = posix.timespec { | ||
| 1375 | .tv_sec = seconds, | ||
| 1376 | .tv_nsec = nanoseconds, | ||
| 1377 | }; | ||
| 1378 | var rem: posix.timespec = undefined; | ||
| 1379 | while (true) { | ||
| 1380 | const ret_val = posix.nanosleep(&req, &rem); | ||
| 1381 | const err = posix.getErrno(ret_val); | ||
| 1382 | if (err == 0) return; | ||
| 1383 | switch (err) { | ||
| 1384 | posix.EFAULT => unreachable, | ||
| 1385 | posix.EINVAL => { | ||
| 1386 | // Sometimes Darwin returns EINVAL for no reason. | ||
| 1387 | // We treat it as a spurious wakeup. | ||
| 1388 | return; | ||
| 1389 | }, | ||
| 1390 | posix.EINTR => { | ||
| 1391 | req = rem; | ||
| 1392 | continue; | ||
| 1393 | }, | ||
| 1394 | else => return, | ||
| 1395 | } | ||
| 1396 | } | ||
| 1397 | } | ||
| 1398 | |||
| 1399 | test "os.sleep" { | ||
| 1400 | sleep(0, 1); | ||
| 1401 | } | ||
| 1402 | |||
| 1403 | pub fn posix_setuid(uid: u32) !void { | 1360 | pub fn posix_setuid(uid: u32) !void { |
| 1404 | const err = posix.getErrno(posix.setuid(uid)); | 1361 | const err = posix.getErrno(posix.setuid(uid)); |
| 1405 | if (err == 0) return; | 1362 | if (err == 0) return; |
std/os/linux/index.zig+20| ... | @@ -495,6 +495,26 @@ pub fn waitpid(pid: i32, status: &i32, options: i32) usize { | ... | @@ -495,6 +495,26 @@ pub fn waitpid(pid: i32, status: &i32, options: i32) usize { |
| 495 | return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); | 495 | return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); |
| 496 | } | 496 | } |
| 497 | 497 | ||
| 498 | pub fn clock_gettime(clk_id: i32, tp: &timespec) usize { | ||
| 499 | return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | ||
| 500 | } | ||
| 501 | |||
| 502 | pub fn clock_getres(clk_id: i32, tp: &timespec) usize { | ||
| 503 | return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | ||
| 504 | } | ||
| 505 | |||
| 506 | pub fn clock_settime(clk_id: i32, tp: &const timespec) usize { | ||
| 507 | return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | ||
| 508 | } | ||
| 509 | |||
| 510 | pub fn gettimeofday(tv: &timeval, tz: &timezone) usize { | ||
| 511 | return syscall2(SYS_gettimeofday, @ptrToInt(tv), @ptrToInt(tz)); | ||
| 512 | } | ||
| 513 | |||
| 514 | pub fn settimeofdat(tv: &const timeval, tz: &const timezone) usize { | ||
| 515 | return syscall2(SYS_settimeofday, @ptrToInt(tv), @ptrToInt(tz)); | ||
| 516 | } | ||
| 517 | |||
| 498 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { | 518 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { |
| 499 | return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); | 519 | return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); |
| 500 | } | 520 | } |
std/os/linux/x86_64.zig+10| ... | @@ -489,6 +489,16 @@ pub const timespec = extern struct { | ... | @@ -489,6 +489,16 @@ pub const timespec = extern struct { |
| 489 | tv_nsec: isize, | 489 | tv_nsec: isize, |
| 490 | }; | 490 | }; |
| 491 | 491 | ||
| 492 | pub const timeval = extern struct { | ||
| 493 | tv_sec: isize, | ||
| 494 | tv_usec: isize, | ||
| 495 | }; | ||
| 496 | |||
| 497 | pub const timezone = extern struct { | ||
| 498 | tz_minuteswest: i32, | ||
| 499 | tz_dsttime: i32, | ||
| 500 | }; | ||
| 501 | |||
| 492 | pub const dirent = extern struct { | 502 | pub const dirent = extern struct { |
| 493 | d_ino: usize, | 503 | d_ino: usize, |
| 494 | d_off: usize, | 504 | d_off: usize, |
std/os/windows/index.zig+7| ... | @@ -61,6 +61,8 @@ pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpsz | ... | @@ -61,6 +61,8 @@ pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpsz |
| 61 | 61 | ||
| 62 | pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE; | 62 | pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE; |
| 63 | 63 | ||
| 64 | pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(?&FILETIME) void; | ||
| 65 | |||
| 64 | pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE; | 66 | pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE; |
| 65 | pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL; | 67 | pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL; |
| 66 | pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: &c_void, dwBytes: SIZE_T) ?&c_void; | 68 | pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: &c_void, dwBytes: SIZE_T) ?&c_void; |
| ... | @@ -77,6 +79,10 @@ pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem | ... | @@ -77,6 +79,10 @@ pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem |
| 77 | 79 | ||
| 78 | pub extern "kernel32" stdcallcc fn MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR, | 80 | pub extern "kernel32" stdcallcc fn MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR, |
| 79 | dwFlags: DWORD) BOOL; | 81 | dwFlags: DWORD) BOOL; |
| 82 | |||
| 83 | pub extern "kernel32" stdcallcc fn QueryPerformanceCounter(lpPerformanceCount: &LARGE_INTEGER) BOOL; | ||
| 84 | |||
| 85 | pub extern "kernel32" stdcallcc fn QueryPerformanceFrequency(lpFrequency: &LARGE_INTEGER) BOOL; | ||
| 80 | 86 | ||
| 81 | pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: &c_void, | 87 | pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: &c_void, |
| 82 | in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD, | 88 | in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD, |
| ... | @@ -137,6 +143,7 @@ pub const UNICODE = false; | ... | @@ -137,6 +143,7 @@ pub const UNICODE = false; |
| 137 | pub const WCHAR = u16; | 143 | pub const WCHAR = u16; |
| 138 | pub const WORD = u16; | 144 | pub const WORD = u16; |
| 139 | pub const LARGE_INTEGER = i64; | 145 | pub const LARGE_INTEGER = i64; |
| 146 | pub const FILETIME = i64; | ||
| 140 | 147 | ||
| 141 | pub const TRUE = 1; | 148 | pub const TRUE = 1; |
| 142 | pub const FALSE = 0; | 149 | pub const FALSE = 0; |