Added unstaged changes.
parent
c90f936eef
commit
8b66dd8c7d
|
@ -507,6 +507,8 @@ set(ZIG_STD_FILES
|
|||
"os/linux/index.zig"
|
||||
"os/linux/x86_64.zig"
|
||||
"os/path.zig"
|
||||
"os/time.zig"
|
||||
"os/epoch.zig"
|
||||
"os/windows/error.zig"
|
||||
"os/windows/index.zig"
|
||||
"os/windows/util.zig"
|
||||
|
|
|
@ -3,10 +3,28 @@ pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int;
|
|||
|
||||
pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize;
|
||||
|
||||
pub extern "c" fn mach_absolute_time() u64;
|
||||
pub extern "c" fn mach_timebase_info(&mach_timebase_info_data) void;
|
||||
|
||||
pub use @import("../os/darwin_errno.zig");
|
||||
|
||||
pub const _errno = __error;
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mach_timebase_info_data = struct {
|
||||
numer: u32,
|
||||
denom: u32,
|
||||
};
|
||||
|
||||
/// Renamed to Stat to not conflict with the stat function.
|
||||
pub const Stat = extern struct {
|
||||
dev: i32,
|
||||
|
|
|
@ -40,6 +40,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(&timeval, ?&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: ?×pec) c_int;
|
||||
pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
|
||||
|
|
|
@ -86,7 +86,8 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
|
|||
},
|
||||
's' => {
|
||||
state = State.Buf;
|
||||
},'.' => {
|
||||
},
|
||||
'.' => {
|
||||
state = State.Float;
|
||||
},
|
||||
else => @compileError("Unknown format character: " ++ []u8{c}),
|
||||
|
|
|
@ -251,6 +251,10 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) u
|
|||
return errnoWrap(c.readlink(path, buf_ptr, buf_len));
|
||||
}
|
||||
|
||||
pub fn gettimeofday(&timeval, ?&timezone) usize {
|
||||
return errnoWrap(c.gettimeofday(timeval, timezone));
|
||||
}
|
||||
|
||||
pub fn nanosleep(req: &const timespec, rem: ?×pec) usize {
|
||||
return errnoWrap(c.nanosleep(req, rem));
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ pub const posix = switch(builtin.os) {
|
|||
pub const ChildProcess = @import("child_process.zig").ChildProcess;
|
||||
pub const path = @import("path.zig");
|
||||
pub const File = @import("file.zig").File;
|
||||
pub const time = @import("time.zig");
|
||||
|
||||
pub const FileMode = switch (builtin.os) {
|
||||
Os.windows => void,
|
||||
|
@ -1356,50 +1357,6 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) ![]u8 {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn sleep(seconds: usize, nanoseconds: usize) void {
|
||||
switch(builtin.os) {
|
||||
Os.linux, Os.macosx, Os.ios => {
|
||||
posixSleep(u63(seconds), u63(nanoseconds));
|
||||
},
|
||||
Os.windows => {
|
||||
const milliseconds = seconds * 1000 + nanoseconds / 1000000;
|
||||
windows.Sleep(windows.DWORD(milliseconds));
|
||||
},
|
||||
else => @compileError("Unsupported OS"),
|
||||
}
|
||||
}
|
||||
|
||||
const u63 = @IntType(false, 63);
|
||||
pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
|
||||
var req = posix.timespec {
|
||||
.tv_sec = seconds,
|
||||
.tv_nsec = nanoseconds,
|
||||
};
|
||||
var rem: posix.timespec = undefined;
|
||||
while (true) {
|
||||
const ret_val = posix.nanosleep(&req, &rem);
|
||||
const err = posix.getErrno(ret_val);
|
||||
if (err == 0) return;
|
||||
switch (err) {
|
||||
posix.EFAULT => unreachable,
|
||||
posix.EINVAL => {
|
||||
// Sometimes Darwin returns EINVAL for no reason.
|
||||
// We treat it as a spurious wakeup.
|
||||
return;
|
||||
},
|
||||
posix.EINTR => {
|
||||
req = rem;
|
||||
continue;
|
||||
},
|
||||
else => return,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "os.sleep" {
|
||||
sleep(0, 1);
|
||||
}
|
||||
|
||||
pub fn posix_setuid(uid: u32) !void {
|
||||
const err = posix.getErrno(posix.setuid(uid));
|
||||
if (err == 0) return;
|
||||
|
|
|
@ -495,6 +495,26 @@ pub fn waitpid(pid: i32, status: &i32, options: i32) usize {
|
|||
return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
|
||||
}
|
||||
|
||||
pub fn clock_gettime(clk_id: i32, tp: ×pec) usize {
|
||||
return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
|
||||
}
|
||||
|
||||
pub fn clock_getres(clk_id: i32, tp: ×pec) usize {
|
||||
return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
|
||||
}
|
||||
|
||||
pub fn clock_settime(clk_id: i32, tp: &const timespec) usize {
|
||||
return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
|
||||
}
|
||||
|
||||
pub fn gettimeofday(tv: &timeval, tz: &timezone) usize {
|
||||
return syscall2(SYS_gettimeofday, @ptrToInt(tv), @ptrToInt(tz));
|
||||
}
|
||||
|
||||
pub fn settimeofdat(tv: &const timeval, tz: &const timezone) usize {
|
||||
return syscall2(SYS_settimeofday, @ptrToInt(tv), @ptrToInt(tz));
|
||||
}
|
||||
|
||||
pub fn nanosleep(req: &const timespec, rem: ?×pec) usize {
|
||||
return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
|
||||
}
|
||||
|
|
|
@ -489,6 +489,16 @@ pub const timespec = extern struct {
|
|||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const dirent = extern struct {
|
||||
d_ino: usize,
|
||||
d_off: usize,
|
||||
|
|
|
@ -61,6 +61,8 @@ pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpsz
|
|||
|
||||
pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(?&FILETIME) void;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE;
|
||||
pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL;
|
||||
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
|
|||
|
||||
pub extern "kernel32" stdcallcc fn MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR,
|
||||
dwFlags: DWORD) BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn QueryPerformanceCounter(lpPerformanceCount: &LARGE_INTEGER) BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn QueryPerformanceFrequency(lpFrequency: &LARGE_INTEGER) BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: &c_void,
|
||||
in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD,
|
||||
|
@ -137,6 +143,7 @@ pub const UNICODE = false;
|
|||
pub const WCHAR = u16;
|
||||
pub const WORD = u16;
|
||||
pub const LARGE_INTEGER = i64;
|
||||
pub const FILETIME = i64;
|
||||
|
||||
pub const TRUE = 1;
|
||||
pub const FALSE = 0;
|
||||
|
|
Loading…
Reference in New Issue