authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-23 16:13:57-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-23 16:13:57-05:00
logfe3063e58cf81287a26219903f2720439dfeb7e6
treed07f638d136f35c276c58ac8259cdb84d383ddfb
parentb1ace32f2373914d92459934b9f0697baca9fe83

update std code for MacOS

closes #264

3 files changed, 15 insertions(+), 6 deletions(-)

std/bootstrap.zig+8-5
...@@ -2,8 +2,6 @@...@@ -2,8 +2,6 @@
22
3const root = @import("@root");3const root = @import("@root");
4const std = @import("std");4const std = @import("std");
5const linux = std.linux;
6const cstr = std.cstr;
75
8const want_start_symbol = switch(@compileVar("os")) {6const want_start_symbol = switch(@compileVar("os")) {
9 Os.linux => true,7 Os.linux => true,
...@@ -11,6 +9,11 @@ const want_start_symbol = switch(@compileVar("os")) {...@@ -11,6 +9,11 @@ const want_start_symbol = switch(@compileVar("os")) {
11};9};
12const want_main_symbol = !want_start_symbol;10const want_main_symbol = !want_start_symbol;
1311
12const exit = switch(@compileVar("os")) {
13 Os.linux => std.linux.exit,
14 Os.darwin => std.darwin.exit,
15};
16
14var argc: usize = undefined;17var argc: usize = undefined;
15var argv: &&u8 = undefined;18var argv: &&u8 = undefined;
1619
...@@ -35,14 +38,14 @@ fn callMain() -> %void {...@@ -35,14 +38,14 @@ fn callMain() -> %void {
35 const args = @alloca([]u8, argc);38 const args = @alloca([]u8, argc);
36 for (args) |_, i| {39 for (args) |_, i| {
37 const ptr = argv[i];40 const ptr = argv[i];
38 args[i] = ptr[0...cstr.len(ptr)];41 args[i] = ptr[0...std.cstr.len(ptr)];
39 }42 }
40 return root.main(args);43 return root.main(args);
41}44}
4245
43fn callMainAndExit() -> unreachable {46fn callMainAndExit() -> unreachable {
44 callMain() %% linux.exit(1);47 callMain() %% exit(1);
45 linux.exit(0);48 exit(0);
46}49}
4750
48export fn main(c_argc: i32, c_argv: &&u8) -> i32 {51export fn main(c_argc: i32, c_argv: &&u8) -> i32 {
std/darwin.zig+6-1
...@@ -48,6 +48,11 @@ pub const SIGPWR = 30;...@@ -48,6 +48,11 @@ pub const SIGPWR = 30;
48pub const SIGSYS = 31;48pub const SIGSYS = 31;
49pub const SIGUNUSED = SIGSYS;49pub const SIGUNUSED = SIGSYS;
5050
51pub fn exit(status: usize) -> unreachable {
52 arch.syscall1(arch.SYS_exit, status);
53 @unreachable()
54}
55
51/// Get the errno from a syscall return value, or 0 for no error.56/// Get the errno from a syscall return value, or 0 for no error.
52pub fn getErrno(r: usize) -> usize {57pub fn getErrno(r: usize) -> usize {
53 const signed_r = *(&isize)(&r);58 const signed_r = *(&isize)(&r);
...@@ -67,7 +72,7 @@ pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {...@@ -67,7 +72,7 @@ pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
67}72}
6873
69pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {74pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
70 var buf: [path.len + 1]u8 = undefined;75 const buf = @alloca(u8, path.len + 1);
71 @memcpy(&buf[0], &path[0], path.len);76 @memcpy(&buf[0], &path[0], path.len);
72 buf[path.len] = 0;77 buf[path.len] = 0;
73 return open_c(buf.ptr, flags, perm);78 return open_c(buf.ptr, flags, perm);
std/darwin_x86_64.zig+1
...@@ -11,6 +11,7 @@ pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics...@@ -11,6 +11,7 @@ pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics
1111
12// TODO: use the above constants to create the below values12// TODO: use the above constants to create the below values
1313
14pub const SYS_exit = 0x2000001;
14pub const SYS_read = 0x2000003;15pub const SYS_read = 0x2000003;
15pub const SYS_write = 0x2000004;16pub const SYS_write = 0x2000004;
16pub const SYS_open = 0x2000005;17pub const SYS_open = 0x2000005;