aboutsummaryrefslogtreecommitdiff
path: root/std/os.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-03-26 06:39:28 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-03-26 06:39:28 -0400
commit5bc9feb5cb98fc13db62d01b2b9fec15677310a7 (patch)
tree12972dfc1f9b964bb74428ec0d6766e77b9b0be7 /std/os.zig
parent7ce753a16b0c16b4c6494467f42f2d5fe9a235e6 (diff)
downloadzig-5bc9feb5cb98fc13db62d01b2b9fec15677310a7.tar.gz
zig-5bc9feb5cb98fc13db62d01b2b9fec15677310a7.zip
organize std and make import relative to current file
closes #216
Diffstat (limited to 'std/os.zig')
-rw-r--r--std/os.zig74
1 files changed, 0 insertions, 74 deletions
diff --git a/std/os.zig b/std/os.zig
deleted file mode 100644
index 68a52f5ff1..0000000000
--- a/std/os.zig
+++ /dev/null
@@ -1,74 +0,0 @@
-const posix = switch(@compileVar("os")) {
- Os.linux => @import("linux.zig"),
- Os.darwin, Os.macosx, Os.ios => @import("darwin.zig"),
- else => @compileError("Unsupported OS"),
-};
-const windows = @import("windows.zig");
-const errno = @import("errno.zig");
-const linking_libc = @import("build.zig").linking_libc;
-const c = @import("c/index.zig");
-
-error Unexpected;
-
-/// 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 {
- while (true) {
- const err = switch (@compileVar("os")) {
- Os.linux => {
- if (linking_libc) {
- if (c.getrandom(buf.ptr, buf.len, 0) == -1) *c._errno() else 0
- } else {
- posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0))
- }
- },
- Os.darwin, Os.macosx, Os.ios => {
- if (linking_libc) {
- if (posix.getrandom(buf.ptr, buf.len) == -1) *c._errno() else 0
- } else {
- posix.getErrno(posix.getrandom(buf.ptr, buf.len))
- }
- },
- Os.windows => {
- var hCryptProv: windows.HCRYPTPROV = undefined;
- if (!windows.CryptAcquireContext(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {
- return error.Unexpected;
- }
- defer _ = windows.CryptReleaseContext(hCryptProv, 0);
-
- if (!windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr)) {
- return error.Unexpected;
- }
- return;
- },
- else => @compileError("Unsupported OS"),
- };
- if (err > 0) {
- return switch (err) {
- errno.EINVAL => unreachable,
- errno.EFAULT => unreachable,
- errno.EINTR => continue,
- else => error.Unexpected,
- }
- }
- return;
- }
-}
-
-/// 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 coldcc fn abort() -> noreturn {
- if (linking_libc) {
- c.abort();
- }
- switch (@compileVar("os")) {
- Os.linux => {
- _ = posix.raise(posix.SIGABRT);
- _ = posix.raise(posix.SIGKILL);
- while (true) {}
- },
- else => @compileError("Unsupported OS"),
- }
-}