diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-01-25 04:10:11 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-01-25 04:10:11 -0500 |
| commit | 3671582c15235e5f79a84936ea2f834f6968ff8c (patch) | |
| tree | 7fa2c7f06331feaad43ba63b0969add120633d49 /std/os | |
| parent | e5bc5873d74713bedbc32817ed31370c3256418d (diff) | |
| download | zig-3671582c15235e5f79a84936ea2f834f6968ff8c.tar.gz zig-3671582c15235e5f79a84936ea2f834f6968ff8c.zip | |
syntax: functions require return type. remove `->`
The purpose of this is:
* Only one way to do things
* Changing a function with void return type to return a possible
error becomes a 1 character change, subtly encouraging
people to use errors.
See #632
Here are some imperfect sed commands for performing this update:
remove arrow:
```
sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig")
```
add void:
```
sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig")
```
Some cleanup may be necessary, but this should do the bulk of the work.
Diffstat (limited to 'std/os')
| -rw-r--r-- | std/os/child_process.zig | 78 | ||||
| -rw-r--r-- | std/os/darwin.zig | 90 | ||||
| -rw-r--r-- | std/os/get_user_id.zig | 4 | ||||
| -rw-r--r-- | std/os/index.zig | 136 | ||||
| -rw-r--r-- | std/os/linux.zig | 168 | ||||
| -rw-r--r-- | std/os/linux_i386.zig | 14 | ||||
| -rw-r--r-- | std/os/linux_x86_64.zig | 16 | ||||
| -rw-r--r-- | std/os/path.zig | 78 | ||||
| -rw-r--r-- | std/os/windows/index.zig | 78 | ||||
| -rw-r--r-- | std/os/windows/util.zig | 18 | ||||
| -rw-r--r-- | std/os/zen.zig | 24 |
11 files changed, 350 insertions, 354 deletions
diff --git a/std/os/child_process.zig b/std/os/child_process.zig index aaa7ac3970..f4709ce75a 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -37,7 +37,7 @@ pub const ChildProcess = struct { pub argv: []const []const u8, /// Possibly called from a signal handler. Must set this before calling `spawn`. - pub onTerm: ?fn(&ChildProcess), + pub onTerm: ?fn(&ChildProcess)void, /// Leave as null to use the current env map using the supplied allocator. pub env_map: ?&const BufMap, @@ -74,7 +74,7 @@ pub const ChildProcess = struct { /// First argument in argv is the executable. /// On success must call deinit. - pub fn init(argv: []const []const u8, allocator: &mem.Allocator) -> %&ChildProcess { + pub fn init(argv: []const []const u8, allocator: &mem.Allocator) %&ChildProcess { const child = try allocator.create(ChildProcess); errdefer allocator.destroy(child); @@ -103,7 +103,7 @@ pub const ChildProcess = struct { return child; } - pub fn setUserName(self: &ChildProcess, name: []const u8) -> %void { + pub fn setUserName(self: &ChildProcess, name: []const u8) %void { const user_info = try os.getUserInfo(name); self.uid = user_info.uid; self.gid = user_info.gid; @@ -111,7 +111,7 @@ pub const ChildProcess = struct { /// onTerm can be called before `spawn` returns. /// On success must call `kill` or `wait`. - pub fn spawn(self: &ChildProcess) -> %void { + pub fn spawn(self: &ChildProcess) %void { if (is_windows) { return self.spawnWindows(); } else { @@ -119,13 +119,13 @@ pub const ChildProcess = struct { } } - pub fn spawnAndWait(self: &ChildProcess) -> %Term { + pub fn spawnAndWait(self: &ChildProcess) %Term { try self.spawn(); return self.wait(); } /// Forcibly terminates child process and then cleans up all resources. - pub fn kill(self: &ChildProcess) -> %Term { + pub fn kill(self: &ChildProcess) %Term { if (is_windows) { return self.killWindows(1); } else { @@ -133,7 +133,7 @@ pub const ChildProcess = struct { } } - pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) -> %Term { + pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) %Term { if (self.term) |term| { self.cleanupStreams(); return term; @@ -149,7 +149,7 @@ pub const ChildProcess = struct { return ??self.term; } - pub fn killPosix(self: &ChildProcess) -> %Term { + pub fn killPosix(self: &ChildProcess) %Term { block_SIGCHLD(); defer restore_SIGCHLD(); @@ -172,7 +172,7 @@ pub const ChildProcess = struct { } /// Blocks until child process terminates and then cleans up all resources. - pub fn wait(self: &ChildProcess) -> %Term { + pub fn wait(self: &ChildProcess) %Term { if (is_windows) { return self.waitWindows(); } else { @@ -189,7 +189,7 @@ pub const ChildProcess = struct { /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns. /// If it succeeds, the caller owns result.stdout and result.stderr memory. pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8, - env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult + env_map: ?&const BufMap, max_output_size: usize) %ExecResult { const child = try ChildProcess.init(argv, allocator); defer child.deinit(); @@ -220,7 +220,7 @@ pub const ChildProcess = struct { }; } - fn waitWindows(self: &ChildProcess) -> %Term { + fn waitWindows(self: &ChildProcess) %Term { if (self.term) |term| { self.cleanupStreams(); return term; @@ -230,7 +230,7 @@ pub const ChildProcess = struct { return ??self.term; } - fn waitPosix(self: &ChildProcess) -> %Term { + fn waitPosix(self: &ChildProcess) %Term { block_SIGCHLD(); defer restore_SIGCHLD(); @@ -243,11 +243,11 @@ pub const ChildProcess = struct { return ??self.term; } - pub fn deinit(self: &ChildProcess) { + pub fn deinit(self: &ChildProcess) void { self.allocator.destroy(self); } - fn waitUnwrappedWindows(self: &ChildProcess) -> %void { + fn waitUnwrappedWindows(self: &ChildProcess) %void { const result = os.windowsWaitSingle(self.handle, windows.INFINITE); self.term = (%Term)(x: { @@ -265,7 +265,7 @@ pub const ChildProcess = struct { return result; } - fn waitUnwrapped(self: &ChildProcess) { + fn waitUnwrapped(self: &ChildProcess) void { var status: i32 = undefined; while (true) { const err = posix.getErrno(posix.waitpid(self.pid, &status, 0)); @@ -281,7 +281,7 @@ pub const ChildProcess = struct { } } - fn handleWaitResult(self: &ChildProcess, status: i32) { + fn handleWaitResult(self: &ChildProcess, status: i32) void { self.term = self.cleanupAfterWait(status); if (self.onTerm) |onTerm| { @@ -289,13 +289,13 @@ pub const ChildProcess = struct { } } - fn cleanupStreams(self: &ChildProcess) { + fn cleanupStreams(self: &ChildProcess) void { if (self.stdin) |*stdin| { stdin.close(); self.stdin = null; } if (self.stdout) |*stdout| { stdout.close(); self.stdout = null; } if (self.stderr) |*stderr| { stderr.close(); self.stderr = null; } } - fn cleanupAfterWait(self: &ChildProcess, status: i32) -> %Term { + fn cleanupAfterWait(self: &ChildProcess, status: i32) %Term { children_nodes.remove(&self.llnode); defer { @@ -319,7 +319,7 @@ pub const ChildProcess = struct { return statusToTerm(status); } - fn statusToTerm(status: i32) -> Term { + fn statusToTerm(status: i32) Term { return if (posix.WIFEXITED(status)) Term { .Exited = posix.WEXITSTATUS(status) } else if (posix.WIFSIGNALED(status)) @@ -331,7 +331,7 @@ pub const ChildProcess = struct { ; } - fn spawnPosix(self: &ChildProcess) -> %void { + fn spawnPosix(self: &ChildProcess) %void { // TODO atomically set a flag saying that we already did this install_SIGCHLD_handler(); @@ -440,7 +440,7 @@ pub const ChildProcess = struct { if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); } } - fn spawnWindows(self: &ChildProcess) -> %void { + fn spawnWindows(self: &ChildProcess) %void { const saAttr = windows.SECURITY_ATTRIBUTES { .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES), .bInheritHandle = windows.TRUE, @@ -623,7 +623,7 @@ pub const ChildProcess = struct { if (self.stdout_behavior == StdIo.Pipe) { os.close(??g_hChildStd_OUT_Wr); } } - fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) -> %void { + fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) %void { switch (stdio) { StdIo.Pipe => try os.posixDup2(pipe_fd, std_fileno), StdIo.Close => os.close(std_fileno), @@ -635,7 +635,7 @@ pub const ChildProcess = struct { }; fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?&u8, - lpStartupInfo: &windows.STARTUPINFOA, lpProcessInformation: &windows.PROCESS_INFORMATION) -> %void + lpStartupInfo: &windows.STARTUPINFOA, lpProcessInformation: &windows.PROCESS_INFORMATION) %void { if (windows.CreateProcessA(app_name, cmd_line, null, null, windows.TRUE, 0, @ptrCast(?&c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation) == 0) @@ -655,7 +655,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ? /// Caller must dealloc. /// Guarantees a null byte at result[result.len]. -fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) -> %[]u8 { +fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) %[]u8 { var buf = try Buffer.initSize(allocator, 0); defer buf.deinit(); @@ -690,7 +690,7 @@ fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) return buf.toOwnedSlice(); } -fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) { +fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) void { if (rd) |h| os.close(h); if (wr) |h| os.close(h); } @@ -700,7 +700,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) { // a namespace field lookup const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES; -fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { +fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { if (windows.CreatePipe(rd, wr, sattr, 0) == 0) { const err = windows.GetLastError(); return switch (err) { @@ -709,7 +709,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECUR } } -fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) -> %void { +fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) %void { if (windows.SetHandleInformation(h, mask, flags) == 0) { const err = windows.GetLastError(); return switch (err) { @@ -718,7 +718,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D } } -fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { +fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { var rd_h: windows.HANDLE = undefined; var wr_h: windows.HANDLE = undefined; try windowsMakePipe(&rd_h, &wr_h, sattr); @@ -728,7 +728,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S *wr = wr_h; } -fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { +fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { var rd_h: windows.HANDLE = undefined; var wr_h: windows.HANDLE = undefined; try windowsMakePipe(&rd_h, &wr_h, sattr); @@ -738,7 +738,7 @@ fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const *wr = wr_h; } -fn makePipe() -> %[2]i32 { +fn makePipe() %[2]i32 { var fds: [2]i32 = undefined; const err = posix.getErrno(posix.pipe(&fds)); if (err > 0) { @@ -750,33 +750,33 @@ fn makePipe() -> %[2]i32 { return fds; } -fn destroyPipe(pipe: &const [2]i32) { +fn destroyPipe(pipe: &const [2]i32) void { os.close((*pipe)[0]); os.close((*pipe)[1]); } // Child of fork calls this to report an error to the fork parent. // Then the child exits. -fn forkChildErrReport(fd: i32, err: error) -> noreturn { +fn forkChildErrReport(fd: i32, err: error) noreturn { _ = writeIntFd(fd, ErrInt(err)); posix.exit(1); } const ErrInt = @IntType(false, @sizeOf(error) * 8); -fn writeIntFd(fd: i32, value: ErrInt) -> %void { +fn writeIntFd(fd: i32, value: ErrInt) %void { var bytes: [@sizeOf(ErrInt)]u8 = undefined; mem.writeInt(bytes[0..], value, builtin.endian); os.posixWrite(fd, bytes[0..]) catch return error.SystemResources; } -fn readIntFd(fd: i32) -> %ErrInt { +fn readIntFd(fd: i32) %ErrInt { var bytes: [@sizeOf(ErrInt)]u8 = undefined; os.posixRead(fd, bytes[0..]) catch return error.SystemResources; return mem.readInt(bytes[0..], ErrInt, builtin.endian); } -extern fn sigchld_handler(_: i32) { +extern fn sigchld_handler(_: i32) void { while (true) { var status: i32 = undefined; const pid_result = posix.waitpid(-1, &status, posix.WNOHANG); @@ -794,7 +794,7 @@ extern fn sigchld_handler(_: i32) { } } -fn handleTerm(pid: i32, status: i32) { +fn handleTerm(pid: i32, status: i32) void { var it = children_nodes.first; while (it) |node| : (it = node.next) { if (node.data.pid == pid) { @@ -810,12 +810,12 @@ const sigchld_set = x: { break :x signal_set; }; -fn block_SIGCHLD() { +fn block_SIGCHLD() void { const err = posix.getErrno(posix.sigprocmask(posix.SIG_BLOCK, &sigchld_set, null)); assert(err == 0); } -fn restore_SIGCHLD() { +fn restore_SIGCHLD() void { const err = posix.getErrno(posix.sigprocmask(posix.SIG_UNBLOCK, &sigchld_set, null)); assert(err == 0); } @@ -826,7 +826,7 @@ const sigchld_action = posix.Sigaction { .flags = posix.SA_RESTART | posix.SA_NOCLDSTOP, }; -fn install_SIGCHLD_handler() { +fn install_SIGCHLD_handler() void { const err = posix.getErrno(posix.sigaction(posix.SIGCHLD, &sigchld_action, null)); assert(err == 0); } diff --git a/std/os/darwin.zig b/std/os/darwin.zig index 7e3e5e823e..ebc6f65f55 100644 --- a/std/os/darwin.zig +++ b/std/os/darwin.zig @@ -98,67 +98,67 @@ pub const SIGINFO = 29; /// information request pub const SIGUSR1 = 30; /// user defined signal 1 pub const SIGUSR2 = 31; /// user defined signal 2 -fn wstatus(x: i32) -> i32 { return x & 0o177; } +fn wstatus(x: i32) i32 { return x & 0o177; } const wstopped = 0o177; -pub fn WEXITSTATUS(x: i32) -> i32 { return x >> 8; } -pub fn WTERMSIG(x: i32) -> i32 { return wstatus(x); } -pub fn WSTOPSIG(x: i32) -> i32 { return x >> 8; } -pub fn WIFEXITED(x: i32) -> bool { return wstatus(x) == 0; } -pub fn WIFSTOPPED(x: i32) -> bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; } -pub fn WIFSIGNALED(x: i32) -> bool { return wstatus(x) != wstopped and wstatus(x) != 0; } +pub fn WEXITSTATUS(x: i32) i32 { return x >> 8; } +pub fn WTERMSIG(x: i32) i32 { return wstatus(x); } +pub fn WSTOPSIG(x: i32) i32 { return x >> 8; } +pub fn WIFEXITED(x: i32) bool { return wstatus(x) == 0; } +pub fn WIFSTOPPED(x: i32) bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; } +pub fn WIFSIGNALED(x: i32) bool { return wstatus(x) != wstopped and wstatus(x) != 0; } /// Get the errno from a syscall return value, or 0 for no error. -pub fn getErrno(r: usize) -> usize { +pub fn getErrno(r: usize) usize { const signed_r = @bitCast(isize, r); return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0; } -pub fn close(fd: i32) -> usize { +pub fn close(fd: i32) usize { return errnoWrap(c.close(fd)); } -pub fn abort() -> noreturn { +pub fn abort() noreturn { c.abort(); } -pub fn exit(code: i32) -> noreturn { +pub fn exit(code: i32) noreturn { c.exit(code); } -pub fn isatty(fd: i32) -> bool { +pub fn isatty(fd: i32) bool { return c.isatty(fd) != 0; } -pub fn fstat(fd: i32, buf: &c.Stat) -> usize { +pub fn fstat(fd: i32, buf: &c.Stat) usize { return errnoWrap(c.@"fstat$INODE64"(fd, buf)); } -pub fn lseek(fd: i32, offset: isize, whence: c_int) -> usize { +pub fn lseek(fd: i32, offset: isize, whence: c_int) usize { return errnoWrap(c.lseek(fd, offset, whence)); } -pub fn open(path: &const u8, flags: u32, mode: usize) -> usize { +pub fn open(path: &const u8, flags: u32, mode: usize) usize { return errnoWrap(c.open(path, @bitCast(c_int, flags), mode)); } -pub fn raise(sig: i32) -> usize { +pub fn raise(sig: i32) usize { return errnoWrap(c.raise(sig)); } -pub fn read(fd: i32, buf: &u8, nbyte: usize) -> usize { +pub fn read(fd: i32, buf: &u8, nbyte: usize) usize { return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte)); } -pub fn stat(noalias path: &const u8, noalias buf: &stat) -> usize { +pub fn stat(noalias path: &const u8, noalias buf: &stat) usize { return errnoWrap(c.stat(path, buf)); } -pub fn write(fd: i32, buf: &const u8, nbyte: usize) -> usize { +pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize { return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte)); } pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, - offset: isize) -> usize + offset: isize) usize { const ptr_result = c.mmap(@ptrCast(&c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset); @@ -166,87 +166,85 @@ pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, return errnoWrap(isize_result); } -pub fn munmap(address: &u8, length: usize) -> usize { +pub fn munmap(address: &u8, length: usize) usize { return errnoWrap(c.munmap(@ptrCast(&c_void, address), length)); } -pub fn unlink(path: &const u8) -> usize { +pub fn unlink(path: &const u8) usize { return errnoWrap(c.unlink(path)); } -pub fn getcwd(buf: &u8, size: usize) -> usize { +pub fn getcwd(buf: &u8, size: usize) usize { return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0; } -pub fn waitpid(pid: i32, status: &i32, options: u32) -> usize { +pub fn waitpid(pid: i32, status: &i32, options: u32) usize { comptime assert(i32.bit_count == c_int.bit_count); return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options))); } -pub fn fork() -> usize { +pub fn fork() usize { return errnoWrap(c.fork()); } -pub fn pipe(fds: &[2]i32) -> usize { +pub fn pipe(fds: &[2]i32) usize { comptime assert(i32.bit_count == c_int.bit_count); return errnoWrap(c.pipe(@ptrCast(&c_int, fds))); } -pub fn mkdir(path: &const u8, mode: u32) -> usize { +pub fn mkdir(path: &const u8, mode: u32) usize { return errnoWrap(c.mkdir(path, mode)); } -pub fn symlink(existing: &const u8, new: &const u8) -> usize { +pub fn symlink(existing: &const u8, new: &const u8) usize { return errnoWrap(c.symlink(existing, new)); } -pub fn rename(old: &const u8, new: &const u8) -> usize { +pub fn rename(old: &const u8, new: &const u8) usize { return errnoWrap(c.rename(old, new)); } -pub fn chdir(path: &const u8) -> usize { +pub fn chdir(path: &const u8) usize { return errnoWrap(c.chdir(path)); } -pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) - -> usize -{ +pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize { return errnoWrap(c.execve(path, argv, envp)); } -pub fn dup2(old: i32, new: i32) -> usize { +pub fn dup2(old: i32, new: i32) usize { return errnoWrap(c.dup2(old, new)); } -pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize { +pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize { return errnoWrap(c.readlink(path, buf_ptr, buf_len)); } -pub fn nanosleep(req: &const timespec, rem: ?×pec) -> usize { +pub fn nanosleep(req: &const timespec, rem: ?×pec) usize { return errnoWrap(c.nanosleep(req, rem)); } -pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usize { +pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) usize { return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0; } -pub fn setreuid(ruid: u32, euid: u32) -> usize { +pub fn setreuid(ruid: u32, euid: u32) usize { return errnoWrap(c.setreuid(ruid, euid)); } -pub fn setregid(rgid: u32, egid: u32) -> usize { +pub fn setregid(rgid: u32, egid: u32) usize { return errnoWrap(c.setregid(rgid, egid)); } -pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize { +pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize { return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset)); } -pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize { +pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize { assert(sig != SIGKILL); assert(sig != SIGSTOP); var cact = c.Sigaction { - .handler = @ptrCast(extern fn(c_int), act.handler), + .handler = @ptrCast(extern fn(c_int)void, act.handler), .sa_flags = @bitCast(c_int, act.flags), .sa_mask = act.mask, }; @@ -257,7 +255,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti } if (oact) |old| { *old = Sigaction { - .handler = @ptrCast(extern fn(i32), coact.handler), + .handler = @ptrCast(extern fn(i32)void, coact.handler), .flags = @bitCast(u32, coact.sa_flags), .mask = coact.sa_mask, }; @@ -273,18 +271,18 @@ pub const Stat = c.Stat; /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. pub const Sigaction = struct { - handler: extern fn(i32), + handler: extern fn(i32)void, mask: sigset_t, flags: u32, }; -pub fn sigaddset(set: &sigset_t, signo: u5) { +pub fn sigaddset(set: &sigset_t, signo: u5) void { *set |= u32(1) << (signo - 1); } /// Takes the return value from a syscall and formats it back in the way /// that the kernel represents it to libc. Errno was a mistake, let's make /// it go away forever. -fn errnoWrap(value: isize) -> usize { +fn errnoWrap(value: isize) usize { return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value); } diff --git a/std/os/get_user_id.zig b/std/os/get_user_id.zig index 7485f788fc..68cb268169 100644 --- a/std/os/get_user_id.zig +++ b/std/os/get_user_id.zig @@ -9,7 +9,7 @@ pub const UserInfo = struct { }; /// POSIX function which gets a uid from username. -pub fn getUserInfo(name: []const u8) -> %UserInfo { +pub fn getUserInfo(name: []const u8) %UserInfo { return switch (builtin.os) { Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name), else => @compileError("Unsupported OS"), @@ -30,7 +30,7 @@ error CorruptPasswordFile; // TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else // like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`. -pub fn posixGetUserInfo(name: []const u8) -> %UserInfo { +pub fn posixGetUserInfo(name: []const u8) %UserInfo { var in_stream = try io.InStream.open("/etc/passwd", null); defer in_stream.close(); diff --git a/std/os/index.zig b/std/os/index.zig index 34ab49ca56..4451faf103 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -75,7 +75,7 @@ error WouldBlock; /// Fills `buf` with random bytes. If linking against libc, this calls the /// appropriate OS-specific library call. Otherwise it uses the zig standard /// library implementation. -pub fn getRandomBytes(buf: []u8) -> %void { +pub fn getRandomBytes(buf: []u8) %void { switch (builtin.os) { Os.linux => while (true) { // TODO check libc version and potentially call c.getrandom. @@ -127,7 +127,7 @@ test "os.getRandomBytes" { /// Raises a signal in the current kernel thread, ending its execution. /// If linking against libc, this calls the abort() libc function. Otherwise /// it uses the zig standard library implementation. -pub fn abort() -> noreturn { +pub fn abort() noreturn { @setCold(true); if (builtin.link_libc) { c.abort(); @@ -149,7 +149,7 @@ pub fn abort() -> noreturn { } /// Exits the program cleanly with the specified status code. -pub fn exit(status: u8) -> noreturn { +pub fn exit(status: u8) noreturn { @setCold(true); if (builtin.link_libc) { c.exit(status); @@ -166,7 +166,7 @@ pub fn exit(status: u8) -> noreturn { } /// Closes the file handle. Keeps trying if it gets interrupted by a signal. -pub fn close(handle: FileHandle) { +pub fn close(handle: FileHandle) void { if (is_windows) { windows_util.windowsClose(handle); } else { @@ -182,7 +182,7 @@ pub fn close(handle: FileHandle) { } /// Calls POSIX read, and keeps trying if it gets interrupted. -pub fn posixRead(fd: i32, buf: []u8) -> %void { +pub fn posixRead(fd: i32, buf: []u8) %void { var index: usize = 0; while (index < buf.len) { const amt_written = posix.read(fd, &buf[index], buf.len - index); @@ -213,7 +213,7 @@ error NoSpaceLeft; error BrokenPipe; /// Calls POSIX write, and keeps trying if it gets interrupted. -pub fn posixWrite(fd: i32, bytes: []const u8) -> %void { +pub fn posixWrite(fd: i32, bytes: []const u8) %void { while (true) { const write_ret = posix.write(fd, bytes.ptr, bytes.len); const write_err = posix.getErrno(write_ret); @@ -243,7 +243,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void { /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. /// Calls POSIX open, keeps trying if it gets interrupted, and translates /// the return value into zig errors. -pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Allocator) -> %i32 { +pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Allocator) %i32 { var stack_buf: [max_noalloc_path_len]u8 = undefined; var path0: []u8 = undefined; var need_free = false; @@ -292,7 +292,7 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al } } -pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void { +pub fn posixDup2(old_fd: i32, new_fd: i32) %void { while (true) { const err = posix.getErrno(posix.dup2(old_fd, new_fd)); if (err > 0) { @@ -307,7 +307,7 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void { } } -pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) -> %[]?&u8 { +pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) %[]?&u8 { const envp_count = env_map.count(); const envp_buf = try allocator.alloc(?&u8, envp_count + 1); mem.set(?&u8, envp_buf, null); @@ -330,7 +330,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) return envp_buf; } -pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) { +pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void { for (envp_buf) |env| { const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break; allocator.free(env_buf); @@ -344,7 +344,7 @@ pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) { /// `argv[0]` is the executable path. /// This function also uses the PATH environment variable to get the full path to the executable. pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, - allocator: &Allocator) -> %void + allocator: &Allocator) %void { const argv_buf = try allocator.alloc(?&u8, argv.len + 1); mem.set(?&u8, argv_buf, null); @@ -400,7 +400,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, return posixExecveErrnoToErr(err); } -fn posixExecveErrnoToErr(err: usize) -> error { +fn posixExecveErrnoToErr(err: usize) error { assert(err > 0); return switch (err) { posix.EFAULT => unreachable, @@ -419,7 +419,7 @@ fn posixExecveErrnoToErr(err: usize) -> error { pub var posix_environ_raw: []&u8 = undefined; /// Caller must free result when done. -pub fn getEnvMap(allocator: &Allocator) -> %BufMap { +pub fn getEnvMap(allocator: &Allocator) %BufMap { var result = BufMap.init(allocator); errdefer result.deinit(); @@ -463,7 +463,7 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap { } } -pub fn getEnvPosix(key: []const u8) -> ?[]const u8 { +pub fn getEnvPosix(key: []const u8) ?[]const u8 { for (posix_environ_raw) |ptr| { var line_i: usize = 0; while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {} @@ -483,7 +483,7 @@ pub fn getEnvPosix(key: []const u8) -> ?[]const u8 { error EnvironmentVariableNotFound; /// Caller must free returned memory. -pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) -> %[]u8 { +pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) %[]u8 { if (is_windows) { const key_with_null = try cstr.addNullByte(allocator, key); defer allocator.free(key_with_null); @@ -517,7 +517,7 @@ pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) -> %[]u8 { } /// Caller must free the returned memory. -pub fn getCwd(allocator: &Allocator) -> %[]u8 { +pub fn getCwd(allocator: &Allocator) %[]u8 { switch (builtin.os) { Os.windows => { var buf = try allocator.alloc(u8, 256); @@ -564,7 +564,7 @@ test "os.getCwd" { _ = getCwd(debug.global_allocator); } -pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { +pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void { if (is_windows) { return symLinkWindows(allocator, existing_path, new_path); } else { @@ -572,7 +572,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con } } -pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { +pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void { const existing_with_null = try cstr.addNullByte(allocator, existing_path); defer allocator.free(existing_with_null); const new_with_null = try cstr.addNullByte(allocator, new_path); @@ -586,7 +586,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path } } -pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { +pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void { const full_buf = try allocator.alloc(u8, existing_path.len + new_path.len + 2); defer allocator.free(full_buf); @@ -623,7 +623,7 @@ const b64_fs_encoder = base64.Base64Encoder.init( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", base64.standard_pad_char); -pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { +pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void { if (symLink(allocator, existing_path, new_path)) { return; } else |err| { @@ -652,7 +652,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: } -pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void { +pub fn deleteFile(allocator: &Allocator, file_path: []const u8) %void { if (builtin.os == Os.windows) { return deleteFileWindows(allocator, file_path); } else { @@ -663,7 +663,7 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void { error FileNotFound; error AccessDenied; -pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void { +pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) %void { const buf = try allocator.alloc(u8, file_path.len + 1); defer allocator.free(buf); @@ -681,7 +681,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void } } -pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) -> %void { +pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) %void { const buf = try allocator.alloc(u8, file_path.len + 1); defer allocator.free(buf); @@ -708,13 +708,13 @@ pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) -> %void { } /// Calls ::copyFileMode with 0o666 for the mode. -pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []const u8) -> %void { +pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []const u8) %void { return copyFileMode(allocator, source_path, dest_path, 0o666); } // TODO instead of accepting a mode argument, use the mode from fstat'ing the source path once open /// Guaranteed to be atomic. -pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: []const u8, mode: usize) -> %void { +pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: []const u8, mode: usize) %void { var rand_buf: [12]u8 = undefined; const tmp_path = try allocator.alloc(u8, dest_path.len + base64.Base64Encoder.calcSize(rand_buf.len)); defer allocator.free(tmp_path); @@ -738,7 +738,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [ } } -pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) -> %void { +pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) %void { const full_buf = try allocator.alloc(u8, old_path.len + new_path.len + 2); defer allocator.free(full_buf); @@ -783,7 +783,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) } } -pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void { +pub fn makeDir(allocator: &Allocator, dir_path: []const u8) %void { if (is_windows) { return makeDirWindows(allocator, dir_path); } else { @@ -791,7 +791,7 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void { } } -pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void { +pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) %void { const path_buf = try cstr.addNullByte(allocator, dir_path); defer allocator.free(path_buf); @@ -805,7 +805,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void { } } -pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void { +pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) %void { const path_buf = try cstr.addNullByte(allocator, dir_path); defer allocator.free(path_buf); @@ -831,7 +831,7 @@ pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void { /// Calls makeDir recursively to make an entire path. Returns success if the path /// already exists and is a directory. -pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { +pub fn makePath(allocator: &Allocator, full_path: []const u8) %void { const resolved_path = try path.resolve(allocator, full_path); defer allocator.free(resolved_path); @@ -869,7 +869,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { /// Returns ::error.DirNotEmpty if the directory is not empty. /// To delete a directory recursively, see ::deleteTree -pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void { +pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) %void { const path_buf = try allocator.alloc(u8, dir_path.len + 1); defer allocator.free(path_buf); @@ -898,7 +898,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void { /// removes it. If it cannot be removed because it is a non-empty directory, /// this function recursively removes its entries and then tries again. // TODO non-recursive implementation -pub fn deleteTree(allocator: &Allocator, full_path: []const u8) -> %void { +pub fn deleteTree(allocator: &Allocator, full_path: []const u8) %void { start_over: while (true) { // First, try deleting the item as a file. This way we don't follow sym links. if (deleteFile(allocator, full_path)) { @@ -967,7 +967,7 @@ pub const Dir = struct { }; }; - pub fn open(allocator: &Allocator, dir_path: []const u8) -> %Dir { + pub fn open(allocator: &Allocator, dir_path: []const u8) %Dir { const fd = try posixOpen(dir_path, posix.O_RDONLY|posix.O_DIRECTORY|posix.O_CLOEXEC, 0, allocator); return Dir { .allocator = allocator, @@ -978,14 +978,14 @@ pub const Dir = struct { }; } - pub fn close(self: &Dir) { + pub fn close(self: &Dir) void { self.allocator.free(self.buf); os.close(self.fd); } /// Memory such as file names referenced in this returned entry becomes invalid /// with subsequent calls to next, as well as when this ::Dir is deinitialized. - pub fn next(self: &Dir) -> %?Entry { + pub fn next(self: &Dir) %?Entry { start_over: while (true) { if (self.index >= self.end_index) { if (self.buf.len == 0) { @@ -1042,7 +1042,7 @@ pub const Dir = struct { } }; -pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void { +pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) %void { const path_buf = try allocator.alloc(u8, dir_path.len + 1); defer allocator.free(path_buf); @@ -1066,7 +1066,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void { } /// Read value of a symbolic link. -pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { +pub fn readLink(allocator: &Allocator, pathname: []const u8) %[]u8 { const path_buf = try allocator.alloc(u8, pathname.len + 1); defer allocator.free(path_buf); @@ -1099,7 +1099,7 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { } } -pub fn sleep(seconds: usize, nanoseconds: usize) { +pub fn sleep(seconds: usize, nanoseconds: usize) void { switch(builtin.os) { Os.linux, Os.macosx, Os.ios => { posixSleep(u63(seconds), u63(nanoseconds)); @@ -1113,7 +1113,7 @@ pub fn sleep(seconds: usize, nanoseconds: usize) { } const u63 = @IntType(false, 63); -pub fn posixSleep(seconds: u63, nanoseconds: u63) { +pub fn posixSleep(seconds: u63, nanoseconds: u63) void { var req = posix.timespec { .tv_sec = seconds, .tv_nsec = nanoseconds, @@ -1147,7 +1147,7 @@ error ResourceLimitReached; error InvalidUserId; error PermissionDenied; -pub fn posix_setuid(uid: u32) -> %void { +pub fn posix_setuid(uid: u32) %void { const err = posix.getErrno(posix.setuid(uid)); if (err == 0) return; return switch (err) { @@ -1158,7 +1158,7 @@ pub fn posix_setuid(uid: u32) -> %void { }; } -pub fn posix_setreuid(ruid: u32, euid: u32) -> %void { +pub fn posix_setreuid(ruid: u32, euid: u32) %void { const err = posix.getErrno(posix.setreuid(ruid, euid)); if (err == 0) return; return switch (err) { @@ -1169,7 +1169,7 @@ pub fn posix_setreuid(ruid: u32, euid: u32) -> %void { }; } -pub fn posix_setgid(gid: u32) -> %void { +pub fn posix_setgid(gid: u32) %void { const err = posix.getErrno(posix.setgid(gid)); if (err == 0) return; return switch (err) { @@ -1180,7 +1180,7 @@ pub fn posix_setgid(gid: u32) -> %void { }; } -pub fn posix_setregid(rgid: u32, egid: u32) -> %void { +pub fn posix_setregid(rgid: u32, egid: u32) %void { const err = posix.getErrno(posix.setregid(rgid, egid)); if (err == 0) return; return switch (err) { @@ -1192,7 +1192,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) -> %void { } error NoStdHandles; -pub fn windowsGetStdHandle(handle_id: windows.DWORD) -> %windows.HANDLE { +pub fn windowsGetStdHandle(handle_id: windows.DWORD) %windows.HANDLE { if (windows.GetStdHandle(handle_id)) |handle| { if (handle == windows.INVALID_HANDLE_VALUE) { const err = windows.GetLastError(); @@ -1210,14 +1210,14 @@ pub const ArgIteratorPosix = struct { index: usize, count: usize, - pub fn init() -> ArgIteratorPosix { + pub fn init() ArgIteratorPosix { return ArgIteratorPosix { .index = 0, .count = raw.len, }; } - pub fn next(self: &ArgIteratorPosix) -> ?[]const u8 { + pub fn next(self: &ArgIteratorPosix) ?[]const u8 { if (self.index == self.count) return null; @@ -1226,7 +1226,7 @@ pub const ArgIteratorPosix = struct { return cstr.toSlice(s); } - pub fn skip(self: &ArgIteratorPosix) -> bool { + pub fn skip(self: &ArgIteratorPosix) bool { if (self.index == self.count) return false; @@ -1246,11 +1246,11 @@ pub const ArgIteratorWindows = struct { quote_count: usize, seen_quote_count: usize, - pub fn init() -> ArgIteratorWindows { + pub fn init() ArgIteratorWindows { return initWithCmdLine(windows.GetCommandLineA()); } - pub fn initWithCmdLine(cmd_line: &const u8) -> ArgIteratorWindows { + pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows { return ArgIteratorWindows { .index = 0, .cmd_line = cmd_line, @@ -1261,7 +1261,7 @@ pub const ArgIteratorWindows = struct { } /// You must free the returned memory when done. - pub fn next(self: &ArgIteratorWindows, allocator: &Allocator) -> ?%[]u8 { + pub fn next(self: &ArgIteratorWindows, allocator: &Allocator) ?%[]u8 { // march forward over whitespace while (true) : (self.index += 1) { const byte = self.cmd_line[self.index]; @@ -1275,7 +1275,7 @@ pub const ArgIteratorWindows = struct { return self.internalNext(allocator); } - pub fn skip(self: &ArgIteratorWindows) -> bool { + pub fn skip(self: &ArgIteratorWindows) bool { // march forward over whitespace while (true) : (self.index += 1) { const byte = self.cmd_line[self.index]; @@ -1314,7 +1314,7 @@ pub const ArgIteratorWindows = struct { } } - fn internalNext(self: &ArgIteratorWindows, allocator: &Allocator) -> %[]u8 { + fn internalNext(self: &ArgIteratorWindows, allocator: &Allocator) %[]u8 { var buf = try Buffer.initSize(allocator, 0); defer buf.deinit(); @@ -1358,14 +1358,14 @@ pub const ArgIteratorWindows = struct { } } - fn emitBackslashes(self: &ArgIteratorWindows, buf: &Buffer, emit_count: usize) -> %void { + fn emitBackslashes(self: &ArgIteratorWindows, buf: &Buffer, emit_count: usize) %void { var i: usize = 0; while (i < emit_count) : (i += 1) { try buf.appendByte('\\'); } } - fn countQuotes(cmd_line: &const u8) -> usize { + fn countQuotes(cmd_line: &const u8) usize { var result: usize = 0; var backslash_count: usize = 0; var index: usize = 0; @@ -1390,14 +1390,14 @@ pub const ArgIteratorWindows = struct { pub const ArgIterator = struct { inner: if (builtin.os == Os.windows) ArgIteratorWindows else ArgIteratorPosix, - pub fn init() -> ArgIterator { + pub fn init() ArgIterator { return ArgIterator { .inner = if (builtin.os == Os.windows) ArgIteratorWindows.init() else ArgIteratorPosix.init(), }; } /// You must free the returned memory when done. - pub fn next(self: &ArgIterator, allocator: &Allocator) -> ?%[]u8 { + pub fn next(self: &ArgIterator, allocator: &Allocator) ?%[]u8 { if (builtin.os == Os.windows) { return self.inner.next(allocator); } else { @@ -1406,23 +1406,23 @@ pub const ArgIterator = struct { } /// If you only are targeting posix you can call this and not need an allocator. - pub fn nextPosix(self: &ArgIterator) -> ?[]const u8 { + pub fn nextPosix(self: &ArgIterator) ?[]const u8 { return self.inner.next(); } /// Parse past 1 argument without capturing it. /// Returns `true` if skipped an arg, `false` if we are at the end. - pub fn skip(self: &ArgIterator) -> bool { + pub fn skip(self: &ArgIterator) bool { return self.inner.skip(); } }; -pub fn args() -> ArgIterator { +pub fn args() ArgIterator { return ArgIterator.init(); } /// Caller must call freeArgs on result. -pub fn argsAlloc(allocator: &mem.Allocator) -> %[]const []u8 { +pub fn argsAlloc(allocator: &mem.Allocator) %[]const []u8 { // TODO refactor to only make 1 allocation. var it = args(); var contents = try Buffer.initSize(allocator, 0); @@ -1459,7 +1459,7 @@ pub fn argsAlloc(allocator: &mem.Allocator) -> %[]const []u8 { return result_slice_list; } -pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) { +pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void { var total_bytes: usize = 0; for (args_alloc) |arg| { total_bytes += @sizeOf([]u8) + arg.len; @@ -1481,7 +1481,7 @@ test "windows arg parsing" { [][]const u8{".\\..\\zig-cache\\build", "bin\\zig.exe", ".\\..", ".\\..\\zig-cache", "--help"}); } -fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) { +fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) void { var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); for (expected_args) |expected_arg| { const arg = ??it.next(debug.global_allocator) catch unreachable; @@ -1511,7 +1511,7 @@ const unexpected_error_tracing = false; /// Call this when you made a syscall or something that sets errno /// and you get an unexpected error. -pub fn unexpectedErrorPosix(errno: usize) -> error { +pub fn unexpectedErrorPosix(errno: usize) error { if (unexpected_error_tracing) { debug.warn("unexpected errno: {}\n", errno); debug.dumpStackTrace(); @@ -1521,7 +1521,7 @@ pub fn unexpectedErrorPosix(errno: usize) -> error { /// Call this when you made a windows DLL call or something that does SetLastError /// and you get an unexpected error. -pub fn unexpectedErrorWindows(err: windows.DWORD) -> error { +pub fn unexpectedErrorWindows(err: windows.DWORD) error { if (unexpected_error_tracing) { debug.warn("unexpected GetLastError(): {}\n", err); debug.dumpStackTrace(); @@ -1529,7 +1529,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) -> error { return error.Unexpected; } -pub fn openSelfExe() -> %io.File { +pub fn openSelfExe() %io.File { switch (builtin.os) { Os.linux => { return io.File.openRead("/proc/self/exe", null); @@ -1547,7 +1547,7 @@ pub fn openSelfExe() -> %io.File { /// This function may return an error if the current executable /// was deleted after spawning. /// Caller owns returned memory. -pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 { +pub fn selfExePath(allocator: &mem.Allocator) %[]u8 { switch (builtin.os) { Os.linux => { // If the currently executing binary has been deleted, @@ -1590,7 +1590,7 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 { /// Get the directory path that contains the current executable. /// Caller owns returned memory. -pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 { +pub fn selfExeDirPath(allocator: &mem.Allocator) %[]u8 { switch (builtin.os) { Os.linux => { // If the currently executing binary has been deleted, @@ -1612,7 +1612,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 { } } -pub fn isTty(handle: FileHandle) -> bool { +pub fn isTty(handle: FileHandle) bool { if (is_windows) { return windows_util.windowsIsTty(handle); } else { diff --git a/std/os/linux.zig b/std/os/linux.zig index c254f83d10..04cdafb0ac 100644 --- a/std/os/linux.zig +++ b/std/os/linux.zig @@ -368,14 +368,14 @@ pub const TFD_CLOEXEC = O_CLOEXEC; pub const TFD_TIMER_ABSTIME = 1; pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); -fn unsigned(s: i32) -> u32 { return @bitCast(u32, s); } -fn signed(s: u32) -> i32 { return @bitCast(i32, s); } -pub fn WEXITSTATUS(s: i32) -> i32 { return signed((unsigned(s) & 0xff00) >> 8); } -pub fn WTERMSIG(s: i32) -> i32 { return signed(unsigned(s) & 0x7f); } -pub fn WSTOPSIG(s: i32) -> i32 { return WEXITSTATUS(s); } -pub fn WIFEXITED(s: i32) -> bool { return WTERMSIG(s) == 0; } -pub fn WIFSTOPPED(s: i32) -> bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; } -pub fn WIFSIGNALED(s: i32) -> bool { return (unsigned(s)&0xffff)-%1 < 0xff; } +fn unsigned(s: i32) u32 { return @bitCast(u32, s); } +fn signed(s: u32) i32 { return @bitCast(i32, s); } +pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); } +pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); } +pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); } +pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; } +pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; } +pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; } pub const winsize = extern struct { @@ -386,161 +386,159 @@ pub const winsize = extern struct { }; /// Get the errno from a syscall return value, or 0 for no error. -pub fn getErrno(r: usize) -> usize { +pub fn getErrno(r: usize) usize { const signed_r = @bitCast(isize, r); return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0; } -pub fn dup2(old: i32, new: i32) -> usize { +pub fn dup2(old: i32, new: i32) usize { return arch.syscall2(arch.SYS_dup2, usize(old), usize(new)); } -pub fn chdir(path: &const u8) -> usize { +pub fn chdir(path: &const u8) usize { return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); } -pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize { +pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize { return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); } -pub fn fork() -> usize { +pub fn fork() usize { return arch.syscall0(arch.SYS_fork); } -pub fn getcwd(buf: &u8, size: usize) -> usize { +pub fn getcwd(buf: &u8, size: usize) usize { return arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size); } -pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize { +pub fn getdents(fd: i32, dirp: &u8, count: usize) usize { return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count); } -pub fn isatty(fd: i32) -> bool { +pub fn isatty(fd: i32) bool { var wsz: winsize = undefined; return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; } -pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize { +pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize { return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); } -pub fn mkdir(path: &const u8, mode: u32) -> usize { +pub fn mkdir(path: &const u8, mode: u32) usize { return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); } -pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) - -> usize -{ +pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset)); } -pub fn munmap(address: &u8, length: usize) -> usize { +pub fn munmap(address: &u8, length: usize) usize { return arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length); } -pub fn read(fd: i32, buf: &u8, count: usize) -> usize { +pub fn read(fd: i32, buf: &u8, count: usize) usize { return arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count); } -pub fn rmdir(path: &const u8) -> usize { +pub fn rmdir(path: &const u8) usize { return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); } -pub fn symlink(existing: &const u8, new: &const u8) -> usize { +pub fn symlink(existing: &const u8, new: &const u8) usize { return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); } -pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize { +pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize { return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); } -pub fn pipe(fd: &[2]i32) -> usize { +pub fn pipe(fd: &[2]i32) usize { return pipe2(fd, 0); } -pub fn pipe2(fd: &[2]i32, flags: usize) -> usize { +pub fn pipe2(fd: &[2]i32, flags: usize) usize { return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); } -pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { +pub fn write(fd: i32, buf: &const u8, count: usize) usize { return arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count); } -pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize { +pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize { return arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset); } -pub fn rename(old: &const u8, new: &const u8) -> usize { +pub fn rename(old: &const u8, new: &const u8) usize { return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); } -pub fn open(path: &const u8, flags: u32, perm: usize) -> usize { +pub fn open(path: &const u8, flags: u32, perm: usize) usize { return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); } -pub fn create(path: &const u8, perm: usize) -> usize { +pub fn create(path: &const u8, perm: usize) usize { return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); } -pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize { +pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize { return arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode); } -pub fn close(fd: i32) -> usize { +pub fn close(fd: i32) usize { return arch.syscall1(arch.SYS_close, usize(fd)); } -pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize { +pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { return arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos); } -pub fn exit(status: i32) -> noreturn { +pub fn exit(status: i32) noreturn { _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); unreachable; } -pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize { +pub fn getrandom(buf: &u8, count: usize, flags: u32) usize { return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags)); } -pub fn kill(pid: i32, sig: i32) -> usize { +pub fn kill(pid: i32, sig: i32) usize { return arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig)); } -pub fn unlink(path: &const u8) -> usize { +pub fn unlink(path: &const u8) usize { return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); } -pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize { +pub fn waitpid(pid: i32, status: &i32, options: i32) usize { return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); } -pub fn nanosleep(req: &const timespec, rem: ?×pec) -> usize { +pub fn nanosleep(req: &const timespec, rem: ?×pec) usize { return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); } -pub fn setuid(uid: u32) -> usize { +pub fn setuid(uid: u32) usize { return arch.syscall1(arch.SYS_setuid, uid); } -pub fn setgid(gid: u32) -> usize { +pub fn setgid(gid: u32) usize { return arch.syscall1(arch.SYS_setgid, gid); } -pub fn setreuid(ruid: u32, euid: u32) -> usize { +pub fn setreuid(ruid: u32, euid: u32) usize { return arch.syscall2(arch.SYS_setreuid, ruid, euid); } -pub fn setregid(rgid: u32, egid: u32) -> usize { +pub fn setregid(rgid: u32, egid: u32) usize { return arch.syscall2(arch.SYS_setregid, rgid, egid); } -pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize { +pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize { return arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8); } -pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize { +pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize { assert(sig >= 1); assert(sig != SIGKILL); assert(sig != SIGSTOP); @@ -548,7 +546,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti .handler = act.handler, .flags = act.flags | SA_RESTORER, .mask = undefined, - .restorer = @ptrCast(extern fn(), arch.restore_rt), + .restorer = @ptrCast(extern fn()void, arch.restore_rt), }; var ksa_old: k_sigaction = undefined; @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8); @@ -571,25 +569,25 @@ const all_mask = []usize{@maxValue(usize)}; const app_mask = []usize{0xfffffffc7fffffff}; const k_sigaction = extern struct { - handler: extern fn(i32), + handler: extern fn(i32)void, flags: usize, - restorer: extern fn(), + restorer: extern fn()void, mask: [2]u32, }; /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. pub const Sigaction = struct { - handler: extern fn(i32), + handler: extern fn(i32)void, mask: sigset_t, flags: u32, }; -pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize)); -pub const SIG_DFL = @intToPtr(extern fn(i32), 0); -pub const SIG_IGN = @intToPtr(extern fn(i32), 1); +pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize)); +pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0); +pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1); pub const empty_sigset = []usize{0} ** sigset_t.len; -pub fn raise(sig: i32) -> usize { +pub fn raise(sig: i32) usize { var set: sigset_t = undefined; blockAppSignals(&set); const tid = i32(arch.syscall0(arch.SYS_gettid)); @@ -598,24 +596,24 @@ pub fn raise(sig: i32) -> usize { return ret; } -fn blockAllSignals(set: &sigset_t) { +fn blockAllSignals(set: &sigset_t) void { _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8); } -fn blockAppSignals(set: &sigset_t) { +fn blockAppSignals(set: &sigset_t) void { _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8); } -fn restoreSignals(set: &sigset_t) { +fn restoreSignals(set: &sigset_t) void { _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8); } -pub fn sigaddset(set: &sigset_t, sig: u6) { +pub fn sigaddset(set: &sigset_t, sig: u6) void { const s = sig - 1; (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); } -pub fn sigismember(set: &const sigset_t, sig: u6) -> bool { +pub fn sigismember(set: &const sigset_t, sig: u6) bool { const s = sig - 1; return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; } @@ -652,69 +650,69 @@ pub const iovec = extern struct { iov_len: usize, }; -pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { +pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { return arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len)); } -pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { +pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { return arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len)); } -pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize { +pub fn socket(domain: i32, socket_type: i32, protocol: i32) usize { return arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol)); } -pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize { +pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) usize { return arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen)); } -pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize { +pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) usize { return arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen)); } -pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize { +pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) usize { return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags); } -pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { +pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize { return arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len)); } -pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize { +pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) usize { return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags); } pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, - noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize + noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize { return arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); } -pub fn shutdown(fd: i32, how: i32) -> usize { +pub fn shutdown(fd: i32, how: i32) usize { return arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)); } -pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { +pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize { return arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len)); } -pub fn listen(fd: i32, backlog: i32) -> usize { +pub fn listen(fd: i32, backlog: i32) usize { return arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)); } -pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize { +pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize { return arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen)); } -pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize { +pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { return arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0])); } -pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { +pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { return accept4(fd, addr, len, 0); } -pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize { +pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize { return arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags); } @@ -722,7 +720,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: // error SystemResources; // error Io; // -// pub fn if_nametoindex(name: []u8) -> %u32 { +// pub fn if_nametoindex(name: []u8) %u32 { // var ifr: ifreq = undefined; // // if (name.len >= ifr.ifr_name.len) { @@ -749,7 +747,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: pub const Stat = arch.Stat; pub const timespec = arch.timespec; -pub fn fstat(fd: i32, stat_buf: &Stat) -> usize { +pub fn fstat(fd: i32, stat_buf: &Stat) usize { return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)); } @@ -760,19 +758,19 @@ pub const epoll_event = extern struct { data: epoll_data }; -pub fn epoll_create() -> usize { +pub fn epoll_create() usize { return arch.syscall1(arch.SYS_epoll_create, usize(1)); } -pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) -> usize { +pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize { return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev)); } -pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) -> usize { +pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) usize { return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout)); } -pub fn timerfd_create(clockid: i32, flags: u32) -> usize { +pub fn timerfd_create(clockid: i32, flags: u32) usize { return arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags)); } @@ -781,11 +779,11 @@ pub const itimerspec = extern struct { it_value: timespec }; -pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) -> usize { +pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize { return arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value)); } -pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) -> usize { +pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize { return arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value)); } diff --git a/std/os/linux_i386.zig b/std/os/linux_i386.zig index ed49e33c2b..353461562b 100644 --- a/std/os/linux_i386.zig +++ b/std/os/linux_i386.zig @@ -419,20 +419,20 @@ pub const F_GETOWN_EX = 16; pub const F_GETOWNER_UIDS = 17; -pub inline fn syscall0(number: usize) -> usize { +pub inline fn syscall0(number: usize) usize { asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number)) } -pub inline fn syscall1(number: usize, arg1: usize) -> usize { +pub inline fn syscall1(number: usize, arg1: usize) usize { asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), [arg1] "{ebx}" (arg1)) } -pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { +pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize { asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), @@ -440,7 +440,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { [arg2] "{ecx}" (arg2)) } -pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { +pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), @@ -449,7 +449,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> [arg3] "{edx}" (arg3)) } -pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { +pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), @@ -486,7 +486,7 @@ pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, [arg6] "{ebp}" (arg6)) } -pub nakedcc fn restore() { +pub nakedcc fn restore() void { asm volatile ( \\popl %%eax \\movl $119, %%eax @@ -496,7 +496,7 @@ pub nakedcc fn restore() { : "rcx", "r11") } -pub nakedcc fn restore_rt() { +pub nakedcc fn restore_rt() void { asm volatile ("int $0x80" : : [number] "{eax}" (usize(SYS_rt_sigreturn)) diff --git a/std/os/linux_x86_64.zig b/std/os/linux_x86_64.zig index db78decde2..3706633745 100644 --- a/std/os/linux_x86_64.zig +++ b/std/os/linux_x86_64.zig @@ -370,14 +370,14 @@ pub const F_GETOWN_EX = 16; pub const F_GETOWNER_UIDS = 17; -pub fn syscall0(number: usize) -> usize { +pub fn syscall0(number: usize) usize { return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number) : "rcx", "r11"); } -pub fn syscall1(number: usize, arg1: usize) -> usize { +pub fn syscall1(number: usize, arg1: usize) usize { return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), @@ -385,7 +385,7 @@ pub fn syscall1(number: usize, arg1: usize) -> usize { : "rcx", "r11"); } -pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { +pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), @@ -394,7 +394,7 @@ pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { : "rcx", "r11"); } -pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { +pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), @@ -404,7 +404,7 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { : "rcx", "r11"); } -pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { +pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), @@ -415,7 +415,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz : "rcx", "r11"); } -pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize { +pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { return asm volatile ("syscall" : [ret] "={rax}" (-> usize) : [number] "{rax}" (number), @@ -428,7 +428,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz } pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, - arg5: usize, arg6: usize) -> usize + arg5: usize, arg6: usize) usize { return asm volatile ("syscall" : [ret] "={rax}" (-> usize) @@ -442,7 +442,7 @@ pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz : "rcx", "r11"); } -pub nakedcc fn restore_rt() { +pub nakedcc fn restore_rt() void { return asm volatile ("syscall" : : [number] "{rax}" (usize(SYS_rt_sigreturn)) diff --git a/std/os/path.zig b/std/os/path.zig index c71fa68716..eb95f83f45 100644 --- a/std/os/path.zig +++ b/std/os/path.zig @@ -22,7 +22,7 @@ pub const delimiter = if (is_windows) delimiter_windows else delimiter_posix; const is_windows = builtin.os == builtin.Os.windows; -pub fn isSep(byte: u8) -> bool { +pub fn isSep(byte: u8) bool { if (is_windows) { return byte == '/' or byte == '\\'; } else { @@ -32,7 +32,7 @@ pub fn isSep(byte: u8) -> bool { /// Naively combines a series of paths with the native path seperator. /// Allocates memory for the result, which must be freed by the caller. -pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { +pub fn join(allocator: &Allocator, paths: ...) %[]u8 { if (is_windows) { return joinWindows(allocator, paths); } else { @@ -40,11 +40,11 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { } } -pub fn joinWindows(allocator: &Allocator, paths: ...) -> %[]u8 { +pub fn joinWindows(allocator: &Allocator, paths: ...) %[]u8 { return mem.join(allocator, sep_windows, paths); } -pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 { +pub fn joinPosix(allocator: &Allocator, paths: ...) %[]u8 { return mem.join(allocator, sep_posix, paths); } @@ -69,7 +69,7 @@ test "os.path.join" { "/home/andy/dev/zig/build/lib/zig/std/io.zig")); } -pub fn isAbsolute(path: []const u8) -> bool { +pub fn isAbsolute(path: []const u8) bool { if (is_windows) { return isAbsoluteWindows(path); } else { @@ -77,7 +77,7 @@ pub fn isAbsolute(path: []const u8) -> bool { } } -pub fn isAbsoluteWindows(path: []const u8) -> bool { +pub fn isAbsoluteWindows(path: []const u8) bool { if (path[0] == '/') return true; @@ -96,7 +96,7 @@ pub fn isAbsoluteWindows(path: []const u8) -> bool { return false; } -pub fn isAbsolutePosix(path: []const u8) -> bool { +pub fn isAbsolutePosix(path: []const u8) bool { return path[0] == sep_posix; } @@ -129,11 +129,11 @@ test "os.path.isAbsolutePosix" { testIsAbsolutePosix("./baz", false); } -fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) { +fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void { assert(isAbsoluteWindows(path) == expected_result); } -fn testIsAbsolutePosix(path: []const u8, expected_result: bool) { +fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void { assert(isAbsolutePosix(path) == expected_result); } @@ -149,7 +149,7 @@ pub const WindowsPath = struct { }; }; -pub fn windowsParsePath(path: []const u8) -> WindowsPath { +pub fn windowsParsePath(path: []const u8) WindowsPath { if (path.len >= 2 and path[1] == ':') { return WindowsPath { .is_abs = isAbsoluteWindows(path), @@ -248,7 +248,7 @@ test "os.path.windowsParsePath" { } } -pub fn diskDesignator(path: []const u8) -> []const u8 { +pub fn diskDesignator(path: []const u8) []const u8 { if (is_windows) { return diskDesignatorWindows(path); } else { @@ -256,11 +256,11 @@ pub fn diskDesignator(path: []const u8) -> []const u8 { } } -pub fn diskDesignatorWindows(path: []const u8) -> []const u8 { +pub fn diskDesignatorWindows(path: []const u8) []const u8 { return windowsParsePath(path).disk_designator; } -fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool { +fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool { const sep1 = ns1[0]; const sep2 = ns2[0]; @@ -271,7 +271,7 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool { return asciiEqlIgnoreCase(??it1.next(), ??it2.next()); } -fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) -> bool { +fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) bool { switch (kind) { WindowsPath.Kind.None => { assert(p1.len == 0); @@ -294,14 +294,14 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8 } } -fn asciiUpper(byte: u8) -> u8 { +fn asciiUpper(byte: u8) u8 { return switch (byte) { 'a' ... 'z' => 'A' + (byte - 'a'), else => byte, }; } -fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) -> bool { +fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool { if (s1.len != s2.len) return false; var i: usize = 0; @@ -313,7 +313,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) -> bool { } /// Converts the command line arguments into a slice and calls `resolveSlice`. -pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 { +pub fn resolve(allocator: &Allocator, args: ...) %[]u8 { var paths: [args.len][]const u8 = undefined; comptime var arg_i = 0; inline while (arg_i < args.len) : (arg_i += 1) { @@ -323,7 +323,7 @@ pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 { } /// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`. -pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { +pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) %[]u8 { if (is_windows) { return resolveWindows(allocator, paths); } else { @@ -337,7 +337,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { /// If all paths are relative it uses the current working directory as a starting point. /// Each drive has its own current working directory. /// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters. -pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { +pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) %[]u8 { if (paths.len == 0) { assert(is_windows); // resolveWindows called on non windows can't use getCwd return os.getCwd(allocator); @@ -520,7 +520,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 /// It resolves "." and "..". /// The result does not have a trailing path separator. /// If all paths are relative it uses the current working directory as a starting point. -pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { +pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) %[]u8 { if (paths.len == 0) { assert(!is_windows); // resolvePosix called on windows can't use getCwd return os.getCwd(allocator); @@ -648,15 +648,15 @@ test "os.path.resolvePosix" { assert(mem.eql(u8, testResolvePosix([][]const u8{"/foo/tmp.3/", "../tmp.3/cycles/root.js"}), "/foo/tmp.3/cycles/root.js")); } -fn testResolveWindows(paths: []const []const u8) -> []u8 { +fn testResolveWindows(paths: []const []const u8) []u8 { return resolveWindows(debug.global_allocator, paths) catch unreachable; } -fn testResolvePosix(paths: []const []const u8) -> []u8 { +fn testResolvePosix(paths: []const []const u8) []u8 { return resolvePosix(debug.global_allocator, paths) catch unreachable; } -pub fn dirname(path: []const u8) -> []const u8 { +pub fn dirname(path: []const u8) []const u8 { if (is_windows) { return dirnameWindows(path); } else { @@ -664,7 +664,7 @@ pub fn dirname(path: []const u8) -> []const u8 { } } -pub fn dirnameWindows(path: []const u8) -> []const u8 { +pub fn dirnameWindows(path: []const u8) []const u8 { if (path.len == 0) return path[0..0]; @@ -695,7 +695,7 @@ pub fn dirnameWindows(path: []const u8) -> []const u8 { return path[0..end_index]; } -pub fn dirnamePosix(path: []const u8) -> []const u8 { +pub fn dirnamePosix(path: []const u8) []const u8 { if (path.len == 0) return path[0..0]; @@ -766,15 +766,15 @@ test "os.path.dirnameWindows" { testDirnameWindows("foo", ""); } -fn testDirnamePosix(input: []const u8, expected_output: []const u8) { +fn testDirnamePosix(input: []const u8, expected_output: []const u8) void { assert(mem.eql(u8, dirnamePosix(input), expected_output)); } -fn testDirnameWindows(input: []const u8, expected_output: []const u8) { +fn testDirnameWindows(input: []const u8, expected_output: []const u8) void { assert(mem.eql(u8, dirnameWindows(input), expected_output)); } -pub fn basename(path: []const u8) -> []const u8 { +pub fn basename(path: []const u8) []const u8 { if (is_windows) { return basenameWindows(path); } else { @@ -782,7 +782,7 @@ pub fn basename(path: []const u8) -> []const u8 { } } -pub fn basenamePosix(path: []const u8) -> []const u8 { +pub fn basenamePosix(path: []const u8) []const u8 { if (path.len == 0) return []u8{}; @@ -803,7 +803,7 @@ pub fn basenamePosix(path: []const u8) -> []const u8 { return path[start_index + 1..end_index]; } -pub fn basenameWindows(path: []const u8) -> []const u8 { +pub fn basenameWindows(path: []const u8) []const u8 { if (path.len == 0) return []u8{}; @@ -874,15 +874,15 @@ test "os.path.basename" { testBasenameWindows("file:stream", "file:stream"); } -fn testBasename(input: []const u8, expected_output: []const u8) { +fn testBasename(input: []const u8, expected_output: []const u8) void { assert(mem.eql(u8, basename(input), expected_output)); } -fn testBasenamePosix(input: []const u8, expected_output: []const u8) { +fn testBasenamePosix(input: []const u8, expected_output: []const u8) void { assert(mem.eql(u8, basenamePosix(input), expected_output)); } -fn testBasenameWindows(input: []const u8, expected_output: []const u8) { +fn testBasenameWindows(input: []const u8, expected_output: []const u8) void { assert(mem.eql(u8, basenameWindows(input), expected_output)); } @@ -890,7 +890,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) { /// resolve to the same path (after calling `resolve` on each), a zero-length /// string is returned. /// On Windows this canonicalizes the drive to a capital letter and paths to `\\`. -pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 { +pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { if (is_windows) { return relativeWindows(allocator, from, to); } else { @@ -898,7 +898,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u } } -pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 { +pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { const resolved_from = try resolveWindows(allocator, [][]const u8{from}); defer allocator.free(resolved_from); @@ -971,7 +971,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) return []u8{}; } -pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 { +pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { const resolved_from = try resolvePosix(allocator, [][]const u8{from}); defer allocator.free(resolved_from); @@ -1056,12 +1056,12 @@ test "os.path.relative" { testRelativePosix("/baz", "/baz-quux", "../baz-quux"); } -fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) { +fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) void { const result = relativePosix(debug.global_allocator, from, to) catch unreachable; assert(mem.eql(u8, result, expected_output)); } -fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) { +fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) void { const result = relativeWindows(debug.global_allocator, from, to) catch unreachable; assert(mem.eql(u8, result, expected_output)); } @@ -1077,7 +1077,7 @@ error InputOutput; /// Expands all symbolic links and resolves references to `.`, `..`, and /// extra `/` characters in ::pathname. /// Caller must deallocate result. -pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { +pub fn real(allocator: &Allocator, pathname: []const u8) %[]u8 { switch (builtin.os) { Os.windows => { const pathname_buf = try allocator.alloc(u8, pathname.len + 1); diff --git a/std/os/windows/index.zig b/std/os/windows/index.zig index 524760d9ed..e7bf1916f4 100644 --- a/std/os/windows/index.zig +++ b/std/os/windows/index.zig @@ -1,100 +1,100 @@ pub const ERROR = @import("error.zig"); pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR, - pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) -> BOOL; + pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) BOOL; -pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL; +pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) BOOL; -pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> BOOL; +pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) BOOL; -pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL; +pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL; pub extern "kernel32" stdcallcc fn CreateDirectoryA(lpPathName: LPCSTR, - lpSecurityAttributes: ?&SECURITY_ATTRIBUTES) -> BOOL; + lpSecurityAttributes: ?&SECURITY_ATTRIBUTES) BOOL; pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD, dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD, - dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE; + dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) HANDLE; pub extern "kernel32" stdcallcc fn CreatePipe(hReadPipe: &HANDLE, hWritePipe: &HANDLE, - lpPipeAttributes: &const SECURITY_ATTRIBUTES, nSize: DWORD) -> BOOL; + lpPipeAttributes: &const SECURITY_ATTRIBUTES, nSize: DWORD) BOOL; pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lpCommandLine: LPSTR, lpProcessAttributes: ?&SECURITY_ATTRIBUTES, lpThreadAttributes: ?&SECURITY_ATTRIBUTES, bInheritHandles: BOOL, dwCreationFlags: DWORD, lpEnvironment: ?LPVOID, lpCurrentDirectory: ?LPCSTR, lpStartupInfo: &STARTUPINFOA, - lpProcessInformation: &PROCESS_INFORMATION) -> BOOL; + lpProcessInformation: &PROCESS_INFORMATION) BOOL; pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR, - dwFlags: DWORD) -> BOOLEAN; + dwFlags: DWORD) BOOLEAN; -pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> BOOL; +pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) BOOL; -pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn; +pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn; -pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) -> BOOL; +pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) BOOL; -pub extern "kernel32" stdcallcc fn GetCommandLineA() -> LPSTR; +pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR; -pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> BOOL; +pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) BOOL; -pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) -> DWORD; +pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) DWORD; -pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() -> ?LPCH; +pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?LPCH; -pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) -> DWORD; +pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) DWORD; -pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) -> BOOL; +pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) BOOL; -pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL; +pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) BOOL; -pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) -> DWORD; +pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) DWORD; -pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD; +pub extern "kernel32" stdcallcc fn GetLastError() DWORD; pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE, in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, out_lpFileInformation: &c_void, - in_dwBufferSize: DWORD) -> BOOL; + in_dwBufferSize: DWORD) BOOL; pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpszFilePath: LPSTR, - cchFilePath: DWORD, dwFlags: DWORD) -> DWORD; + cchFilePath: DWORD, dwFlags: DWORD) DWORD; -pub extern "kernel32" stdcallcc fn GetProcessHeap() -> ?HANDLE; +pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE; -pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) -> ?HANDLE; +pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE; -pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> ?LPVOID; +pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?LPVOID; -pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL; +pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) BOOL; pub extern "kernel32" stdcallcc fn MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR, - dwFlags: DWORD) -> BOOL; + dwFlags: DWORD) BOOL; pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: LPVOID, in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD, - in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL; + in_out_lpOverlapped: ?&OVERLAPPED) BOOL; pub extern "kernel32" stdcallcc fn SetFilePointerEx(in_fFile: HANDLE, in_liDistanceToMove: LARGE_INTEGER, - out_opt_ldNewFilePointer: ?&LARGE_INTEGER, in_dwMoveMethod: DWORD) -> BOOL; + out_opt_ldNewFilePointer: ?&LARGE_INTEGER, in_dwMoveMethod: DWORD) BOOL; -pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) -> BOOL; +pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) BOOL; -pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD); +pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD) void; -pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL; +pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) BOOL; -pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD; +pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) DWORD; pub extern "kernel32" stdcallcc fn WriteFile(in_hFile: HANDLE, in_lpBuffer: &const c_void, in_nNumberOfBytesToWrite: DWORD, out_lpNumberOfBytesWritten: ?&DWORD, - in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL; + in_out_lpOverlapped: ?&OVERLAPPED) BOOL; //TODO: call unicode versions instead of relying on ANSI code page -pub extern "kernel32" stdcallcc fn LoadLibraryA(lpLibFileName: LPCSTR) -> ?HMODULE; +pub extern "kernel32" stdcallcc fn LoadLibraryA(lpLibFileName: LPCSTR) ?HMODULE; -pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) -> BOOL; +pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) BOOL; -pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) -> c_int; +pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int; pub const PROV_RSA_FULL = 1; @@ -295,4 +295,4 @@ pub const MOVEFILE_WRITE_THROUGH = 8; pub const FILE_BEGIN = 0; pub const FILE_CURRENT = 1; -pub const FILE_END = 2;
\ No newline at end of file +pub const FILE_END = 2; diff --git a/std/os/windows/util.zig b/std/os/windows/util.zig index f1c6f049ee..a8a2e3fcd5 100644 --- a/std/os/windows/util.zig +++ b/std/os/windows/util.zig @@ -10,7 +10,7 @@ error WaitAbandoned; error WaitTimeOut; error Unexpected; -pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) -> %void { +pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) %void { const result = windows.WaitForSingleObject(handle, milliseconds); return switch (result) { windows.WAIT_ABANDONED => error.WaitAbandoned, @@ -26,7 +26,7 @@ pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) -> }; } -pub fn windowsClose(handle: windows.HANDLE) { +pub fn windowsClose(handle: windows.HANDLE) void { assert(windows.CloseHandle(handle) != 0); } @@ -35,7 +35,7 @@ error OperationAborted; error IoPending; error BrokenPipe; -pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void { +pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) %void { if (windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) { const err = windows.GetLastError(); return switch (err) { @@ -50,7 +50,7 @@ pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void { } } -pub fn windowsIsTty(handle: windows.HANDLE) -> bool { +pub fn windowsIsTty(handle: windows.HANDLE) bool { if (windowsIsCygwinPty(handle)) return true; @@ -58,7 +58,7 @@ pub fn windowsIsTty(handle: windows.HANDLE) -> bool { return windows.GetConsoleMode(handle, &out) != 0; } -pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool { +pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool { const size = @sizeOf(windows.FILE_NAME_INFO); var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH); @@ -83,7 +83,7 @@ error PipeBusy; /// size buffer is too small, and the provided allocator is null, ::error.NameTooLong is returned. /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_mode: windows.DWORD, - creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD, allocator: ?&mem.Allocator) -> %windows.HANDLE + creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD, allocator: ?&mem.Allocator) %windows.HANDLE { var stack_buf: [os.max_noalloc_path_len]u8 = undefined; var path0: []u8 = undefined; @@ -120,7 +120,7 @@ pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_m } /// Caller must free result. -pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) -> %[]u8 { +pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) %[]u8 { // count bytes needed const bytes_needed = x: { var bytes_needed: usize = 1; // 1 for the final null byte @@ -152,13 +152,13 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) } error DllNotFound; -pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) -> %windows.HMODULE { +pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) %windows.HMODULE { const padded_buff = try cstr.addNullByte(allocator, dll_path); defer allocator.free(padded_buff); return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound; } -pub fn windowsUnloadDll(hModule: windows.HMODULE) { +pub fn windowsUnloadDll(hModule: windows.HMODULE) void { assert(windows.FreeLibrary(hModule)!= 0); } diff --git a/std/os/zen.zig b/std/os/zen.zig index 37ec68763d..f31d46e481 100644 --- a/std/os/zen.zig +++ b/std/os/zen.zig @@ -21,28 +21,28 @@ pub const SYS_createThread = 5; //// Syscalls //// //////////////////// -pub fn exit(status: i32) -> noreturn { +pub fn exit(status: i32) noreturn { _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); unreachable; } -pub fn createMailbox(id: u16) { +pub fn createMailbox(id: u16) void { _ = syscall1(SYS_createMailbox, id); } -pub fn send(mailbox_id: u16, data: usize) { +pub fn send(mailbox_id: u16, data: usize) void { _ = syscall2(SYS_send, mailbox_id, data); } -pub fn receive(mailbox_id: u16) -> usize { +pub fn receive(mailbox_id: u16) usize { return syscall1(SYS_receive, mailbox_id); } -pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) -> bool { +pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0; } -pub fn createThread(function: fn()) -> u16 { +pub fn createThread(function: fn()) u16 { return u16(syscall1(SYS_createThread, @ptrToInt(function))); } @@ -51,20 +51,20 @@ pub fn createThread(function: fn()) -> u16 { //// Syscall stubs //// ///////////////////////// -pub inline fn syscall0(number: usize) -> usize { +pub inline fn syscall0(number: usize) usize { return asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number)); } -pub inline fn syscall1(number: usize, arg1: usize) -> usize { +pub inline fn syscall1(number: usize, arg1: usize) usize { return asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), [arg1] "{ecx}" (arg1)); } -pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { +pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize { return asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), @@ -72,7 +72,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { [arg2] "{edx}" (arg2)); } -pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { +pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { return asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), @@ -81,7 +81,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> [arg3] "{ebx}" (arg3)); } -pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { +pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { return asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), @@ -92,7 +92,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg } pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, - arg4: usize, arg5: usize) -> usize + arg4: usize, arg5: usize) usize { return asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) |
