aboutsummaryrefslogtreecommitdiff
path: root/std/os.zig
diff options
context:
space:
mode:
authoralter <p@scene.cl>2016-09-12 01:01:06 -0300
committerAndrew Kelley <superjoe30@gmail.com>2016-09-14 02:46:02 -0400
commitcf9b21c09fc641b4697e06981ac5114a8d3d09ab (patch)
treea69ab92c864c8807209eb09214b868bf8cce39ec /std/os.zig
parent06f2f4d64b63cf78a3ff77cc64dbc822123f454d (diff)
downloadzig-cf9b21c09fc641b4697e06981ac5114a8d3d09ab.tar.gz
zig-cf9b21c09fc641b4697e06981ac5114a8d3d09ab.zip
MacOSX compatibility
- Implemented some syscall for MacOSX - tested on : El Capitan 10.11 x86_64 - make self hosted test run on macosx - modified run_test so it does not fail when parseh throws warnings (most of them are related to buildin types from gcc that arent defined in header files and unions) - making -mmacosx-version-min and -mios-version-min works like gcc (command line paramers have precedence over enviroment variables)
Diffstat (limited to 'std/os.zig')
-rw-r--r--std/os.zig41
1 files changed, 23 insertions, 18 deletions
diff --git a/std/os.zig b/std/os.zig
index bfdc97220a..806cc43f33 100644
--- a/std/os.zig
+++ b/std/os.zig
@@ -1,33 +1,38 @@
-const linux = @import("linux.zig");
+const system = switch(@compileVar("os")) {
+ linux => @import("linux.zig"),
+ darwin => @import("darwin.zig"),
+ else => @compileError("Unsupported OS"),
+};
const errno = @import("errno.zig");
-pub error SigInterrupt;
pub error Unexpected;
pub fn getRandomBytes(buf: []u8) -> %void {
- switch (@compileVar("os")) {
- linux => {
- const ret = linux.getrandom(buf.ptr, buf.len, 0);
- const err = linux.getErrno(ret);
- if (err > 0) {
- return switch (err) {
- errno.EINVAL => @unreachable(),
- errno.EFAULT => @unreachable(),
- errno.EINTR => error.SigInterrupt,
- else => error.Unexpected,
- }
+ while (true) {
+ const ret = switch (@compileVar("os")) {
+ linux => system.getrandom(buf.ptr, buf.len, 0),
+ darwin => system.getrandom(buf.ptr, buf.len),
+ else => @compileError("unsupported os"),
+ };
+ const err = system.getErrno(ret);
+ if (err > 0) {
+ return switch (err) {
+ errno.EINVAL => @unreachable(),
+ errno.EFAULT => @unreachable(),
+ errno.EINTR => continue,
+ else => error.Unexpected,
}
- },
- else => @compileError("unsupported os"),
+ }
+ return;
}
}
#attribute("cold")
pub fn abort() -> unreachable {
switch (@compileVar("os")) {
- linux => {
- linux.raise(linux.SIGABRT);
- linux.raise(linux.SIGKILL);
+ linux, darwin => {
+ system.raise(system.SIGABRT);
+ system.raise(system.SIGKILL);
while (true) {}
},
else => @compileError("unsupported os"),