aboutsummaryrefslogtreecommitdiff
path: root/std/os
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-01-09 09:56:24 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-01-09 09:56:24 -0500
commitd1d3dbc7b5bc986849db476e491300ffd18d4db5 (patch)
tree8ab3bb2b5b8a82edf18caca6e28dc8e74ab81d11 /std/os
parent5a8d87f5042b5ab86de7c72df4ce84a314878e40 (diff)
parent3c094116aae459b651934663a31981cf09cdb3e4 (diff)
downloadzig-d1d3dbc7b5bc986849db476e491300ffd18d4db5.tar.gz
zig-d1d3dbc7b5bc986849db476e491300ffd18d4db5.zip
Merge branch 'master' into llvm6
Diffstat (limited to 'std/os')
-rw-r--r--std/os/child_process.zig2
-rw-r--r--std/os/index.zig4
-rw-r--r--std/os/path.zig38
-rw-r--r--std/os/zen.zig19
4 files changed, 37 insertions, 26 deletions
diff --git a/std/os/child_process.zig b/std/os/child_process.zig
index e112cce66a..8bf60bc52b 100644
--- a/std/os/child_process.zig
+++ b/std/os/child_process.zig
@@ -191,7 +191,7 @@ pub const ChildProcess = struct {
pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8,
env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult
{
- const child = %%ChildProcess.init(argv, allocator);
+ const child = try ChildProcess.init(argv, allocator);
defer child.deinit();
child.stdin_behavior = ChildProcess.StdIo.Ignore;
diff --git a/std/os/index.zig b/std/os/index.zig
index 44d1507f44..e338359522 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -121,7 +121,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
test "os.getRandomBytes" {
var buf: [50]u8 = undefined;
- %%getRandomBytes(buf[0..]);
+ try getRandomBytes(buf[0..]);
}
/// Raises a signal in the current kernel thread, ending its execution.
@@ -1489,7 +1489,7 @@ test "windows arg parsing" {
fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) {
var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
for (expected_args) |expected_arg| {
- const arg = %%??it.next(debug.global_allocator);
+ const arg = ??it.next(debug.global_allocator) catch unreachable;
assert(mem.eql(u8, arg, expected_arg));
}
assert(it.next(debug.global_allocator) == null);
diff --git a/std/os/path.zig b/std/os/path.zig
index d14cc6ae20..7597282669 100644
--- a/std/os/path.zig
+++ b/std/os/path.zig
@@ -49,23 +49,23 @@ pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 {
}
test "os.path.join" {
- assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c"));
- assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c"));
+ assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c"));
+ assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c"));
- assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
- assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
+ assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
+ assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
- assert(mem.eql(u8, %%joinWindows(debug.global_allocator,
+ assert(mem.eql(u8, try joinWindows(debug.global_allocator,
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"),
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
- assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
- assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
+ assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
+ assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
- assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
- assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
+ assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
+ assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
- assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"),
+ assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"),
"/home/andy/dev/zig/build/lib/zig/std/io.zig"));
}
@@ -584,7 +584,7 @@ pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
}
test "os.path.resolve" {
- const cwd = %%os.getCwd(debug.global_allocator);
+ const cwd = try os.getCwd(debug.global_allocator);
if (is_windows) {
if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
cwd[0] = asciiUpper(cwd[0]);
@@ -598,11 +598,11 @@ test "os.path.resolve" {
test "os.path.resolveWindows" {
if (is_windows) {
- const cwd = %%os.getCwd(debug.global_allocator);
+ const cwd = try os.getCwd(debug.global_allocator);
const parsed_cwd = windowsParsePath(cwd);
{
const result = testResolveWindows([][]const u8{"/usr/local", "lib\\zig\\std\\array_list.zig"});
- const expected = %%join(debug.global_allocator,
+ const expected = try join(debug.global_allocator,
parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
@@ -611,7 +611,7 @@ test "os.path.resolveWindows" {
}
{
const result = testResolveWindows([][]const u8{"usr/local", "lib\\zig"});
- const expected = %%join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
+ const expected = try join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
}
@@ -649,11 +649,11 @@ test "os.path.resolvePosix" {
}
fn testResolveWindows(paths: []const []const u8) -> []u8 {
- return %%resolveWindows(debug.global_allocator, paths);
+ return resolveWindows(debug.global_allocator, paths) catch unreachable;
}
fn testResolvePosix(paths: []const []const u8) -> []u8 {
- return %%resolvePosix(debug.global_allocator, paths);
+ return resolvePosix(debug.global_allocator, paths) catch unreachable;
}
pub fn dirname(path: []const u8) -> []const u8 {
@@ -1057,12 +1057,12 @@ test "os.path.relative" {
}
fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) {
- const result = %%relativePosix(debug.global_allocator, from, to);
+ 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) {
- const result = %%relativeWindows(debug.global_allocator, from, to);
+ const result = relativeWindows(debug.global_allocator, from, to) catch unreachable;
assert(mem.eql(u8, result, expected_output));
}
@@ -1172,7 +1172,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
defer os.close(fd);
var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined;
- const proc_path = %%fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd);
+ const proc_path = fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd) catch unreachable;
return os.readLink(allocator, proc_path);
},
diff --git a/std/os/zen.zig b/std/os/zen.zig
index ffc491e404..37ec68763d 100644
--- a/std/os/zen.zig
+++ b/std/os/zen.zig
@@ -9,16 +9,23 @@ pub const MBOX_TERMINAL = 1;
//// Syscall numbers ////
///////////////////////////
-pub const SYS_createMailbox = 0;
-pub const SYS_send = 1;
-pub const SYS_receive = 2;
-pub const SYS_map = 3;
+pub const SYS_exit = 0;
+pub const SYS_createMailbox = 1;
+pub const SYS_send = 2;
+pub const SYS_receive = 3;
+pub const SYS_map = 4;
+pub const SYS_createThread = 5;
////////////////////
//// Syscalls ////
////////////////////
+pub fn exit(status: i32) -> noreturn {
+ _ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
+ unreachable;
+}
+
pub fn createMailbox(id: u16) {
_ = syscall1(SYS_createMailbox, id);
}
@@ -35,6 +42,10 @@ 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 {
+ return u16(syscall1(SYS_createThread, @ptrToInt(function)));
+}
+
/////////////////////////
//// Syscall stubs ////