authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-23 17:06:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-24 01:23:28-04:00
loga98fa56ae9ad437d3e4241bc2c231e0745766ba9
treefa621754f81e0007a6f894c0f726e810f0462d95
parent9e3ec98937de07d0e06f483ba8f7e6592b4dd152

std: [breaking] move errno to become an nonexhaustive enum

The primary purpose of this change is to eliminate one usage of `usingnamespace` in the standard library - specifically the usage for errno values in `std.os.linux`. This is accomplished by truncating the `E` prefix from error values, and making errno a proper enum. A similar strategy can be used to eliminate some other `usingnamespace` sites in the std lib.

40 files changed, 3509 insertions(+), 3448 deletions(-)

CMakeLists.txt+1-1
...@@ -426,7 +426,7 @@ set(ZIG_STAGE2_SOURCES...@@ -426,7 +426,7 @@ set(ZIG_STAGE2_SOURCES
426 "${CMAKE_SOURCE_DIR}/lib/std/os.zig"426 "${CMAKE_SOURCE_DIR}/lib/std/os.zig"
427 "${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"427 "${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"
428 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"428 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"
429 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno-generic.zig"429 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno/generic.zig"
430 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"430 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"
431 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"431 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"
432 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"432 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"
lib/std/Thread.zig+85-81
...@@ -9,9 +9,10 @@...@@ -9,9 +9,10 @@
9//! both evented I/O and async I/O, see the respective names in the top level std namespace.9//! both evented I/O and async I/O, see the respective names in the top level std namespace.
1010
11const std = @import("std.zig");11const std = @import("std.zig");
12const builtin = @import("builtin");
12const os = std.os;13const os = std.os;
13const assert = std.debug.assert;14const assert = std.debug.assert;
14const target = std.Target.current;15const target = builtin.target;
15const Atomic = std.atomic.Atomic;16const Atomic = std.atomic.Atomic;
1617
17pub const AutoResetEvent = @import("Thread/AutoResetEvent.zig");18pub const AutoResetEvent = @import("Thread/AutoResetEvent.zig");
...@@ -24,7 +25,8 @@ pub const Condition = @import("Thread/Condition.zig");...@@ -24,7 +25,8 @@ pub const Condition = @import("Thread/Condition.zig");
2425
25pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint");26pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint");
2627
27pub const use_pthreads = target.os.tag != .windows and std.Target.current.os.tag != .wasi and std.builtin.link_libc;28pub const use_pthreads = target.os.tag != .windows and target.os.tag != .wasi and builtin.link_libc;
29const is_gnu = target.abi.isGnu();
2830
29const Thread = @This();31const Thread = @This();
30const Impl = if (target.os.tag == .windows)32const Impl = if (target.os.tag == .windows)
...@@ -38,7 +40,7 @@ else...@@ -38,7 +40,7 @@ else
3840
39impl: Impl,41impl: Impl,
4042
41pub const max_name_len = switch (std.Target.current.os.tag) {43pub const max_name_len = switch (target.os.tag) {
42 .linux => 15,44 .linux => 15,
43 .windows => 31,45 .windows => 31,
44 .macos, .ios, .watchos, .tvos => 63,46 .macos, .ios, .watchos, .tvos => 63,
...@@ -64,20 +66,21 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {...@@ -64,20 +66,21 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
64 break :blk name_buf[0..name.len :0];66 break :blk name_buf[0..name.len :0];
65 };67 };
6668
67 switch (std.Target.current.os.tag) {69 switch (target.os.tag) {
68 .linux => if (use_pthreads) {70 .linux => if (use_pthreads) {
69 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);71 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
70 return switch (err) {72 switch (err) {
71 0 => {},73 .SUCCESS => return,
72 os.ERANGE => unreachable,74 .RANGE => unreachable,
73 else => return os.unexpectedErrno(err),75 else => |e| return os.unexpectedErrno(e),
74 };76 }
75 } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) {77 } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) {
78 // TODO: this is dead code. what did the author of this code intend to happen here?
76 const err = try os.prctl(.SET_NAME, .{@ptrToInt(name_with_terminator.ptr)});79 const err = try os.prctl(.SET_NAME, .{@ptrToInt(name_with_terminator.ptr)});
77 return switch (err) {80 switch (@intToEnum(os.E, err)) {
78 0 => {},81 .SUCCESS => return,
79 else => return os.unexpectedErrno(err),82 else => |e| return os.unexpectedErrno(e),
80 };83 }
81 } else {84 } else {
82 var buf: [32]u8 = undefined;85 var buf: [32]u8 = undefined;
83 const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});86 const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
...@@ -87,7 +90,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {...@@ -87,7 +90,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
8790
88 try file.writer().writeAll(name);91 try file.writer().writeAll(name);
89 },92 },
90 .windows => if (std.Target.current.os.isAtLeast(.windows, .win10_rs1)) |res| {93 .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| {
91 // SetThreadDescription is only available since version 1607, which is 10.0.14393.79594 // SetThreadDescription is only available since version 1607, which is 10.0.14393.795
92 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK95 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
93 if (!res) {96 if (!res) {
...@@ -110,24 +113,25 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {...@@ -110,24 +113,25 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
110 if (self.getHandle() != std.c.pthread_self()) return error.Unsupported;113 if (self.getHandle() != std.c.pthread_self()) return error.Unsupported;
111114
112 const err = std.c.pthread_setname_np(name_with_terminator.ptr);115 const err = std.c.pthread_setname_np(name_with_terminator.ptr);
113 return switch (err) {116 switch (err) {
114 0 => {},117 .SUCCESS => return,
115 else => return os.unexpectedErrno(err),118 else => |e| return os.unexpectedErrno(e),
116 };119 }
117 },120 },
118 .netbsd => if (use_pthreads) {121 .netbsd => if (use_pthreads) {
119 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null);122 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null);
120 return switch (err) {123 switch (err) {
121 0 => {},124 .SUCCESS => return,
122 os.EINVAL => unreachable,125 .INVAL => unreachable,
123 os.ESRCH => unreachable,126 .SRCH => unreachable,
124 os.ENOMEM => unreachable,127 .NOMEM => unreachable,
125 else => return os.unexpectedErrno(err),128 else => |e| return os.unexpectedErrno(e),
126 };129 }
127 },130 },
128 .freebsd, .openbsd => if (use_pthreads) {131 .freebsd, .openbsd => if (use_pthreads) {
129 // Use pthread_set_name_np for FreeBSD because pthread_setname_np is FreeBSD 12.2+ only.132 // Use pthread_set_name_np for FreeBSD because pthread_setname_np is FreeBSD 12.2+ only.
130 // TODO maybe revisit this if depending on FreeBSD 12.2+ is acceptable because pthread_setname_np can return an error.133 // TODO maybe revisit this if depending on FreeBSD 12.2+ is acceptable because
134 // pthread_setname_np can return an error.
131135
132 std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr);136 std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr);
133 },137 },
...@@ -151,20 +155,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co...@@ -151,20 +155,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
151 buffer_ptr[max_name_len] = 0;155 buffer_ptr[max_name_len] = 0;
152 var buffer = std.mem.span(buffer_ptr);156 var buffer = std.mem.span(buffer_ptr);
153157
154 switch (std.Target.current.os.tag) {158 switch (target.os.tag) {
155 .linux => if (use_pthreads and comptime std.Target.current.abi.isGnu()) {159 .linux => if (use_pthreads and is_gnu) {
156 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);160 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
157 return switch (err) {161 switch (err) {
158 0 => std.mem.sliceTo(buffer, 0),162 .SUCCESS => return std.mem.sliceTo(buffer, 0),
159 os.ERANGE => unreachable,163 .RANGE => unreachable,
160 else => return os.unexpectedErrno(err),164 else => |e| return os.unexpectedErrno(e),
161 };165 }
162 } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) {166 } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) {
163 const err = try os.prctl(.GET_NAME, .{@ptrToInt(buffer.ptr)});167 const err = try os.prctl(.GET_NAME, .{@ptrToInt(buffer.ptr)});
164 return switch (err) {168 switch (@intToEnum(os.E, err)) {
165 0 => std.mem.sliceTo(buffer, 0),169 .SUCCESS => return std.mem.sliceTo(buffer, 0),
166 else => return os.unexpectedErrno(err),170 else => |e| return os.unexpectedErrno(e),
167 };171 }
168 } else if (!use_pthreads) {172 } else if (!use_pthreads) {
169 var buf: [32]u8 = undefined;173 var buf: [32]u8 = undefined;
170 const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});174 const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
...@@ -179,7 +183,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co...@@ -179,7 +183,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
179 // musl doesn't provide pthread_getname_np and there's no way to retrieve the thread id of an arbitrary thread.183 // musl doesn't provide pthread_getname_np and there's no way to retrieve the thread id of an arbitrary thread.
180 return error.Unsupported;184 return error.Unsupported;
181 },185 },
182 .windows => if (std.Target.current.os.isAtLeast(.windows, .win10_rs1)) |res| {186 .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| {
183 // GetThreadDescription is only available since version 1607, which is 10.0.14393.795187 // GetThreadDescription is only available since version 1607, which is 10.0.14393.795
184 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK188 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
185 if (!res) {189 if (!res) {
...@@ -198,20 +202,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co...@@ -198,20 +202,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
198 },202 },
199 .macos, .ios, .watchos, .tvos => if (use_pthreads) {203 .macos, .ios, .watchos, .tvos => if (use_pthreads) {
200 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);204 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
201 return switch (err) {205 switch (err) {
202 0 => std.mem.sliceTo(buffer, 0),206 .SUCCESS => return std.mem.sliceTo(buffer, 0),
203 os.ESRCH => unreachable,207 .SRCH => unreachable,
204 else => return os.unexpectedErrno(err),208 else => |e| return os.unexpectedErrno(e),
205 };209 }
206 },210 },
207 .netbsd => if (use_pthreads) {211 .netbsd => if (use_pthreads) {
208 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);212 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
209 return switch (err) {213 switch (err) {
210 0 => std.mem.sliceTo(buffer, 0),214 .SUCCESS => return std.mem.sliceTo(buffer, 0),
211 os.EINVAL => unreachable,215 .INVAL => unreachable,
212 os.ESRCH => unreachable,216 .SRCH => unreachable,
213 else => return os.unexpectedErrno(err),217 else => |e| return os.unexpectedErrno(e),
214 };218 }
215 },219 },
216 .freebsd, .openbsd => if (use_pthreads) {220 .freebsd, .openbsd => if (use_pthreads) {
217 // Use pthread_get_name_np for FreeBSD because pthread_getname_np is FreeBSD 12.2+ only.221 // Use pthread_get_name_np for FreeBSD because pthread_getname_np is FreeBSD 12.2+ only.
...@@ -288,7 +292,7 @@ pub const SpawnError = error{...@@ -288,7 +292,7 @@ pub const SpawnError = error{
288/// The caller must eventually either call `join()` to wait for the thread to finish and free its resources292/// The caller must eventually either call `join()` to wait for the thread to finish and free its resources
289/// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`.293/// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`.
290pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread {294pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread {
291 if (std.builtin.single_threaded) {295 if (builtin.single_threaded) {
292 @compileError("Cannot spawn thread when building in single-threaded mode");296 @compileError("Cannot spawn thread when building in single-threaded mode");
293 }297 }
294298
...@@ -611,13 +615,13 @@ const PosixThreadImpl = struct {...@@ -611,13 +615,13 @@ const PosixThreadImpl = struct {
611 errdefer allocator.destroy(args_ptr);615 errdefer allocator.destroy(args_ptr);
612616
613 var attr: c.pthread_attr_t = undefined;617 var attr: c.pthread_attr_t = undefined;
614 if (c.pthread_attr_init(&attr) != 0) return error.SystemResources;618 if (c.pthread_attr_init(&attr) != .SUCCESS) return error.SystemResources;
615 defer assert(c.pthread_attr_destroy(&attr) == 0);619 defer assert(c.pthread_attr_destroy(&attr) == .SUCCESS);
616620
617 // Use the same set of parameters used by the libc-less impl.621 // Use the same set of parameters used by the libc-less impl.
618 const stack_size = std.math.max(config.stack_size, 16 * 1024);622 const stack_size = std.math.max(config.stack_size, 16 * 1024);
619 assert(c.pthread_attr_setstacksize(&attr, stack_size) == 0);623 assert(c.pthread_attr_setstacksize(&attr, stack_size) == .SUCCESS);
620 assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == 0);624 assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == .SUCCESS);
621625
622 var handle: c.pthread_t = undefined;626 var handle: c.pthread_t = undefined;
623 switch (c.pthread_create(627 switch (c.pthread_create(
...@@ -626,10 +630,10 @@ const PosixThreadImpl = struct {...@@ -626,10 +630,10 @@ const PosixThreadImpl = struct {
626 Instance.entryFn,630 Instance.entryFn,
627 if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined,631 if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined,
628 )) {632 )) {
629 0 => return Impl{ .handle = handle },633 .SUCCESS => return Impl{ .handle = handle },
630 os.EAGAIN => return error.SystemResources,634 .AGAIN => return error.SystemResources,
631 os.EPERM => unreachable,635 .PERM => unreachable,
632 os.EINVAL => unreachable,636 .INVAL => unreachable,
633 else => |err| return os.unexpectedErrno(err),637 else => |err| return os.unexpectedErrno(err),
634 }638 }
635 }639 }
...@@ -640,19 +644,19 @@ const PosixThreadImpl = struct {...@@ -640,19 +644,19 @@ const PosixThreadImpl = struct {
640644
641 fn detach(self: Impl) void {645 fn detach(self: Impl) void {
642 switch (c.pthread_detach(self.handle)) {646 switch (c.pthread_detach(self.handle)) {
643 0 => {},647 .SUCCESS => {},
644 os.EINVAL => unreachable, // thread handle is not joinable648 .INVAL => unreachable, // thread handle is not joinable
645 os.ESRCH => unreachable, // thread handle is invalid649 .SRCH => unreachable, // thread handle is invalid
646 else => unreachable,650 else => unreachable,
647 }651 }
648 }652 }
649653
650 fn join(self: Impl) void {654 fn join(self: Impl) void {
651 switch (c.pthread_join(self.handle, null)) {655 switch (c.pthread_join(self.handle, null)) {
652 0 => {},656 .SUCCESS => {},
653 os.EINVAL => unreachable, // thread handle is not joinable (or another thread is already joining in)657 .INVAL => unreachable, // thread handle is not joinable (or another thread is already joining in)
654 os.ESRCH => unreachable, // thread handle is invalid658 .SRCH => unreachable, // thread handle is invalid
655 os.EDEADLK => unreachable, // two threads tried to join each other659 .DEADLK => unreachable, // two threads tried to join each other
656 else => unreachable,660 else => unreachable,
657 }661 }
658 }662 }
...@@ -937,13 +941,13 @@ const LinuxThreadImpl = struct {...@@ -937,13 +941,13 @@ const LinuxThreadImpl = struct {
937 tls_ptr,941 tls_ptr,
938 &instance.thread.child_tid.value,942 &instance.thread.child_tid.value,
939 ))) {943 ))) {
940 0 => return Impl{ .thread = &instance.thread },944 .SUCCESS => return Impl{ .thread = &instance.thread },
941 os.EAGAIN => return error.ThreadQuotaExceeded,945 .AGAIN => return error.ThreadQuotaExceeded,
942 os.EINVAL => unreachable,946 .INVAL => unreachable,
943 os.ENOMEM => return error.SystemResources,947 .NOMEM => return error.SystemResources,
944 os.ENOSPC => unreachable,948 .NOSPC => unreachable,
945 os.EPERM => unreachable,949 .PERM => unreachable,
946 os.EUSERS => unreachable,950 .USERS => unreachable,
947 else => |err| return os.unexpectedErrno(err),951 else => |err| return os.unexpectedErrno(err),
948 }952 }
949 }953 }
...@@ -982,9 +986,9 @@ const LinuxThreadImpl = struct {...@@ -982,9 +986,9 @@ const LinuxThreadImpl = struct {
982 tid,986 tid,
983 null,987 null,
984 ))) {988 ))) {
985 0 => continue,989 .SUCCESS => continue,
986 os.EINTR => continue,990 .INTR => continue,
987 os.EAGAIN => continue,991 .AGAIN => continue,
988 else => unreachable,992 else => unreachable,
989 }993 }
990 }994 }
...@@ -1011,7 +1015,7 @@ fn testThreadName(thread: *Thread) !void {...@@ -1011,7 +1015,7 @@ fn testThreadName(thread: *Thread) !void {
1011}1015}
10121016
1013test "setName, getName" {1017test "setName, getName" {
1014 if (std.builtin.single_threaded) return error.SkipZigTest;1018 if (builtin.single_threaded) return error.SkipZigTest;
10151019
1016 const Context = struct {1020 const Context = struct {
1017 start_wait_event: ResetEvent = undefined,1021 start_wait_event: ResetEvent = undefined,
...@@ -1029,7 +1033,7 @@ test "setName, getName" {...@@ -1029,7 +1033,7 @@ test "setName, getName" {
1029 // Wait for the main thread to have set the thread field in the context.1033 // Wait for the main thread to have set the thread field in the context.
1030 ctx.start_wait_event.wait();1034 ctx.start_wait_event.wait();
10311035
1032 switch (std.Target.current.os.tag) {1036 switch (target.os.tag) {
1033 .windows => testThreadName(&ctx.thread) catch |err| switch (err) {1037 .windows => testThreadName(&ctx.thread) catch |err| switch (err) {
1034 error.Unsupported => return error.SkipZigTest,1038 error.Unsupported => return error.SkipZigTest,
1035 else => return err,1039 else => return err,
...@@ -1054,7 +1058,7 @@ test "setName, getName" {...@@ -1054,7 +1058,7 @@ test "setName, getName" {
1054 context.start_wait_event.set();1058 context.start_wait_event.set();
1055 context.test_done_event.wait();1059 context.test_done_event.wait();
10561060
1057 switch (std.Target.current.os.tag) {1061 switch (target.os.tag) {
1058 .macos, .ios, .watchos, .tvos => {1062 .macos, .ios, .watchos, .tvos => {
1059 const res = thread.setName("foobar");1063 const res = thread.setName("foobar");
1060 try std.testing.expectError(error.Unsupported, res);1064 try std.testing.expectError(error.Unsupported, res);
...@@ -1063,7 +1067,7 @@ test "setName, getName" {...@@ -1063,7 +1067,7 @@ test "setName, getName" {
1063 error.Unsupported => return error.SkipZigTest,1067 error.Unsupported => return error.SkipZigTest,
1064 else => return err,1068 else => return err,
1065 },1069 },
1066 else => |tag| if (tag == .linux and use_pthreads and comptime std.Target.current.abi.isMusl()) {1070 else => |tag| if (tag == .linux and use_pthreads and comptime target.abi.isMusl()) {
1067 try thread.setName("foobar");1071 try thread.setName("foobar");
10681072
1069 var name_buffer: [max_name_len:0]u8 = undefined;1073 var name_buffer: [max_name_len:0]u8 = undefined;
...@@ -1096,7 +1100,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {...@@ -1096,7 +1100,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {
1096}1100}
10971101
1098test "Thread.join" {1102test "Thread.join" {
1099 if (std.builtin.single_threaded) return error.SkipZigTest;1103 if (builtin.single_threaded) return error.SkipZigTest;
11001104
1101 var value: usize = 0;1105 var value: usize = 0;
1102 var event: ResetEvent = undefined;1106 var event: ResetEvent = undefined;
...@@ -1110,7 +1114,7 @@ test "Thread.join" {...@@ -1110,7 +1114,7 @@ test "Thread.join" {
1110}1114}
11111115
1112test "Thread.detach" {1116test "Thread.detach" {
1113 if (std.builtin.single_threaded) return error.SkipZigTest;1117 if (builtin.single_threaded) return error.SkipZigTest;
11141118
1115 var value: usize = 0;1119 var value: usize = 0;
1116 var event: ResetEvent = undefined;1120 var event: ResetEvent = undefined;
lib/std/Thread/Condition.zig+8-8
...@@ -81,17 +81,17 @@ pub const PthreadCondition = struct {...@@ -81,17 +81,17 @@ pub const PthreadCondition = struct {
8181
82 pub fn wait(cond: *PthreadCondition, mutex: *Mutex) void {82 pub fn wait(cond: *PthreadCondition, mutex: *Mutex) void {
83 const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.impl.pthread_mutex);83 const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.impl.pthread_mutex);
84 assert(rc == 0);84 assert(rc == .SUCCESS);
85 }85 }
8686
87 pub fn signal(cond: *PthreadCondition) void {87 pub fn signal(cond: *PthreadCondition) void {
88 const rc = std.c.pthread_cond_signal(&cond.cond);88 const rc = std.c.pthread_cond_signal(&cond.cond);
89 assert(rc == 0);89 assert(rc == .SUCCESS);
90 }90 }
9191
92 pub fn broadcast(cond: *PthreadCondition) void {92 pub fn broadcast(cond: *PthreadCondition) void {
93 const rc = std.c.pthread_cond_broadcast(&cond.cond);93 const rc = std.c.pthread_cond_broadcast(&cond.cond);
94 assert(rc == 0);94 assert(rc == .SUCCESS);
95 }95 }
96};96};
9797
...@@ -115,9 +115,9 @@ pub const AtomicCondition = struct {...@@ -115,9 +115,9 @@ pub const AtomicCondition = struct {
115 0,115 0,
116 null,116 null,
117 ))) {117 ))) {
118 0 => {},118 .SUCCESS => {},
119 std.os.EINTR => {},119 .INTR => {},
120 std.os.EAGAIN => {},120 .AGAIN => {},
121 else => unreachable,121 else => unreachable,
122 }122 }
123 },123 },
...@@ -136,8 +136,8 @@ pub const AtomicCondition = struct {...@@ -136,8 +136,8 @@ pub const AtomicCondition = struct {
136 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,136 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
137 1,137 1,
138 ))) {138 ))) {
139 0 => {},139 .SUCCESS => {},
140 std.os.EFAULT => {},140 .FAULT => {},
141 else => unreachable,141 else => unreachable,
142 }142 }
143 },143 },
lib/std/Thread/Futex.zig+39-39
...@@ -152,12 +152,12 @@ const LinuxFutex = struct {...@@ -152,12 +152,12 @@ const LinuxFutex = struct {
152 @bitCast(i32, expect),152 @bitCast(i32, expect),
153 ts_ptr,153 ts_ptr,
154 ))) {154 ))) {
155 0 => {}, // notified by `wake()`155 .SUCCESS => {}, // notified by `wake()`
156 std.os.EINTR => {}, // spurious wakeup156 .INTR => {}, // spurious wakeup
157 std.os.EAGAIN => {}, // ptr.* != expect157 .AGAIN => {}, // ptr.* != expect
158 std.os.ETIMEDOUT => return error.TimedOut,158 .TIMEDOUT => return error.TimedOut,
159 std.os.EINVAL => {}, // possibly timeout overflow159 .INVAL => {}, // possibly timeout overflow
160 std.os.EFAULT => unreachable,160 .FAULT => unreachable,
161 else => unreachable,161 else => unreachable,
162 }162 }
163 }163 }
...@@ -168,9 +168,9 @@ const LinuxFutex = struct {...@@ -168,9 +168,9 @@ const LinuxFutex = struct {
168 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,168 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
169 std.math.cast(i32, num_waiters) catch std.math.maxInt(i32),169 std.math.cast(i32, num_waiters) catch std.math.maxInt(i32),
170 ))) {170 ))) {
171 0 => {}, // successful wake up171 .SUCCESS => {}, // successful wake up
172 std.os.EINVAL => {}, // invalid futex_wait() on ptr done elsewhere172 .INVAL => {}, // invalid futex_wait() on ptr done elsewhere
173 std.os.EFAULT => {}, // pointer became invalid while doing the wake173 .FAULT => {}, // pointer became invalid while doing the wake
174 else => unreachable,174 else => unreachable,
175 }175 }
176 }176 }
...@@ -215,13 +215,13 @@ const DarwinFutex = struct {...@@ -215,13 +215,13 @@ const DarwinFutex = struct {
215 };215 };
216216
217 if (status >= 0) return;217 if (status >= 0) return;
218 switch (-status) {218 switch (@intToEnum(std.os.E, -status)) {
219 darwin.EINTR => {},219 .INTR => {},
220 // Address of the futex is paged out. This is unlikely, but possible in theory, and220 // Address of the futex is paged out. This is unlikely, but possible in theory, and
221 // pthread/libdispatch on darwin bother to handle it. In this case we'll return221 // pthread/libdispatch on darwin bother to handle it. In this case we'll return
222 // without waiting, but the caller should retry anyway.222 // without waiting, but the caller should retry anyway.
223 darwin.EFAULT => {},223 .FAULT => {},
224 darwin.ETIMEDOUT => if (!timeout_overflowed) return error.TimedOut,224 .TIMEDOUT => if (!timeout_overflowed) return error.TimedOut,
225 else => unreachable,225 else => unreachable,
226 }226 }
227 }227 }
...@@ -237,11 +237,11 @@ const DarwinFutex = struct {...@@ -237,11 +237,11 @@ const DarwinFutex = struct {
237 const status = darwin.__ulock_wake(flags, addr, 0);237 const status = darwin.__ulock_wake(flags, addr, 0);
238238
239 if (status >= 0) return;239 if (status >= 0) return;
240 switch (-status) {240 switch (@intToEnum(std.os.E, -status)) {
241 darwin.EINTR => continue, // spurious wake()241 .INTR => continue, // spurious wake()
242 darwin.EFAULT => continue, // address of the lock was paged out242 .FAULT => continue, // address of the lock was paged out
243 darwin.ENOENT => return, // nothing was woken up243 .NOENT => return, // nothing was woken up
244 darwin.EALREADY => unreachable, // only for ULF_WAKE_THREAD244 .ALREADY => unreachable, // only for ULF_WAKE_THREAD
245 else => unreachable,245 else => unreachable,
246 }246 }
247 }247 }
...@@ -255,8 +255,8 @@ const PosixFutex = struct {...@@ -255,8 +255,8 @@ const PosixFutex = struct {
255 var waiter: List.Node = undefined;255 var waiter: List.Node = undefined;
256256
257 {257 {
258 assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);258 assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
259 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);259 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
260260
261 if (ptr.load(.SeqCst) != expect) {261 if (ptr.load(.SeqCst) != expect) {
262 return;262 return;
...@@ -272,8 +272,8 @@ const PosixFutex = struct {...@@ -272,8 +272,8 @@ const PosixFutex = struct {
272 waiter.data.wait(null) catch unreachable;272 waiter.data.wait(null) catch unreachable;
273 };273 };
274274
275 assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);275 assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
276 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);276 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
277277
278 if (waiter.data.address == address) {278 if (waiter.data.address == address) {
279 timed_out = true;279 timed_out = true;
...@@ -297,8 +297,8 @@ const PosixFutex = struct {...@@ -297,8 +297,8 @@ const PosixFutex = struct {
297 waiter.data.notify();297 waiter.data.notify();
298 };298 };
299299
300 assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);300 assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
301 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);301 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
302302
303 var waiters = bucket.list.first;303 var waiters = bucket.list.first;
304 while (waiters) |waiter| {304 while (waiters) |waiter| {
...@@ -340,16 +340,13 @@ const PosixFutex = struct {...@@ -340,16 +340,13 @@ const PosixFutex = struct {
340 };340 };
341341
342 fn deinit(self: *Self) void {342 fn deinit(self: *Self) void {
343 const rc = std.c.pthread_cond_destroy(&self.cond);343 _ = std.c.pthread_cond_destroy(&self.cond);
344 assert(rc == 0 or rc == std.os.EINVAL);344 _ = std.c.pthread_mutex_destroy(&self.mutex);
345
346 const rm = std.c.pthread_mutex_destroy(&self.mutex);
347 assert(rm == 0 or rm == std.os.EINVAL);
348 }345 }
349346
350 fn wait(self: *Self, timeout: ?u64) error{TimedOut}!void {347 fn wait(self: *Self, timeout: ?u64) error{TimedOut}!void {
351 assert(std.c.pthread_mutex_lock(&self.mutex) == 0);348 assert(std.c.pthread_mutex_lock(&self.mutex) == .SUCCESS);
352 defer assert(std.c.pthread_mutex_unlock(&self.mutex) == 0);349 defer assert(std.c.pthread_mutex_unlock(&self.mutex) == .SUCCESS);
353350
354 switch (self.state) {351 switch (self.state) {
355 .empty => self.state = .waiting,352 .empty => self.state = .waiting,
...@@ -378,28 +375,31 @@ const PosixFutex = struct {...@@ -378,28 +375,31 @@ const PosixFutex = struct {
378 }375 }
379376
380 const ts_ref = ts_ptr orelse {377 const ts_ref = ts_ptr orelse {
381 assert(std.c.pthread_cond_wait(&self.cond, &self.mutex) == 0);378 assert(std.c.pthread_cond_wait(&self.cond, &self.mutex) == .SUCCESS);
382 continue;379 continue;
383 };380 };
384381
385 const rc = std.c.pthread_cond_timedwait(&self.cond, &self.mutex, ts_ref);382 const rc = std.c.pthread_cond_timedwait(&self.cond, &self.mutex, ts_ref);
386 assert(rc == 0 or rc == std.os.ETIMEDOUT);383 switch (rc) {
387 if (rc == std.os.ETIMEDOUT) {384 .SUCCESS => {},
388 self.state = .empty;385 .TIMEDOUT => {
389 return error.TimedOut;386 self.state = .empty;
387 return error.TimedOut;
388 },
389 else => unreachable,
390 }390 }
391 }391 }
392 }392 }
393393
394 fn notify(self: *Self) void {394 fn notify(self: *Self) void {
395 assert(std.c.pthread_mutex_lock(&self.mutex) == 0);395 assert(std.c.pthread_mutex_lock(&self.mutex) == .SUCCESS);
396 defer assert(std.c.pthread_mutex_unlock(&self.mutex) == 0);396 defer assert(std.c.pthread_mutex_unlock(&self.mutex) == .SUCCESS);
397397
398 switch (self.state) {398 switch (self.state) {
399 .empty => self.state = .notified,399 .empty => self.state = .notified,
400 .waiting => {400 .waiting => {
401 self.state = .notified;401 self.state = .notified;
402 assert(std.c.pthread_cond_signal(&self.cond) == 0);402 assert(std.c.pthread_cond_signal(&self.cond) == .SUCCESS);
403 },403 },
404 .notified => unreachable,404 .notified => unreachable,
405 }405 }
lib/std/Thread/Mutex.zig+16-16
...@@ -143,9 +143,9 @@ pub const AtomicMutex = struct {...@@ -143,9 +143,9 @@ pub const AtomicMutex = struct {
143 @enumToInt(new_state),143 @enumToInt(new_state),
144 null,144 null,
145 ))) {145 ))) {
146 0 => {},146 .SUCCESS => {},
147 std.os.EINTR => {},147 .INTR => {},
148 std.os.EAGAIN => {},148 .AGAIN => {},
149 else => unreachable,149 else => unreachable,
150 }150 }
151 },151 },
...@@ -164,8 +164,8 @@ pub const AtomicMutex = struct {...@@ -164,8 +164,8 @@ pub const AtomicMutex = struct {
164 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,164 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
165 1,165 1,
166 ))) {166 ))) {
167 0 => {},167 .SUCCESS => {},
168 std.os.EFAULT => {},168 .FAULT => unreachable, // invalid pointer passed to futex_wake
169 else => unreachable,169 else => unreachable,
170 }170 }
171 },171 },
...@@ -182,10 +182,10 @@ pub const PthreadMutex = struct {...@@ -182,10 +182,10 @@ pub const PthreadMutex = struct {
182182
183 pub fn release(held: Held) void {183 pub fn release(held: Held) void {
184 switch (std.c.pthread_mutex_unlock(&held.mutex.pthread_mutex)) {184 switch (std.c.pthread_mutex_unlock(&held.mutex.pthread_mutex)) {
185 0 => return,185 .SUCCESS => return,
186 std.c.EINVAL => unreachable,186 .INVAL => unreachable,
187 std.c.EAGAIN => unreachable,187 .AGAIN => unreachable,
188 std.c.EPERM => unreachable,188 .PERM => unreachable,
189 else => unreachable,189 else => unreachable,
190 }190 }
191 }191 }
...@@ -195,7 +195,7 @@ pub const PthreadMutex = struct {...@@ -195,7 +195,7 @@ pub const PthreadMutex = struct {
195 /// the mutex is unavailable. Otherwise returns Held. Call195 /// the mutex is unavailable. Otherwise returns Held. Call
196 /// release on Held.196 /// release on Held.
197 pub fn tryAcquire(m: *PthreadMutex) ?Held {197 pub fn tryAcquire(m: *PthreadMutex) ?Held {
198 if (std.c.pthread_mutex_trylock(&m.pthread_mutex) == 0) {198 if (std.c.pthread_mutex_trylock(&m.pthread_mutex) == .SUCCESS) {
199 return Held{ .mutex = m };199 return Held{ .mutex = m };
200 } else {200 } else {
201 return null;201 return null;
...@@ -206,12 +206,12 @@ pub const PthreadMutex = struct {...@@ -206,12 +206,12 @@ pub const PthreadMutex = struct {
206 /// held by the calling thread.206 /// held by the calling thread.
207 pub fn acquire(m: *PthreadMutex) Held {207 pub fn acquire(m: *PthreadMutex) Held {
208 switch (std.c.pthread_mutex_lock(&m.pthread_mutex)) {208 switch (std.c.pthread_mutex_lock(&m.pthread_mutex)) {
209 0 => return Held{ .mutex = m },209 .SUCCESS => return Held{ .mutex = m },
210 std.c.EINVAL => unreachable,210 .INVAL => unreachable,
211 std.c.EBUSY => unreachable,211 .BUSY => unreachable,
212 std.c.EAGAIN => unreachable,212 .AGAIN => unreachable,
213 std.c.EDEADLK => unreachable,213 .DEADLK => unreachable,
214 std.c.EPERM => unreachable,214 .PERM => unreachable,
215 else => unreachable,215 else => unreachable,
216 }216 }
217 }217 }
lib/std/Thread/ResetEvent.zig+12-12
...@@ -130,7 +130,7 @@ pub const PosixEvent = struct {...@@ -130,7 +130,7 @@ pub const PosixEvent = struct {
130130
131 pub fn init(ev: *PosixEvent) !void {131 pub fn init(ev: *PosixEvent) !void {
132 switch (c.getErrno(c.sem_init(&ev.sem, 0, 0))) {132 switch (c.getErrno(c.sem_init(&ev.sem, 0, 0))) {
133 0 => return,133 .SUCCESS => return,
134 else => return error.SystemResources,134 else => return error.SystemResources,
135 }135 }
136 }136 }
...@@ -147,9 +147,9 @@ pub const PosixEvent = struct {...@@ -147,9 +147,9 @@ pub const PosixEvent = struct {
147 pub fn wait(ev: *PosixEvent) void {147 pub fn wait(ev: *PosixEvent) void {
148 while (true) {148 while (true) {
149 switch (c.getErrno(c.sem_wait(&ev.sem))) {149 switch (c.getErrno(c.sem_wait(&ev.sem))) {
150 0 => return,150 .SUCCESS => return,
151 c.EINTR => continue,151 .INTR => continue,
152 c.EINVAL => unreachable,152 .INVAL => unreachable,
153 else => unreachable,153 else => unreachable,
154 }154 }
155 }155 }
...@@ -165,10 +165,10 @@ pub const PosixEvent = struct {...@@ -165,10 +165,10 @@ pub const PosixEvent = struct {
165 ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.ns_per_s));165 ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.ns_per_s));
166 while (true) {166 while (true) {
167 switch (c.getErrno(c.sem_timedwait(&ev.sem, &ts))) {167 switch (c.getErrno(c.sem_timedwait(&ev.sem, &ts))) {
168 0 => return .event_set,168 .SUCCESS => return .event_set,
169 c.EINTR => continue,169 .INTR => continue,
170 c.EINVAL => unreachable,170 .INVAL => unreachable,
171 c.ETIMEDOUT => return .timed_out,171 .TIMEDOUT => return .timed_out,
172 else => unreachable,172 else => unreachable,
173 }173 }
174 }174 }
...@@ -177,10 +177,10 @@ pub const PosixEvent = struct {...@@ -177,10 +177,10 @@ pub const PosixEvent = struct {
177 pub fn reset(ev: *PosixEvent) void {177 pub fn reset(ev: *PosixEvent) void {
178 while (true) {178 while (true) {
179 switch (c.getErrno(c.sem_trywait(&ev.sem))) {179 switch (c.getErrno(c.sem_trywait(&ev.sem))) {
180 0 => continue, // Need to make it go to zero.180 .SUCCESS => continue, // Need to make it go to zero.
181 c.EINTR => continue,181 .INTR => continue,
182 c.EINVAL => unreachable,182 .INVAL => unreachable,
183 c.EAGAIN => return, // The semaphore currently has the value zero.183 .AGAIN => return, // The semaphore currently has the value zero.
184 else => unreachable,184 else => unreachable,
185 }185 }
186 }186 }
lib/std/Thread/RwLock.zig+11-13
...@@ -13,7 +13,7 @@ impl: Impl,...@@ -13,7 +13,7 @@ impl: Impl,
1313
14const RwLock = @This();14const RwLock = @This();
15const std = @import("../std.zig");15const std = @import("../std.zig");
16const builtin = std.builtin;16const builtin = @import("builtin");
17const assert = std.debug.assert;17const assert = std.debug.assert;
18const Mutex = std.Thread.Mutex;18const Mutex = std.Thread.Mutex;
19const Semaphore = std.Semaphore;19const Semaphore = std.Semaphore;
...@@ -165,43 +165,41 @@ pub const PthreadRwLock = struct {...@@ -165,43 +165,41 @@ pub const PthreadRwLock = struct {
165 }165 }
166166
167 pub fn deinit(rwl: *PthreadRwLock) void {167 pub fn deinit(rwl: *PthreadRwLock) void {
168 const safe_rc = switch (std.builtin.os.tag) {168 const safe_rc: std.os.E = switch (builtin.os.tag) {
169 .dragonfly, .netbsd => std.os.EAGAIN,169 .dragonfly, .netbsd => .AGAIN,
170 else => 0,170 else => .SUCCESS,
171 };171 };
172
173 const rc = std.c.pthread_rwlock_destroy(&rwl.rwlock);172 const rc = std.c.pthread_rwlock_destroy(&rwl.rwlock);
174 assert(rc == 0 or rc == safe_rc);173 assert(rc == .SUCCESS or rc == safe_rc);
175
176 rwl.* = undefined;174 rwl.* = undefined;
177 }175 }
178176
179 pub fn tryLock(rwl: *PthreadRwLock) bool {177 pub fn tryLock(rwl: *PthreadRwLock) bool {
180 return pthread_rwlock_trywrlock(&rwl.rwlock) == 0;178 return pthread_rwlock_trywrlock(&rwl.rwlock) == .SUCCESS;
181 }179 }
182180
183 pub fn lock(rwl: *PthreadRwLock) void {181 pub fn lock(rwl: *PthreadRwLock) void {
184 const rc = pthread_rwlock_wrlock(&rwl.rwlock);182 const rc = pthread_rwlock_wrlock(&rwl.rwlock);
185 assert(rc == 0);183 assert(rc == .SUCCESS);
186 }184 }
187185
188 pub fn unlock(rwl: *PthreadRwLock) void {186 pub fn unlock(rwl: *PthreadRwLock) void {
189 const rc = pthread_rwlock_unlock(&rwl.rwlock);187 const rc = pthread_rwlock_unlock(&rwl.rwlock);
190 assert(rc == 0);188 assert(rc == .SUCCESS);
191 }189 }
192190
193 pub fn tryLockShared(rwl: *PthreadRwLock) bool {191 pub fn tryLockShared(rwl: *PthreadRwLock) bool {
194 return pthread_rwlock_tryrdlock(&rwl.rwlock) == 0;192 return pthread_rwlock_tryrdlock(&rwl.rwlock) == .SUCCESS;
195 }193 }
196194
197 pub fn lockShared(rwl: *PthreadRwLock) void {195 pub fn lockShared(rwl: *PthreadRwLock) void {
198 const rc = pthread_rwlock_rdlock(&rwl.rwlock);196 const rc = pthread_rwlock_rdlock(&rwl.rwlock);
199 assert(rc == 0);197 assert(rc == .SUCCESS);
200 }198 }
201199
202 pub fn unlockShared(rwl: *PthreadRwLock) void {200 pub fn unlockShared(rwl: *PthreadRwLock) void {
203 const rc = pthread_rwlock_unlock(&rwl.rwlock);201 const rc = pthread_rwlock_unlock(&rwl.rwlock);
204 assert(rc == 0);202 assert(rc == .SUCCESS);
205 }203 }
206};204};
207205
lib/std/Thread/StaticResetEvent.zig+5-5
...@@ -201,7 +201,7 @@ pub const AtomicEvent = struct {...@@ -201,7 +201,7 @@ pub const AtomicEvent = struct {
201 const waiting = std.math.maxInt(i32); // wake_count201 const waiting = std.math.maxInt(i32); // wake_count
202 const ptr = @ptrCast(*const i32, waiters);202 const ptr = @ptrCast(*const i32, waiters);
203 const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting);203 const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting);
204 assert(linux.getErrno(rc) == 0);204 assert(linux.getErrno(rc) == .SUCCESS);
205 }205 }
206206
207 fn wait(waiters: *u32, timeout: ?u64) !void {207 fn wait(waiters: *u32, timeout: ?u64) !void {
...@@ -221,10 +221,10 @@ pub const AtomicEvent = struct {...@@ -221,10 +221,10 @@ pub const AtomicEvent = struct {
221 const ptr = @ptrCast(*const i32, waiters);221 const ptr = @ptrCast(*const i32, waiters);
222 const rc = linux.futex_wait(ptr, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, expected, ts_ptr);222 const rc = linux.futex_wait(ptr, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, expected, ts_ptr);
223 switch (linux.getErrno(rc)) {223 switch (linux.getErrno(rc)) {
224 0 => continue,224 .SUCCESS => continue,
225 os.ETIMEDOUT => return error.TimedOut,225 .TIMEDOUT => return error.TimedOut,
226 os.EINTR => continue,226 .INTR => continue,
227 os.EAGAIN => return,227 .AGAIN => return,
228 else => unreachable,228 else => unreachable,
229 }229 }
230 }230 }
lib/std/c.zig+29-29
...@@ -35,11 +35,11 @@ pub usingnamespace switch (std.Target.current.os.tag) {...@@ -35,11 +35,11 @@ pub usingnamespace switch (std.Target.current.os.tag) {
35 else => struct {},35 else => struct {},
36};36};
3737
38pub fn getErrno(rc: anytype) c_int {38pub fn getErrno(rc: anytype) E {
39 if (rc == -1) {39 if (rc == -1) {
40 return _errno().*;40 return @intToEnum(E, _errno().*);
41 } else {41 } else {
42 return 0;42 return .SUCCESS;
43 }43 }
44}44}
4545
...@@ -270,22 +270,22 @@ pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;...@@ -270,22 +270,22 @@ pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
270pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;270pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
271pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;271pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
272272
273pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) c_int;273pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) E;
274pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int;274pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E;
275pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;275pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) E;
276pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) c_int;276pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) E;
277pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;277pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) E;
278pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;278pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) E;
279pub extern "c" fn pthread_self() pthread_t;279pub extern "c" fn pthread_self() pthread_t;
280pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;280pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) E;
281pub extern "c" fn pthread_detach(thread: pthread_t) c_int;281pub extern "c" fn pthread_detach(thread: pthread_t) E;
282pub extern "c" fn pthread_atfork(282pub extern "c" fn pthread_atfork(
283 prepare: ?fn () callconv(.C) void,283 prepare: ?fn () callconv(.C) void,
284 parent: ?fn () callconv(.C) void,284 parent: ?fn () callconv(.C) void,
285 child: ?fn () callconv(.C) void,285 child: ?fn () callconv(.C) void,
286) c_int;286) c_int;
287pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) c_int;287pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) E;
288pub extern "c" fn pthread_key_delete(key: pthread_key_t) c_int;288pub extern "c" fn pthread_key_delete(key: pthread_key_t) E;
289pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*c_void;289pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*c_void;
290pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*c_void) c_int;290pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*c_void) c_int;
291pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int;291pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int;
...@@ -339,24 +339,24 @@ pub extern "c" fn dn_expand(...@@ -339,24 +339,24 @@ pub extern "c" fn dn_expand(
339) c_int;339) c_int;
340340
341pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};341pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
342pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;342pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) E;
343pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;343pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) E;
344pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c_int;344pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) E;
345pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c_int;345pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) E;
346346
347pub const PTHREAD_COND_INITIALIZER = pthread_cond_t{};347pub const PTHREAD_COND_INITIALIZER = pthread_cond_t{};
348pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c_int;348pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) E;
349pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) c_int;349pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) E;
350pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c_int;350pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
351pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int;351pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
352pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c_int;352pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;
353353
354pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) c_int;354pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E;
355pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;355pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
356pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;356pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
357pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;357pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
358pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;358pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
359pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;359pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E;
360360
361pub const pthread_t = *opaque {};361pub const pthread_t = *opaque {};
362pub const FILE = opaque {};362pub const FILE = opaque {};
lib/std/c/darwin.zig+2-2
...@@ -193,8 +193,8 @@ pub const pthread_attr_t = extern struct {...@@ -193,8 +193,8 @@ pub const pthread_attr_t = extern struct {
193193
194const pthread_t = std.c.pthread_t;194const pthread_t = std.c.pthread_t;
195pub extern "c" fn pthread_threadid_np(thread: ?pthread_t, thread_id: *u64) c_int;195pub extern "c" fn pthread_threadid_np(thread: ?pthread_t, thread_id: *u64) c_int;
196pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;196pub extern "c" fn pthread_setname_np(name: [*:0]const u8) E;
197pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;197pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
198198
199pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;199pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
200200
lib/std/c/linux.zig+2-2
...@@ -186,8 +186,8 @@ const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {...@@ -186,8 +186,8 @@ const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {
186};186};
187const __SIZEOF_SEM_T = 4 * @sizeOf(usize);187const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
188188
189pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;189pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
190pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;190pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
191191
192pub const RTLD_LAZY = 1;192pub const RTLD_LAZY = 1;
193pub const RTLD_NOW = 2;193pub const RTLD_NOW = 2;
lib/std/c/netbsd.zig+2-2
...@@ -95,5 +95,5 @@ pub const pthread_attr_t = extern struct {...@@ -95,5 +95,5 @@ pub const pthread_attr_t = extern struct {
9595
96pub const sem_t = ?*opaque {};96pub const sem_t = ?*opaque {};
9797
98pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) c_int;98pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) E;
99pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;99pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
lib/std/fs.zig+28-28
...@@ -339,10 +339,10 @@ pub const Dir = struct {...@@ -339,10 +339,10 @@ pub const Dir = struct {
339 if (rc == 0) return null;339 if (rc == 0) return null;
340 if (rc < 0) {340 if (rc < 0) {
341 switch (os.errno(rc)) {341 switch (os.errno(rc)) {
342 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability342 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
343 os.EFAULT => unreachable,343 .FAULT => unreachable,
344 os.ENOTDIR => unreachable,344 .NOTDIR => unreachable,
345 os.EINVAL => unreachable,345 .INVAL => unreachable,
346 else => |err| return os.unexpectedErrno(err),346 else => |err| return os.unexpectedErrno(err),
347 }347 }
348 }348 }
...@@ -385,11 +385,11 @@ pub const Dir = struct {...@@ -385,11 +385,11 @@ pub const Dir = struct {
385 else385 else
386 os.system.getdents(self.dir.fd, &self.buf, self.buf.len);386 os.system.getdents(self.dir.fd, &self.buf, self.buf.len);
387 switch (os.errno(rc)) {387 switch (os.errno(rc)) {
388 0 => {},388 .SUCCESS => {},
389 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability389 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
390 os.EFAULT => unreachable,390 .FAULT => unreachable,
391 os.ENOTDIR => unreachable,391 .NOTDIR => unreachable,
392 os.EINVAL => unreachable,392 .INVAL => unreachable,
393 else => |err| return os.unexpectedErrno(err),393 else => |err| return os.unexpectedErrno(err),
394 }394 }
395 if (rc == 0) return null;395 if (rc == 0) return null;
...@@ -457,10 +457,10 @@ pub const Dir = struct {...@@ -457,10 +457,10 @@ pub const Dir = struct {
457 if (rc == 0) return null;457 if (rc == 0) return null;
458 if (rc < 0) {458 if (rc < 0) {
459 switch (os.errno(rc)) {459 switch (os.errno(rc)) {
460 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability460 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
461 os.EFAULT => unreachable,461 .FAULT => unreachable,
462 os.ENOTDIR => unreachable,462 .NOTDIR => unreachable,
463 os.EINVAL => unreachable,463 .INVAL => unreachable,
464 else => |err| return os.unexpectedErrno(err),464 else => |err| return os.unexpectedErrno(err),
465 }465 }
466 }466 }
...@@ -522,11 +522,11 @@ pub const Dir = struct {...@@ -522,11 +522,11 @@ pub const Dir = struct {
522 if (self.index >= self.end_index) {522 if (self.index >= self.end_index) {
523 const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len);523 const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
524 switch (os.linux.getErrno(rc)) {524 switch (os.linux.getErrno(rc)) {
525 0 => {},525 .SUCCESS => {},
526 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability526 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
527 os.EFAULT => unreachable,527 .FAULT => unreachable,
528 os.ENOTDIR => unreachable,528 .NOTDIR => unreachable,
529 os.EINVAL => unreachable,529 .INVAL => unreachable,
530 else => |err| return os.unexpectedErrno(err),530 else => |err| return os.unexpectedErrno(err),
531 }531 }
532 if (rc == 0) return null;532 if (rc == 0) return null;
...@@ -655,12 +655,12 @@ pub const Dir = struct {...@@ -655,12 +655,12 @@ pub const Dir = struct {
655 if (self.index >= self.end_index) {655 if (self.index >= self.end_index) {
656 var bufused: usize = undefined;656 var bufused: usize = undefined;
657 switch (w.fd_readdir(self.dir.fd, &self.buf, self.buf.len, self.cookie, &bufused)) {657 switch (w.fd_readdir(self.dir.fd, &self.buf, self.buf.len, self.cookie, &bufused)) {
658 w.ESUCCESS => {},658 .SUCCESS => {},
659 w.EBADF => unreachable, // Dir is invalid or was opened without iteration ability659 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
660 w.EFAULT => unreachable,660 .FAULT => unreachable,
661 w.ENOTDIR => unreachable,661 .NOTDIR => unreachable,
662 w.EINVAL => unreachable,662 .INVAL => unreachable,
663 w.ENOTCAPABLE => return error.AccessDenied,663 .NOTCAPABLE => return error.AccessDenied,
664 else => |err| return os.unexpectedErrno(err),664 else => |err| return os.unexpectedErrno(err),
665 }665 }
666 if (bufused == 0) return null;666 if (bufused == 0) return null;
...@@ -2557,12 +2557,12 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {...@@ -2557,12 +2557,12 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {
2557 if (comptime std.Target.current.isDarwin()) {2557 if (comptime std.Target.current.isDarwin()) {
2558 const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);2558 const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);
2559 switch (os.errno(rc)) {2559 switch (os.errno(rc)) {
2560 0 => return,2560 .SUCCESS => return,
2561 os.EINVAL => unreachable,2561 .INVAL => unreachable,
2562 os.ENOMEM => return error.SystemResources,2562 .NOMEM => return error.SystemResources,
2563 // The source file is not a directory, symbolic link, or regular file.2563 // The source file is not a directory, symbolic link, or regular file.
2564 // Try with the fallback path before giving up.2564 // Try with the fallback path before giving up.
2565 os.ENOTSUP => {},2565 .OPNOTSUPP => {},
2566 else => |err| return os.unexpectedErrno(err),2566 else => |err| return os.unexpectedErrno(err),
2567 }2567 }
2568 }2568 }
lib/std/fs/wasi.zig+4-4
...@@ -121,13 +121,13 @@ pub const PreopenList = struct {...@@ -121,13 +121,13 @@ pub const PreopenList = struct {
121 while (true) {121 while (true) {
122 var buf: prestat_t = undefined;122 var buf: prestat_t = undefined;
123 switch (fd_prestat_get(fd, &buf)) {123 switch (fd_prestat_get(fd, &buf)) {
124 ESUCCESS => {},124 .SUCCESS => {},
125 ENOTSUP => {125 .OPNOTSUPP => {
126 // not a preopen, so keep going126 // not a preopen, so keep going
127 fd = try math.add(fd_t, fd, 1);127 fd = try math.add(fd_t, fd, 1);
128 continue;128 continue;
129 },129 },
130 EBADF => {130 .BADF => {
131 // OK, no more fds available131 // OK, no more fds available
132 break;132 break;
133 },133 },
...@@ -137,7 +137,7 @@ pub const PreopenList = struct {...@@ -137,7 +137,7 @@ pub const PreopenList = struct {
137 const path_buf = try self.buffer.allocator.alloc(u8, preopen_len);137 const path_buf = try self.buffer.allocator.alloc(u8, preopen_len);
138 mem.set(u8, path_buf, 0);138 mem.set(u8, path_buf, 0);
139 switch (fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) {139 switch (fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) {
140 ESUCCESS => {},140 .SUCCESS => {},
141 else => |err| return os.unexpectedErrno(err),141 else => |err| return os.unexpectedErrno(err),
142 }142 }
143 const preopen = Preopen.new(fd, PreopenType{ .Dir = path_buf });143 const preopen = Preopen.new(fd, PreopenType{ .Dir = path_buf });
lib/std/io/c_writer.zig+13-13
...@@ -17,19 +17,19 @@ pub fn cWriter(c_file: *std.c.FILE) CWriter {...@@ -17,19 +17,19 @@ pub fn cWriter(c_file: *std.c.FILE) CWriter {
17fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {17fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {
18 const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);18 const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);
19 if (amt_written >= 0) return amt_written;19 if (amt_written >= 0) return amt_written;
20 switch (std.c._errno().*) {20 switch (@intToEnum(os.E, std.c._errno().*)) {
21 0 => unreachable,21 .SUCCESS => unreachable,
22 os.EINVAL => unreachable,22 .INVAL => unreachable,
23 os.EFAULT => unreachable,23 .FAULT => unreachable,
24 os.EAGAIN => unreachable, // this is a blocking API24 .AGAIN => unreachable, // this is a blocking API
25 os.EBADF => unreachable, // always a race condition25 .BADF => unreachable, // always a race condition
26 os.EDESTADDRREQ => unreachable, // connect was never called26 .DESTADDRREQ => unreachable, // connect was never called
27 os.EDQUOT => return error.DiskQuota,27 .DQUOT => return error.DiskQuota,
28 os.EFBIG => return error.FileTooBig,28 .FBIG => return error.FileTooBig,
29 os.EIO => return error.InputOutput,29 .IO => return error.InputOutput,
30 os.ENOSPC => return error.NoSpaceLeft,30 .NOSPC => return error.NoSpaceLeft,
31 os.EPERM => return error.AccessDenied,31 .PERM => return error.AccessDenied,
32 os.EPIPE => return error.BrokenPipe,32 .PIPE => return error.BrokenPipe,
33 else => |err| return os.unexpectedErrno(err),33 else => |err| return os.unexpectedErrno(err),
34 }34 }
35}35}
lib/std/os.zig+1304-1304
...@@ -116,13 +116,13 @@ pub fn close(fd: fd_t) void {...@@ -116,13 +116,13 @@ pub fn close(fd: fd_t) void {
116 if (comptime std.Target.current.isDarwin()) {116 if (comptime std.Target.current.isDarwin()) {
117 // This avoids the EINTR problem.117 // This avoids the EINTR problem.
118 switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) {118 switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) {
119 EBADF => unreachable, // Always a race condition.119 .BADF => unreachable, // Always a race condition.
120 else => return,120 else => return,
121 }121 }
122 }122 }
123 switch (errno(system.close(fd))) {123 switch (errno(system.close(fd))) {
124 EBADF => unreachable, // Always a race condition.124 .BADF => unreachable, // Always a race condition.
125 EINTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425125 .INTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425
126 else => return,126 else => return,
127 }127 }
128}128}
...@@ -159,11 +159,11 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {...@@ -159,11 +159,11 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
159 };159 };
160160
161 switch (res.err) {161 switch (res.err) {
162 0 => buf = buf[res.num_read..],162 .SUCCESS => buf = buf[res.num_read..],
163 EINVAL => unreachable,163 .INVAL => unreachable,
164 EFAULT => unreachable,164 .FAULT => unreachable,
165 EINTR => continue,165 .INTR => continue,
166 ENOSYS => return getRandomBytesDevURandom(buf),166 .NOSYS => return getRandomBytesDevURandom(buf),
167 else => return unexpectedErrno(res.err),167 else => return unexpectedErrno(res.err),
168 }168 }
169 }169 }
...@@ -175,7 +175,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {...@@ -175,7 +175,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
175 return;175 return;
176 },176 },
177 .wasi => switch (wasi.random_get(buffer.ptr, buffer.len)) {177 .wasi => switch (wasi.random_get(buffer.ptr, buffer.len)) {
178 0 => return,178 .SUCCESS => return,
179 else => |err| return unexpectedErrno(err),179 else => |err| return unexpectedErrno(err),
180 },180 },
181 else => return getRandomBytesDevURandom(buffer),181 else => return getRandomBytesDevURandom(buffer),
...@@ -238,7 +238,7 @@ pub const RaiseError = UnexpectedError;...@@ -238,7 +238,7 @@ pub const RaiseError = UnexpectedError;
238pub fn raise(sig: u8) RaiseError!void {238pub fn raise(sig: u8) RaiseError!void {
239 if (builtin.link_libc) {239 if (builtin.link_libc) {
240 switch (errno(system.raise(sig))) {240 switch (errno(system.raise(sig))) {
241 0 => return,241 .SUCCESS => return,
242 else => |err| return unexpectedErrno(err),242 else => |err| return unexpectedErrno(err),
243 }243 }
244 }244 }
...@@ -255,7 +255,7 @@ pub fn raise(sig: u8) RaiseError!void {...@@ -255,7 +255,7 @@ pub fn raise(sig: u8) RaiseError!void {
255 _ = linux.sigprocmask(SIG_SETMASK, &set, null);255 _ = linux.sigprocmask(SIG_SETMASK, &set, null);
256256
257 switch (errno(rc)) {257 switch (errno(rc)) {
258 0 => return,258 .SUCCESS => return,
259 else => |err| return unexpectedErrno(err),259 else => |err| return unexpectedErrno(err),
260 }260 }
261 }261 }
...@@ -267,10 +267,10 @@ pub const KillError = error{PermissionDenied} || UnexpectedError;...@@ -267,10 +267,10 @@ pub const KillError = error{PermissionDenied} || UnexpectedError;
267267
268pub fn kill(pid: pid_t, sig: u8) KillError!void {268pub fn kill(pid: pid_t, sig: u8) KillError!void {
269 switch (errno(system.kill(pid, sig))) {269 switch (errno(system.kill(pid, sig))) {
270 0 => return,270 .SUCCESS => return,
271 EINVAL => unreachable, // invalid signal271 .INVAL => unreachable, // invalid signal
272 EPERM => return error.PermissionDenied,272 .PERM => return error.PermissionDenied,
273 ESRCH => unreachable, // always a race condition273 .SRCH => unreachable, // always a race condition
274 else => |err| return unexpectedErrno(err),274 else => |err| return unexpectedErrno(err),
275 }275 }
276}276}
...@@ -342,19 +342,19 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -342,19 +342,19 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
342342
343 var nread: usize = undefined;343 var nread: usize = undefined;
344 switch (wasi.fd_read(fd, &iovs, iovs.len, &nread)) {344 switch (wasi.fd_read(fd, &iovs, iovs.len, &nread)) {
345 wasi.ESUCCESS => return nread,345 .SUCCESS => return nread,
346 wasi.EINTR => unreachable,346 .INTR => unreachable,
347 wasi.EINVAL => unreachable,347 .INVAL => unreachable,
348 wasi.EFAULT => unreachable,348 .FAULT => unreachable,
349 wasi.EAGAIN => unreachable,349 .AGAIN => unreachable,
350 wasi.EBADF => return error.NotOpenForReading, // Can be a race condition.350 .BADF => return error.NotOpenForReading, // Can be a race condition.
351 wasi.EIO => return error.InputOutput,351 .IO => return error.InputOutput,
352 wasi.EISDIR => return error.IsDir,352 .ISDIR => return error.IsDir,
353 wasi.ENOBUFS => return error.SystemResources,353 .NOBUFS => return error.SystemResources,
354 wasi.ENOMEM => return error.SystemResources,354 .NOMEM => return error.SystemResources,
355 wasi.ECONNRESET => return error.ConnectionResetByPeer,355 .CONNRESET => return error.ConnectionResetByPeer,
356 wasi.ETIMEDOUT => return error.ConnectionTimedOut,356 .TIMEDOUT => return error.ConnectionTimedOut,
357 wasi.ENOTCAPABLE => return error.AccessDenied,357 .NOTCAPABLE => return error.AccessDenied,
358 else => |err| return unexpectedErrno(err),358 else => |err| return unexpectedErrno(err),
359 }359 }
360 }360 }
...@@ -370,18 +370,18 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -370,18 +370,18 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
370 while (true) {370 while (true) {
371 const rc = system.read(fd, buf.ptr, adjusted_len);371 const rc = system.read(fd, buf.ptr, adjusted_len);
372 switch (errno(rc)) {372 switch (errno(rc)) {
373 0 => return @intCast(usize, rc),373 .SUCCESS => return @intCast(usize, rc),
374 EINTR => continue,374 .INTR => continue,
375 EINVAL => unreachable,375 .INVAL => unreachable,
376 EFAULT => unreachable,376 .FAULT => unreachable,
377 EAGAIN => return error.WouldBlock,377 .AGAIN => return error.WouldBlock,
378 EBADF => return error.NotOpenForReading, // Can be a race condition.378 .BADF => return error.NotOpenForReading, // Can be a race condition.
379 EIO => return error.InputOutput,379 .IO => return error.InputOutput,
380 EISDIR => return error.IsDir,380 .ISDIR => return error.IsDir,
381 ENOBUFS => return error.SystemResources,381 .NOBUFS => return error.SystemResources,
382 ENOMEM => return error.SystemResources,382 .NOMEM => return error.SystemResources,
383 ECONNRESET => return error.ConnectionResetByPeer,383 .CONNRESET => return error.ConnectionResetByPeer,
384 ETIMEDOUT => return error.ConnectionTimedOut,384 .TIMEDOUT => return error.ConnectionTimedOut,
385 else => |err| return unexpectedErrno(err),385 else => |err| return unexpectedErrno(err),
386 }386 }
387 }387 }
...@@ -407,17 +407,17 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {...@@ -407,17 +407,17 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
407 if (builtin.os.tag == .wasi and !builtin.link_libc) {407 if (builtin.os.tag == .wasi and !builtin.link_libc) {
408 var nread: usize = undefined;408 var nread: usize = undefined;
409 switch (wasi.fd_read(fd, iov.ptr, iov.len, &nread)) {409 switch (wasi.fd_read(fd, iov.ptr, iov.len, &nread)) {
410 wasi.ESUCCESS => return nread,410 .SUCCESS => return nread,
411 wasi.EINTR => unreachable,411 .INTR => unreachable,
412 wasi.EINVAL => unreachable,412 .INVAL => unreachable,
413 wasi.EFAULT => unreachable,413 .FAULT => unreachable,
414 wasi.EAGAIN => unreachable, // currently not support in WASI414 .AGAIN => unreachable, // currently not support in WASI
415 wasi.EBADF => return error.NotOpenForReading, // can be a race condition415 .BADF => return error.NotOpenForReading, // can be a race condition
416 wasi.EIO => return error.InputOutput,416 .IO => return error.InputOutput,
417 wasi.EISDIR => return error.IsDir,417 .ISDIR => return error.IsDir,
418 wasi.ENOBUFS => return error.SystemResources,418 .NOBUFS => return error.SystemResources,
419 wasi.ENOMEM => return error.SystemResources,419 .NOMEM => return error.SystemResources,
420 wasi.ENOTCAPABLE => return error.AccessDenied,420 .NOTCAPABLE => return error.AccessDenied,
421 else => |err| return unexpectedErrno(err),421 else => |err| return unexpectedErrno(err),
422 }422 }
423 }423 }
...@@ -426,16 +426,16 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {...@@ -426,16 +426,16 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
426 // TODO handle the case when iov_len is too large and get rid of this @intCast426 // TODO handle the case when iov_len is too large and get rid of this @intCast
427 const rc = system.readv(fd, iov.ptr, iov_count);427 const rc = system.readv(fd, iov.ptr, iov_count);
428 switch (errno(rc)) {428 switch (errno(rc)) {
429 0 => return @intCast(usize, rc),429 .SUCCESS => return @intCast(usize, rc),
430 EINTR => continue,430 .INTR => continue,
431 EINVAL => unreachable,431 .INVAL => unreachable,
432 EFAULT => unreachable,432 .FAULT => unreachable,
433 EAGAIN => return error.WouldBlock,433 .AGAIN => return error.WouldBlock,
434 EBADF => return error.NotOpenForReading, // can be a race condition434 .BADF => return error.NotOpenForReading, // can be a race condition
435 EIO => return error.InputOutput,435 .IO => return error.InputOutput,
436 EISDIR => return error.IsDir,436 .ISDIR => return error.IsDir,
437 ENOBUFS => return error.SystemResources,437 .NOBUFS => return error.SystemResources,
438 ENOMEM => return error.SystemResources,438 .NOMEM => return error.SystemResources,
439 else => |err| return unexpectedErrno(err),439 else => |err| return unexpectedErrno(err),
440 }440 }
441 }441 }
...@@ -469,21 +469,21 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {...@@ -469,21 +469,21 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
469469
470 var nread: usize = undefined;470 var nread: usize = undefined;
471 switch (wasi.fd_pread(fd, &iovs, iovs.len, offset, &nread)) {471 switch (wasi.fd_pread(fd, &iovs, iovs.len, offset, &nread)) {
472 wasi.ESUCCESS => return nread,472 .SUCCESS => return nread,
473 wasi.EINTR => unreachable,473 .INTR => unreachable,
474 wasi.EINVAL => unreachable,474 .INVAL => unreachable,
475 wasi.EFAULT => unreachable,475 .FAULT => unreachable,
476 wasi.EAGAIN => unreachable,476 .AGAIN => unreachable,
477 wasi.EBADF => return error.NotOpenForReading, // Can be a race condition.477 .BADF => return error.NotOpenForReading, // Can be a race condition.
478 wasi.EIO => return error.InputOutput,478 .IO => return error.InputOutput,
479 wasi.EISDIR => return error.IsDir,479 .ISDIR => return error.IsDir,
480 wasi.ENOBUFS => return error.SystemResources,480 .NOBUFS => return error.SystemResources,
481 wasi.ENOMEM => return error.SystemResources,481 .NOMEM => return error.SystemResources,
482 wasi.ECONNRESET => return error.ConnectionResetByPeer,482 .CONNRESET => return error.ConnectionResetByPeer,
483 wasi.ENXIO => return error.Unseekable,483 .NXIO => return error.Unseekable,
484 wasi.ESPIPE => return error.Unseekable,484 .SPIPE => return error.Unseekable,
485 wasi.EOVERFLOW => return error.Unseekable,485 .OVERFLOW => return error.Unseekable,
486 wasi.ENOTCAPABLE => return error.AccessDenied,486 .NOTCAPABLE => return error.AccessDenied,
487 else => |err| return unexpectedErrno(err),487 else => |err| return unexpectedErrno(err),
488 }488 }
489 }489 }
...@@ -505,20 +505,20 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {...@@ -505,20 +505,20 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
505 while (true) {505 while (true) {
506 const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset);506 const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset);
507 switch (errno(rc)) {507 switch (errno(rc)) {
508 0 => return @intCast(usize, rc),508 .SUCCESS => return @intCast(usize, rc),
509 EINTR => continue,509 .INTR => continue,
510 EINVAL => unreachable,510 .INVAL => unreachable,
511 EFAULT => unreachable,511 .FAULT => unreachable,
512 EAGAIN => return error.WouldBlock,512 .AGAIN => return error.WouldBlock,
513 EBADF => return error.NotOpenForReading, // Can be a race condition.513 .BADF => return error.NotOpenForReading, // Can be a race condition.
514 EIO => return error.InputOutput,514 .IO => return error.InputOutput,
515 EISDIR => return error.IsDir,515 .ISDIR => return error.IsDir,
516 ENOBUFS => return error.SystemResources,516 .NOBUFS => return error.SystemResources,
517 ENOMEM => return error.SystemResources,517 .NOMEM => return error.SystemResources,
518 ECONNRESET => return error.ConnectionResetByPeer,518 .CONNRESET => return error.ConnectionResetByPeer,
519 ENXIO => return error.Unseekable,519 .NXIO => return error.Unseekable,
520 ESPIPE => return error.Unseekable,520 .SPIPE => return error.Unseekable,
521 EOVERFLOW => return error.Unseekable,521 .OVERFLOW => return error.Unseekable,
522 else => |err| return unexpectedErrno(err),522 else => |err| return unexpectedErrno(err),
523 }523 }
524 }524 }
...@@ -558,15 +558,15 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -558,15 +558,15 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
558 }558 }
559 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {559 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
560 switch (wasi.fd_filestat_set_size(fd, length)) {560 switch (wasi.fd_filestat_set_size(fd, length)) {
561 wasi.ESUCCESS => return,561 .SUCCESS => return,
562 wasi.EINTR => unreachable,562 .INTR => unreachable,
563 wasi.EFBIG => return error.FileTooBig,563 .FBIG => return error.FileTooBig,
564 wasi.EIO => return error.InputOutput,564 .IO => return error.InputOutput,
565 wasi.EPERM => return error.AccessDenied,565 .PERM => return error.AccessDenied,
566 wasi.ETXTBSY => return error.FileBusy,566 .TXTBSY => return error.FileBusy,
567 wasi.EBADF => unreachable, // Handle not open for writing567 .BADF => unreachable, // Handle not open for writing
568 wasi.EINVAL => unreachable, // Handle not open for writing568 .INVAL => unreachable, // Handle not open for writing
569 wasi.ENOTCAPABLE => return error.AccessDenied,569 .NOTCAPABLE => return error.AccessDenied,
570 else => |err| return unexpectedErrno(err),570 else => |err| return unexpectedErrno(err),
571 }571 }
572 }572 }
...@@ -579,14 +579,14 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -579,14 +579,14 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
579579
580 const ilen = @bitCast(i64, length); // the OS treats this as unsigned580 const ilen = @bitCast(i64, length); // the OS treats this as unsigned
581 switch (errno(ftruncate_sym(fd, ilen))) {581 switch (errno(ftruncate_sym(fd, ilen))) {
582 0 => return,582 .SUCCESS => return,
583 EINTR => continue,583 .INTR => continue,
584 EFBIG => return error.FileTooBig,584 .FBIG => return error.FileTooBig,
585 EIO => return error.InputOutput,585 .IO => return error.InputOutput,
586 EPERM => return error.AccessDenied,586 .PERM => return error.AccessDenied,
587 ETXTBSY => return error.FileBusy,587 .TXTBSY => return error.FileBusy,
588 EBADF => unreachable, // Handle not open for writing588 .BADF => unreachable, // Handle not open for writing
589 EINVAL => unreachable, // Handle not open for writing589 .INVAL => unreachable, // Handle not open for writing
590 else => |err| return unexpectedErrno(err),590 else => |err| return unexpectedErrno(err),
591 }591 }
592 }592 }
...@@ -620,20 +620,20 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {...@@ -620,20 +620,20 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
620 if (builtin.os.tag == .wasi and !builtin.link_libc) {620 if (builtin.os.tag == .wasi and !builtin.link_libc) {
621 var nread: usize = undefined;621 var nread: usize = undefined;
622 switch (wasi.fd_pread(fd, iov.ptr, iov.len, offset, &nread)) {622 switch (wasi.fd_pread(fd, iov.ptr, iov.len, offset, &nread)) {
623 wasi.ESUCCESS => return nread,623 .SUCCESS => return nread,
624 wasi.EINTR => unreachable,624 .INTR => unreachable,
625 wasi.EINVAL => unreachable,625 .INVAL => unreachable,
626 wasi.EFAULT => unreachable,626 .FAULT => unreachable,
627 wasi.EAGAIN => unreachable,627 .AGAIN => unreachable,
628 wasi.EBADF => return error.NotOpenForReading, // can be a race condition628 .BADF => return error.NotOpenForReading, // can be a race condition
629 wasi.EIO => return error.InputOutput,629 .IO => return error.InputOutput,
630 wasi.EISDIR => return error.IsDir,630 .ISDIR => return error.IsDir,
631 wasi.ENOBUFS => return error.SystemResources,631 .NOBUFS => return error.SystemResources,
632 wasi.ENOMEM => return error.SystemResources,632 .NOMEM => return error.SystemResources,
633 wasi.ENXIO => return error.Unseekable,633 .NXIO => return error.Unseekable,
634 wasi.ESPIPE => return error.Unseekable,634 .SPIPE => return error.Unseekable,
635 wasi.EOVERFLOW => return error.Unseekable,635 .OVERFLOW => return error.Unseekable,
636 wasi.ENOTCAPABLE => return error.AccessDenied,636 .NOTCAPABLE => return error.AccessDenied,
637 else => |err| return unexpectedErrno(err),637 else => |err| return unexpectedErrno(err),
638 }638 }
639 }639 }
...@@ -649,19 +649,19 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {...@@ -649,19 +649,19 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
649 while (true) {649 while (true) {
650 const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset);650 const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset);
651 switch (errno(rc)) {651 switch (errno(rc)) {
652 0 => return @bitCast(usize, rc),652 .SUCCESS => return @bitCast(usize, rc),
653 EINTR => continue,653 .INTR => continue,
654 EINVAL => unreachable,654 .INVAL => unreachable,
655 EFAULT => unreachable,655 .FAULT => unreachable,
656 EAGAIN => return error.WouldBlock,656 .AGAIN => return error.WouldBlock,
657 EBADF => return error.NotOpenForReading, // can be a race condition657 .BADF => return error.NotOpenForReading, // can be a race condition
658 EIO => return error.InputOutput,658 .IO => return error.InputOutput,
659 EISDIR => return error.IsDir,659 .ISDIR => return error.IsDir,
660 ENOBUFS => return error.SystemResources,660 .NOBUFS => return error.SystemResources,
661 ENOMEM => return error.SystemResources,661 .NOMEM => return error.SystemResources,
662 ENXIO => return error.Unseekable,662 .NXIO => return error.Unseekable,
663 ESPIPE => return error.Unseekable,663 .SPIPE => return error.Unseekable,
664 EOVERFLOW => return error.Unseekable,664 .OVERFLOW => return error.Unseekable,
665 else => |err| return unexpectedErrno(err),665 else => |err| return unexpectedErrno(err),
666 }666 }
667 }667 }
...@@ -723,20 +723,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -723,20 +723,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
723 }};723 }};
724 var nwritten: usize = undefined;724 var nwritten: usize = undefined;
725 switch (wasi.fd_write(fd, &ciovs, ciovs.len, &nwritten)) {725 switch (wasi.fd_write(fd, &ciovs, ciovs.len, &nwritten)) {
726 wasi.ESUCCESS => return nwritten,726 .SUCCESS => return nwritten,
727 wasi.EINTR => unreachable,727 .INTR => unreachable,
728 wasi.EINVAL => unreachable,728 .INVAL => unreachable,
729 wasi.EFAULT => unreachable,729 .FAULT => unreachable,
730 wasi.EAGAIN => unreachable,730 .AGAIN => unreachable,
731 wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.731 .BADF => return error.NotOpenForWriting, // can be a race condition.
732 wasi.EDESTADDRREQ => unreachable, // `connect` was never called.732 .DESTADDRREQ => unreachable, // `connect` was never called.
733 wasi.EDQUOT => return error.DiskQuota,733 .DQUOT => return error.DiskQuota,
734 wasi.EFBIG => return error.FileTooBig,734 .FBIG => return error.FileTooBig,
735 wasi.EIO => return error.InputOutput,735 .IO => return error.InputOutput,
736 wasi.ENOSPC => return error.NoSpaceLeft,736 .NOSPC => return error.NoSpaceLeft,
737 wasi.EPERM => return error.AccessDenied,737 .PERM => return error.AccessDenied,
738 wasi.EPIPE => return error.BrokenPipe,738 .PIPE => return error.BrokenPipe,
739 wasi.ENOTCAPABLE => return error.AccessDenied,739 .NOTCAPABLE => return error.AccessDenied,
740 else => |err| return unexpectedErrno(err),740 else => |err| return unexpectedErrno(err),
741 }741 }
742 }742 }
...@@ -751,20 +751,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -751,20 +751,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
751 while (true) {751 while (true) {
752 const rc = system.write(fd, bytes.ptr, adjusted_len);752 const rc = system.write(fd, bytes.ptr, adjusted_len);
753 switch (errno(rc)) {753 switch (errno(rc)) {
754 0 => return @intCast(usize, rc),754 .SUCCESS => return @intCast(usize, rc),
755 EINTR => continue,755 .INTR => continue,
756 EINVAL => unreachable,756 .INVAL => unreachable,
757 EFAULT => unreachable,757 .FAULT => unreachable,
758 EAGAIN => return error.WouldBlock,758 .AGAIN => return error.WouldBlock,
759 EBADF => return error.NotOpenForWriting, // can be a race condition.759 .BADF => return error.NotOpenForWriting, // can be a race condition.
760 EDESTADDRREQ => unreachable, // `connect` was never called.760 .DESTADDRREQ => unreachable, // `connect` was never called.
761 EDQUOT => return error.DiskQuota,761 .DQUOT => return error.DiskQuota,
762 EFBIG => return error.FileTooBig,762 .FBIG => return error.FileTooBig,
763 EIO => return error.InputOutput,763 .IO => return error.InputOutput,
764 ENOSPC => return error.NoSpaceLeft,764 .NOSPC => return error.NoSpaceLeft,
765 EPERM => return error.AccessDenied,765 .PERM => return error.AccessDenied,
766 EPIPE => return error.BrokenPipe,766 .PIPE => return error.BrokenPipe,
767 ECONNRESET => return error.ConnectionResetByPeer,767 .CONNRESET => return error.ConnectionResetByPeer,
768 else => |err| return unexpectedErrno(err),768 else => |err| return unexpectedErrno(err),
769 }769 }
770 }770 }
...@@ -798,20 +798,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {...@@ -798,20 +798,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
798 if (builtin.os.tag == .wasi and !builtin.link_libc) {798 if (builtin.os.tag == .wasi and !builtin.link_libc) {
799 var nwritten: usize = undefined;799 var nwritten: usize = undefined;
800 switch (wasi.fd_write(fd, iov.ptr, iov.len, &nwritten)) {800 switch (wasi.fd_write(fd, iov.ptr, iov.len, &nwritten)) {
801 wasi.ESUCCESS => return nwritten,801 .SUCCESS => return nwritten,
802 wasi.EINTR => unreachable,802 .INTR => unreachable,
803 wasi.EINVAL => unreachable,803 .INVAL => unreachable,
804 wasi.EFAULT => unreachable,804 .FAULT => unreachable,
805 wasi.EAGAIN => unreachable,805 .AGAIN => unreachable,
806 wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.806 .BADF => return error.NotOpenForWriting, // can be a race condition.
807 wasi.EDESTADDRREQ => unreachable, // `connect` was never called.807 .DESTADDRREQ => unreachable, // `connect` was never called.
808 wasi.EDQUOT => return error.DiskQuota,808 .DQUOT => return error.DiskQuota,
809 wasi.EFBIG => return error.FileTooBig,809 .FBIG => return error.FileTooBig,
810 wasi.EIO => return error.InputOutput,810 .IO => return error.InputOutput,
811 wasi.ENOSPC => return error.NoSpaceLeft,811 .NOSPC => return error.NoSpaceLeft,
812 wasi.EPERM => return error.AccessDenied,812 .PERM => return error.AccessDenied,
813 wasi.EPIPE => return error.BrokenPipe,813 .PIPE => return error.BrokenPipe,
814 wasi.ENOTCAPABLE => return error.AccessDenied,814 .NOTCAPABLE => return error.AccessDenied,
815 else => |err| return unexpectedErrno(err),815 else => |err| return unexpectedErrno(err),
816 }816 }
817 }817 }
...@@ -820,20 +820,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {...@@ -820,20 +820,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
820 while (true) {820 while (true) {
821 const rc = system.writev(fd, iov.ptr, iov_count);821 const rc = system.writev(fd, iov.ptr, iov_count);
822 switch (errno(rc)) {822 switch (errno(rc)) {
823 0 => return @intCast(usize, rc),823 .SUCCESS => return @intCast(usize, rc),
824 EINTR => continue,824 .INTR => continue,
825 EINVAL => unreachable,825 .INVAL => unreachable,
826 EFAULT => unreachable,826 .FAULT => unreachable,
827 EAGAIN => return error.WouldBlock,827 .AGAIN => return error.WouldBlock,
828 EBADF => return error.NotOpenForWriting, // Can be a race condition.828 .BADF => return error.NotOpenForWriting, // Can be a race condition.
829 EDESTADDRREQ => unreachable, // `connect` was never called.829 .DESTADDRREQ => unreachable, // `connect` was never called.
830 EDQUOT => return error.DiskQuota,830 .DQUOT => return error.DiskQuota,
831 EFBIG => return error.FileTooBig,831 .FBIG => return error.FileTooBig,
832 EIO => return error.InputOutput,832 .IO => return error.InputOutput,
833 ENOSPC => return error.NoSpaceLeft,833 .NOSPC => return error.NoSpaceLeft,
834 EPERM => return error.AccessDenied,834 .PERM => return error.AccessDenied,
835 EPIPE => return error.BrokenPipe,835 .PIPE => return error.BrokenPipe,
836 ECONNRESET => return error.ConnectionResetByPeer,836 .CONNRESET => return error.ConnectionResetByPeer,
837 else => |err| return unexpectedErrno(err),837 else => |err| return unexpectedErrno(err),
838 }838 }
839 }839 }
...@@ -875,23 +875,23 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {...@@ -875,23 +875,23 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
875875
876 var nwritten: usize = undefined;876 var nwritten: usize = undefined;
877 switch (wasi.fd_pwrite(fd, &ciovs, ciovs.len, offset, &nwritten)) {877 switch (wasi.fd_pwrite(fd, &ciovs, ciovs.len, offset, &nwritten)) {
878 wasi.ESUCCESS => return nwritten,878 .SUCCESS => return nwritten,
879 wasi.EINTR => unreachable,879 .INTR => unreachable,
880 wasi.EINVAL => unreachable,880 .INVAL => unreachable,
881 wasi.EFAULT => unreachable,881 .FAULT => unreachable,
882 wasi.EAGAIN => unreachable,882 .AGAIN => unreachable,
883 wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.883 .BADF => return error.NotOpenForWriting, // can be a race condition.
884 wasi.EDESTADDRREQ => unreachable, // `connect` was never called.884 .DESTADDRREQ => unreachable, // `connect` was never called.
885 wasi.EDQUOT => return error.DiskQuota,885 .DQUOT => return error.DiskQuota,
886 wasi.EFBIG => return error.FileTooBig,886 .FBIG => return error.FileTooBig,
887 wasi.EIO => return error.InputOutput,887 .IO => return error.InputOutput,
888 wasi.ENOSPC => return error.NoSpaceLeft,888 .NOSPC => return error.NoSpaceLeft,
889 wasi.EPERM => return error.AccessDenied,889 .PERM => return error.AccessDenied,
890 wasi.EPIPE => return error.BrokenPipe,890 .PIPE => return error.BrokenPipe,
891 wasi.ENXIO => return error.Unseekable,891 .NXIO => return error.Unseekable,
892 wasi.ESPIPE => return error.Unseekable,892 .SPIPE => return error.Unseekable,
893 wasi.EOVERFLOW => return error.Unseekable,893 .OVERFLOW => return error.Unseekable,
894 wasi.ENOTCAPABLE => return error.AccessDenied,894 .NOTCAPABLE => return error.AccessDenied,
895 else => |err| return unexpectedErrno(err),895 else => |err| return unexpectedErrno(err),
896 }896 }
897 }897 }
...@@ -913,22 +913,22 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {...@@ -913,22 +913,22 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
913 while (true) {913 while (true) {
914 const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset);914 const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset);
915 switch (errno(rc)) {915 switch (errno(rc)) {
916 0 => return @intCast(usize, rc),916 .SUCCESS => return @intCast(usize, rc),
917 EINTR => continue,917 .INTR => continue,
918 EINVAL => unreachable,918 .INVAL => unreachable,
919 EFAULT => unreachable,919 .FAULT => unreachable,
920 EAGAIN => return error.WouldBlock,920 .AGAIN => return error.WouldBlock,
921 EBADF => return error.NotOpenForWriting, // Can be a race condition.921 .BADF => return error.NotOpenForWriting, // Can be a race condition.
922 EDESTADDRREQ => unreachable, // `connect` was never called.922 .DESTADDRREQ => unreachable, // `connect` was never called.
923 EDQUOT => return error.DiskQuota,923 .DQUOT => return error.DiskQuota,
924 EFBIG => return error.FileTooBig,924 .FBIG => return error.FileTooBig,
925 EIO => return error.InputOutput,925 .IO => return error.InputOutput,
926 ENOSPC => return error.NoSpaceLeft,926 .NOSPC => return error.NoSpaceLeft,
927 EPERM => return error.AccessDenied,927 .PERM => return error.AccessDenied,
928 EPIPE => return error.BrokenPipe,928 .PIPE => return error.BrokenPipe,
929 ENXIO => return error.Unseekable,929 .NXIO => return error.Unseekable,
930 ESPIPE => return error.Unseekable,930 .SPIPE => return error.Unseekable,
931 EOVERFLOW => return error.Unseekable,931 .OVERFLOW => return error.Unseekable,
932 else => |err| return unexpectedErrno(err),932 else => |err| return unexpectedErrno(err),
933 }933 }
934 }934 }
...@@ -971,23 +971,23 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz...@@ -971,23 +971,23 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
971 if (builtin.os.tag == .wasi and !builtin.link_libc) {971 if (builtin.os.tag == .wasi and !builtin.link_libc) {
972 var nwritten: usize = undefined;972 var nwritten: usize = undefined;
973 switch (wasi.fd_pwrite(fd, iov.ptr, iov.len, offset, &nwritten)) {973 switch (wasi.fd_pwrite(fd, iov.ptr, iov.len, offset, &nwritten)) {
974 wasi.ESUCCESS => return nwritten,974 .SUCCESS => return nwritten,
975 wasi.EINTR => unreachable,975 .INTR => unreachable,
976 wasi.EINVAL => unreachable,976 .INVAL => unreachable,
977 wasi.EFAULT => unreachable,977 .FAULT => unreachable,
978 wasi.EAGAIN => unreachable,978 .AGAIN => unreachable,
979 wasi.EBADF => return error.NotOpenForWriting, // Can be a race condition.979 .BADF => return error.NotOpenForWriting, // Can be a race condition.
980 wasi.EDESTADDRREQ => unreachable, // `connect` was never called.980 .DESTADDRREQ => unreachable, // `connect` was never called.
981 wasi.EDQUOT => return error.DiskQuota,981 .DQUOT => return error.DiskQuota,
982 wasi.EFBIG => return error.FileTooBig,982 .FBIG => return error.FileTooBig,
983 wasi.EIO => return error.InputOutput,983 .IO => return error.InputOutput,
984 wasi.ENOSPC => return error.NoSpaceLeft,984 .NOSPC => return error.NoSpaceLeft,
985 wasi.EPERM => return error.AccessDenied,985 .PERM => return error.AccessDenied,
986 wasi.EPIPE => return error.BrokenPipe,986 .PIPE => return error.BrokenPipe,
987 wasi.ENXIO => return error.Unseekable,987 .NXIO => return error.Unseekable,
988 wasi.ESPIPE => return error.Unseekable,988 .SPIPE => return error.Unseekable,
989 wasi.EOVERFLOW => return error.Unseekable,989 .OVERFLOW => return error.Unseekable,
990 wasi.ENOTCAPABLE => return error.AccessDenied,990 .NOTCAPABLE => return error.AccessDenied,
991 else => |err| return unexpectedErrno(err),991 else => |err| return unexpectedErrno(err),
992 }992 }
993 }993 }
...@@ -1002,22 +1002,22 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz...@@ -1002,22 +1002,22 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
1002 while (true) {1002 while (true) {
1003 const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset);1003 const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset);
1004 switch (errno(rc)) {1004 switch (errno(rc)) {
1005 0 => return @intCast(usize, rc),1005 .SUCCESS => return @intCast(usize, rc),
1006 EINTR => continue,1006 .INTR => continue,
1007 EINVAL => unreachable,1007 .INVAL => unreachable,
1008 EFAULT => unreachable,1008 .FAULT => unreachable,
1009 EAGAIN => return error.WouldBlock,1009 .AGAIN => return error.WouldBlock,
1010 EBADF => return error.NotOpenForWriting, // Can be a race condition.1010 .BADF => return error.NotOpenForWriting, // Can be a race condition.
1011 EDESTADDRREQ => unreachable, // `connect` was never called.1011 .DESTADDRREQ => unreachable, // `connect` was never called.
1012 EDQUOT => return error.DiskQuota,1012 .DQUOT => return error.DiskQuota,
1013 EFBIG => return error.FileTooBig,1013 .FBIG => return error.FileTooBig,
1014 EIO => return error.InputOutput,1014 .IO => return error.InputOutput,
1015 ENOSPC => return error.NoSpaceLeft,1015 .NOSPC => return error.NoSpaceLeft,
1016 EPERM => return error.AccessDenied,1016 .PERM => return error.AccessDenied,
1017 EPIPE => return error.BrokenPipe,1017 .PIPE => return error.BrokenPipe,
1018 ENXIO => return error.Unseekable,1018 .NXIO => return error.Unseekable,
1019 ESPIPE => return error.Unseekable,1019 .SPIPE => return error.Unseekable,
1020 EOVERFLOW => return error.Unseekable,1020 .OVERFLOW => return error.Unseekable,
1021 else => |err| return unexpectedErrno(err),1021 else => |err| return unexpectedErrno(err),
1022 }1022 }
1023 }1023 }
...@@ -1098,27 +1098,27 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t...@@ -1098,27 +1098,27 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t
1098 while (true) {1098 while (true) {
1099 const rc = open_sym(file_path, flags, perm);1099 const rc = open_sym(file_path, flags, perm);
1100 switch (errno(rc)) {1100 switch (errno(rc)) {
1101 0 => return @intCast(fd_t, rc),1101 .SUCCESS => return @intCast(fd_t, rc),
1102 EINTR => continue,1102 .INTR => continue,
11031103
1104 EFAULT => unreachable,1104 .FAULT => unreachable,
1105 EINVAL => unreachable,1105 .INVAL => unreachable,
1106 EACCES => return error.AccessDenied,1106 .ACCES => return error.AccessDenied,
1107 EFBIG => return error.FileTooBig,1107 .FBIG => return error.FileTooBig,
1108 EOVERFLOW => return error.FileTooBig,1108 .OVERFLOW => return error.FileTooBig,
1109 EISDIR => return error.IsDir,1109 .ISDIR => return error.IsDir,
1110 ELOOP => return error.SymLinkLoop,1110 .LOOP => return error.SymLinkLoop,
1111 EMFILE => return error.ProcessFdQuotaExceeded,1111 .MFILE => return error.ProcessFdQuotaExceeded,
1112 ENAMETOOLONG => return error.NameTooLong,1112 .NAMETOOLONG => return error.NameTooLong,
1113 ENFILE => return error.SystemFdQuotaExceeded,1113 .NFILE => return error.SystemFdQuotaExceeded,
1114 ENODEV => return error.NoDevice,1114 .NODEV => return error.NoDevice,
1115 ENOENT => return error.FileNotFound,1115 .NOENT => return error.FileNotFound,
1116 ENOMEM => return error.SystemResources,1116 .NOMEM => return error.SystemResources,
1117 ENOSPC => return error.NoSpaceLeft,1117 .NOSPC => return error.NoSpaceLeft,
1118 ENOTDIR => return error.NotDir,1118 .NOTDIR => return error.NotDir,
1119 EPERM => return error.AccessDenied,1119 .PERM => return error.AccessDenied,
1120 EEXIST => return error.PathAlreadyExists,1120 .EXIST => return error.PathAlreadyExists,
1121 EBUSY => return error.DeviceBusy,1121 .BUSY => return error.DeviceBusy,
1122 else => |err| return unexpectedErrno(err),1122 else => |err| return unexpectedErrno(err),
1123 }1123 }
1124 }1124 }
...@@ -1193,28 +1193,28 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, lookup_flags: lookupflags...@@ -1193,28 +1193,28 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, lookup_flags: lookupflags
1193 while (true) {1193 while (true) {
1194 var fd: fd_t = undefined;1194 var fd: fd_t = undefined;
1195 switch (wasi.path_open(dir_fd, lookup_flags, file_path.ptr, file_path.len, oflags, base, inheriting, fdflags, &fd)) {1195 switch (wasi.path_open(dir_fd, lookup_flags, file_path.ptr, file_path.len, oflags, base, inheriting, fdflags, &fd)) {
1196 wasi.ESUCCESS => return fd,1196 .SUCCESS => return fd,
1197 wasi.EINTR => continue,1197 .INTR => continue,
11981198
1199 wasi.EFAULT => unreachable,1199 .FAULT => unreachable,
1200 wasi.EINVAL => unreachable,1200 .INVAL => unreachable,
1201 wasi.EACCES => return error.AccessDenied,1201 .ACCES => return error.AccessDenied,
1202 wasi.EFBIG => return error.FileTooBig,1202 .FBIG => return error.FileTooBig,
1203 wasi.EOVERFLOW => return error.FileTooBig,1203 .OVERFLOW => return error.FileTooBig,
1204 wasi.EISDIR => return error.IsDir,1204 .ISDIR => return error.IsDir,
1205 wasi.ELOOP => return error.SymLinkLoop,1205 .LOOP => return error.SymLinkLoop,
1206 wasi.EMFILE => return error.ProcessFdQuotaExceeded,1206 .MFILE => return error.ProcessFdQuotaExceeded,
1207 wasi.ENAMETOOLONG => return error.NameTooLong,1207 .NAMETOOLONG => return error.NameTooLong,
1208 wasi.ENFILE => return error.SystemFdQuotaExceeded,1208 .NFILE => return error.SystemFdQuotaExceeded,
1209 wasi.ENODEV => return error.NoDevice,1209 .NODEV => return error.NoDevice,
1210 wasi.ENOENT => return error.FileNotFound,1210 .NOENT => return error.FileNotFound,
1211 wasi.ENOMEM => return error.SystemResources,1211 .NOMEM => return error.SystemResources,
1212 wasi.ENOSPC => return error.NoSpaceLeft,1212 .NOSPC => return error.NoSpaceLeft,
1213 wasi.ENOTDIR => return error.NotDir,1213 .NOTDIR => return error.NotDir,
1214 wasi.EPERM => return error.AccessDenied,1214 .PERM => return error.AccessDenied,
1215 wasi.EEXIST => return error.PathAlreadyExists,1215 .EXIST => return error.PathAlreadyExists,
1216 wasi.EBUSY => return error.DeviceBusy,1216 .BUSY => return error.DeviceBusy,
1217 wasi.ENOTCAPABLE => return error.AccessDenied,1217 .NOTCAPABLE => return error.AccessDenied,
1218 else => |err| return unexpectedErrno(err),1218 else => |err| return unexpectedErrno(err),
1219 }1219 }
1220 }1220 }
...@@ -1239,30 +1239,30 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)...@@ -1239,30 +1239,30 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
1239 while (true) {1239 while (true) {
1240 const rc = openat_sym(dir_fd, file_path, flags, mode);1240 const rc = openat_sym(dir_fd, file_path, flags, mode);
1241 switch (errno(rc)) {1241 switch (errno(rc)) {
1242 0 => return @intCast(fd_t, rc),1242 .SUCCESS => return @intCast(fd_t, rc),
1243 EINTR => continue,1243 .INTR => continue,
12441244
1245 EFAULT => unreachable,1245 .FAULT => unreachable,
1246 EINVAL => unreachable,1246 .INVAL => unreachable,
1247 EBADF => unreachable,1247 .BADF => unreachable,
1248 EACCES => return error.AccessDenied,1248 .ACCES => return error.AccessDenied,
1249 EFBIG => return error.FileTooBig,1249 .FBIG => return error.FileTooBig,
1250 EOVERFLOW => return error.FileTooBig,1250 .OVERFLOW => return error.FileTooBig,
1251 EISDIR => return error.IsDir,1251 .ISDIR => return error.IsDir,
1252 ELOOP => return error.SymLinkLoop,1252 .LOOP => return error.SymLinkLoop,
1253 EMFILE => return error.ProcessFdQuotaExceeded,1253 .MFILE => return error.ProcessFdQuotaExceeded,
1254 ENAMETOOLONG => return error.NameTooLong,1254 .NAMETOOLONG => return error.NameTooLong,
1255 ENFILE => return error.SystemFdQuotaExceeded,1255 .NFILE => return error.SystemFdQuotaExceeded,
1256 ENODEV => return error.NoDevice,1256 .NODEV => return error.NoDevice,
1257 ENOENT => return error.FileNotFound,1257 .NOENT => return error.FileNotFound,
1258 ENOMEM => return error.SystemResources,1258 .NOMEM => return error.SystemResources,
1259 ENOSPC => return error.NoSpaceLeft,1259 .NOSPC => return error.NoSpaceLeft,
1260 ENOTDIR => return error.NotDir,1260 .NOTDIR => return error.NotDir,
1261 EPERM => return error.AccessDenied,1261 .PERM => return error.AccessDenied,
1262 EEXIST => return error.PathAlreadyExists,1262 .EXIST => return error.PathAlreadyExists,
1263 EBUSY => return error.DeviceBusy,1263 .BUSY => return error.DeviceBusy,
1264 EOPNOTSUPP => return error.FileLocksNotSupported,1264 .OPNOTSUPP => return error.FileLocksNotSupported,
1265 EWOULDBLOCK => return error.WouldBlock,1265 .AGAIN => return error.WouldBlock,
1266 else => |err| return unexpectedErrno(err),1266 else => |err| return unexpectedErrno(err),
1267 }1267 }
1268 }1268 }
...@@ -1286,9 +1286,9 @@ pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t)...@@ -1286,9 +1286,9 @@ pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t)
1286pub fn dup(old_fd: fd_t) !fd_t {1286pub fn dup(old_fd: fd_t) !fd_t {
1287 const rc = system.dup(old_fd);1287 const rc = system.dup(old_fd);
1288 return switch (errno(rc)) {1288 return switch (errno(rc)) {
1289 0 => return @intCast(fd_t, rc),1289 .SUCCESS => return @intCast(fd_t, rc),
1290 EMFILE => error.ProcessFdQuotaExceeded,1290 .MFILE => error.ProcessFdQuotaExceeded,
1291 EBADF => unreachable, // invalid file descriptor1291 .BADF => unreachable, // invalid file descriptor
1292 else => |err| return unexpectedErrno(err),1292 else => |err| return unexpectedErrno(err),
1293 };1293 };
1294}1294}
...@@ -1296,11 +1296,11 @@ pub fn dup(old_fd: fd_t) !fd_t {...@@ -1296,11 +1296,11 @@ pub fn dup(old_fd: fd_t) !fd_t {
1296pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {1296pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
1297 while (true) {1297 while (true) {
1298 switch (errno(system.dup2(old_fd, new_fd))) {1298 switch (errno(system.dup2(old_fd, new_fd))) {
1299 0 => return,1299 .SUCCESS => return,
1300 EBUSY, EINTR => continue,1300 .BUSY, .INTR => continue,
1301 EMFILE => return error.ProcessFdQuotaExceeded,1301 .MFILE => return error.ProcessFdQuotaExceeded,
1302 EINVAL => unreachable, // invalid parameters passed to dup21302 .INVAL => unreachable, // invalid parameters passed to dup2
1303 EBADF => unreachable, // invalid file descriptor1303 .BADF => unreachable, // invalid file descriptor
1304 else => |err| return unexpectedErrno(err),1304 else => |err| return unexpectedErrno(err),
1305 }1305 }
1306 }1306 }
...@@ -1331,23 +1331,23 @@ pub fn execveZ(...@@ -1331,23 +1331,23 @@ pub fn execveZ(
1331 envp: [*:null]const ?[*:0]const u8,1331 envp: [*:null]const ?[*:0]const u8,
1332) ExecveError {1332) ExecveError {
1333 switch (errno(system.execve(path, child_argv, envp))) {1333 switch (errno(system.execve(path, child_argv, envp))) {
1334 0 => unreachable,1334 .SUCCESS => unreachable,
1335 EFAULT => unreachable,1335 .FAULT => unreachable,
1336 E2BIG => return error.SystemResources,1336 .@"2BIG" => return error.SystemResources,
1337 EMFILE => return error.ProcessFdQuotaExceeded,1337 .MFILE => return error.ProcessFdQuotaExceeded,
1338 ENAMETOOLONG => return error.NameTooLong,1338 .NAMETOOLONG => return error.NameTooLong,
1339 ENFILE => return error.SystemFdQuotaExceeded,1339 .NFILE => return error.SystemFdQuotaExceeded,
1340 ENOMEM => return error.SystemResources,1340 .NOMEM => return error.SystemResources,
1341 EACCES => return error.AccessDenied,1341 .ACCES => return error.AccessDenied,
1342 EPERM => return error.AccessDenied,1342 .PERM => return error.AccessDenied,
1343 EINVAL => return error.InvalidExe,1343 .INVAL => return error.InvalidExe,
1344 ENOEXEC => return error.InvalidExe,1344 .NOEXEC => return error.InvalidExe,
1345 EIO => return error.FileSystem,1345 .IO => return error.FileSystem,
1346 ELOOP => return error.FileSystem,1346 .LOOP => return error.FileSystem,
1347 EISDIR => return error.IsDir,1347 .ISDIR => return error.IsDir,
1348 ENOENT => return error.FileNotFound,1348 .NOENT => return error.FileNotFound,
1349 ENOTDIR => return error.NotDir,1349 .NOTDIR => return error.NotDir,
1350 ETXTBSY => return error.FileBusy,1350 .TXTBSY => return error.FileBusy,
1351 else => |err| return unexpectedErrno(err),1351 else => |err| return unexpectedErrno(err),
1352 }1352 }
1353}1353}
...@@ -1543,16 +1543,17 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {...@@ -1543,16 +1543,17 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
1543 }1543 }
15441544
1545 const err = if (builtin.link_libc) blk: {1545 const err = if (builtin.link_libc) blk: {
1546 break :blk if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*;1546 const c_err = if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*;
1547 break :blk @intToEnum(E, c_err);
1547 } else blk: {1548 } else blk: {
1548 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));1549 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
1549 };1550 };
1550 switch (err) {1551 switch (err) {
1551 0 => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)),1552 .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)),
1552 EFAULT => unreachable,1553 .FAULT => unreachable,
1553 EINVAL => unreachable,1554 .INVAL => unreachable,
1554 ENOENT => return error.CurrentWorkingDirectoryUnlinked,1555 .NOENT => return error.CurrentWorkingDirectoryUnlinked,
1555 ERANGE => return error.NameTooLong,1556 .RANGE => return error.NameTooLong,
1556 else => return unexpectedErrno(err),1557 else => return unexpectedErrno(err),
1557 }1558 }
1558}1559}
...@@ -1601,21 +1602,21 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin...@@ -1601,21 +1602,21 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin
1601 @compileError("symlink is not supported on Windows; use std.os.windows.CreateSymbolicLink instead");1602 @compileError("symlink is not supported on Windows; use std.os.windows.CreateSymbolicLink instead");
1602 }1603 }
1603 switch (errno(system.symlink(target_path, sym_link_path))) {1604 switch (errno(system.symlink(target_path, sym_link_path))) {
1604 0 => return,1605 .SUCCESS => return,
1605 EFAULT => unreachable,1606 .FAULT => unreachable,
1606 EINVAL => unreachable,1607 .INVAL => unreachable,
1607 EACCES => return error.AccessDenied,1608 .ACCES => return error.AccessDenied,
1608 EPERM => return error.AccessDenied,1609 .PERM => return error.AccessDenied,
1609 EDQUOT => return error.DiskQuota,1610 .DQUOT => return error.DiskQuota,
1610 EEXIST => return error.PathAlreadyExists,1611 .EXIST => return error.PathAlreadyExists,
1611 EIO => return error.FileSystem,1612 .IO => return error.FileSystem,
1612 ELOOP => return error.SymLinkLoop,1613 .LOOP => return error.SymLinkLoop,
1613 ENAMETOOLONG => return error.NameTooLong,1614 .NAMETOOLONG => return error.NameTooLong,
1614 ENOENT => return error.FileNotFound,1615 .NOENT => return error.FileNotFound,
1615 ENOTDIR => return error.NotDir,1616 .NOTDIR => return error.NotDir,
1616 ENOMEM => return error.SystemResources,1617 .NOMEM => return error.SystemResources,
1617 ENOSPC => return error.NoSpaceLeft,1618 .NOSPC => return error.NoSpaceLeft,
1618 EROFS => return error.ReadOnlyFileSystem,1619 .ROFS => return error.ReadOnlyFileSystem,
1619 else => |err| return unexpectedErrno(err),1620 else => |err| return unexpectedErrno(err),
1620 }1621 }
1621}1622}
...@@ -1644,22 +1645,22 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");...@@ -1644,22 +1645,22 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
1644/// See also `symlinkat`.1645/// See also `symlinkat`.
1645pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {1646pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
1646 switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) {1647 switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) {
1647 wasi.ESUCCESS => {},1648 .SUCCESS => {},
1648 wasi.EFAULT => unreachable,1649 .FAULT => unreachable,
1649 wasi.EINVAL => unreachable,1650 .INVAL => unreachable,
1650 wasi.EACCES => return error.AccessDenied,1651 .ACCES => return error.AccessDenied,
1651 wasi.EPERM => return error.AccessDenied,1652 .PERM => return error.AccessDenied,
1652 wasi.EDQUOT => return error.DiskQuota,1653 .DQUOT => return error.DiskQuota,
1653 wasi.EEXIST => return error.PathAlreadyExists,1654 .EXIST => return error.PathAlreadyExists,
1654 wasi.EIO => return error.FileSystem,1655 .IO => return error.FileSystem,
1655 wasi.ELOOP => return error.SymLinkLoop,1656 .LOOP => return error.SymLinkLoop,
1656 wasi.ENAMETOOLONG => return error.NameTooLong,1657 .NAMETOOLONG => return error.NameTooLong,
1657 wasi.ENOENT => return error.FileNotFound,1658 .NOENT => return error.FileNotFound,
1658 wasi.ENOTDIR => return error.NotDir,1659 .NOTDIR => return error.NotDir,
1659 wasi.ENOMEM => return error.SystemResources,1660 .NOMEM => return error.SystemResources,
1660 wasi.ENOSPC => return error.NoSpaceLeft,1661 .NOSPC => return error.NoSpaceLeft,
1661 wasi.EROFS => return error.ReadOnlyFileSystem,1662 .ROFS => return error.ReadOnlyFileSystem,
1662 wasi.ENOTCAPABLE => return error.AccessDenied,1663 .NOTCAPABLE => return error.AccessDenied,
1663 else => |err| return unexpectedErrno(err),1664 else => |err| return unexpectedErrno(err),
1664 }1665 }
1665}1666}
...@@ -1671,21 +1672,21 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:...@@ -1671,21 +1672,21 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:
1671 @compileError("symlinkat is not supported on Windows; use std.os.windows.CreateSymbolicLink instead");1672 @compileError("symlinkat is not supported on Windows; use std.os.windows.CreateSymbolicLink instead");
1672 }1673 }
1673 switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) {1674 switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) {
1674 0 => return,1675 .SUCCESS => return,
1675 EFAULT => unreachable,1676 .FAULT => unreachable,
1676 EINVAL => unreachable,1677 .INVAL => unreachable,
1677 EACCES => return error.AccessDenied,1678 .ACCES => return error.AccessDenied,
1678 EPERM => return error.AccessDenied,1679 .PERM => return error.AccessDenied,
1679 EDQUOT => return error.DiskQuota,1680 .DQUOT => return error.DiskQuota,
1680 EEXIST => return error.PathAlreadyExists,1681 .EXIST => return error.PathAlreadyExists,
1681 EIO => return error.FileSystem,1682 .IO => return error.FileSystem,
1682 ELOOP => return error.SymLinkLoop,1683 .LOOP => return error.SymLinkLoop,
1683 ENAMETOOLONG => return error.NameTooLong,1684 .NAMETOOLONG => return error.NameTooLong,
1684 ENOENT => return error.FileNotFound,1685 .NOENT => return error.FileNotFound,
1685 ENOTDIR => return error.NotDir,1686 .NOTDIR => return error.NotDir,
1686 ENOMEM => return error.SystemResources,1687 .NOMEM => return error.SystemResources,
1687 ENOSPC => return error.NoSpaceLeft,1688 .NOSPC => return error.NoSpaceLeft,
1688 EROFS => return error.ReadOnlyFileSystem,1689 .ROFS => return error.ReadOnlyFileSystem,
1689 else => |err| return unexpectedErrno(err),1690 else => |err| return unexpectedErrno(err),
1690 }1691 }
1691}1692}
...@@ -1707,22 +1708,22 @@ pub const LinkError = UnexpectedError || error{...@@ -1707,22 +1708,22 @@ pub const LinkError = UnexpectedError || error{
17071708
1708pub fn linkZ(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) LinkError!void {1709pub fn linkZ(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) LinkError!void {
1709 switch (errno(system.link(oldpath, newpath, flags))) {1710 switch (errno(system.link(oldpath, newpath, flags))) {
1710 0 => return,1711 .SUCCESS => return,
1711 EACCES => return error.AccessDenied,1712 .ACCES => return error.AccessDenied,
1712 EDQUOT => return error.DiskQuota,1713 .DQUOT => return error.DiskQuota,
1713 EEXIST => return error.PathAlreadyExists,1714 .EXIST => return error.PathAlreadyExists,
1714 EFAULT => unreachable,1715 .FAULT => unreachable,
1715 EIO => return error.FileSystem,1716 .IO => return error.FileSystem,
1716 ELOOP => return error.SymLinkLoop,1717 .LOOP => return error.SymLinkLoop,
1717 EMLINK => return error.LinkQuotaExceeded,1718 .MLINK => return error.LinkQuotaExceeded,
1718 ENAMETOOLONG => return error.NameTooLong,1719 .NAMETOOLONG => return error.NameTooLong,
1719 ENOENT => return error.FileNotFound,1720 .NOENT => return error.FileNotFound,
1720 ENOMEM => return error.SystemResources,1721 .NOMEM => return error.SystemResources,
1721 ENOSPC => return error.NoSpaceLeft,1722 .NOSPC => return error.NoSpaceLeft,
1722 EPERM => return error.AccessDenied,1723 .PERM => return error.AccessDenied,
1723 EROFS => return error.ReadOnlyFileSystem,1724 .ROFS => return error.ReadOnlyFileSystem,
1724 EXDEV => return error.NotSameFileSystem,1725 .XDEV => return error.NotSameFileSystem,
1725 EINVAL => unreachable,1726 .INVAL => unreachable,
1726 else => |err| return unexpectedErrno(err),1727 else => |err| return unexpectedErrno(err),
1727 }1728 }
1728}1729}
...@@ -1743,23 +1744,23 @@ pub fn linkatZ(...@@ -1743,23 +1744,23 @@ pub fn linkatZ(
1743 flags: i32,1744 flags: i32,
1744) LinkatError!void {1745) LinkatError!void {
1745 switch (errno(system.linkat(olddir, oldpath, newdir, newpath, flags))) {1746 switch (errno(system.linkat(olddir, oldpath, newdir, newpath, flags))) {
1746 0 => return,1747 .SUCCESS => return,
1747 EACCES => return error.AccessDenied,1748 .ACCES => return error.AccessDenied,
1748 EDQUOT => return error.DiskQuota,1749 .DQUOT => return error.DiskQuota,
1749 EEXIST => return error.PathAlreadyExists,1750 .EXIST => return error.PathAlreadyExists,
1750 EFAULT => unreachable,1751 .FAULT => unreachable,
1751 EIO => return error.FileSystem,1752 .IO => return error.FileSystem,
1752 ELOOP => return error.SymLinkLoop,1753 .LOOP => return error.SymLinkLoop,
1753 EMLINK => return error.LinkQuotaExceeded,1754 .MLINK => return error.LinkQuotaExceeded,
1754 ENAMETOOLONG => return error.NameTooLong,1755 .NAMETOOLONG => return error.NameTooLong,
1755 ENOENT => return error.FileNotFound,1756 .NOENT => return error.FileNotFound,
1756 ENOMEM => return error.SystemResources,1757 .NOMEM => return error.SystemResources,
1757 ENOSPC => return error.NoSpaceLeft,1758 .NOSPC => return error.NoSpaceLeft,
1758 ENOTDIR => return error.NotDir,1759 .NOTDIR => return error.NotDir,
1759 EPERM => return error.AccessDenied,1760 .PERM => return error.AccessDenied,
1760 EROFS => return error.ReadOnlyFileSystem,1761 .ROFS => return error.ReadOnlyFileSystem,
1761 EXDEV => return error.NotSameFileSystem,1762 .XDEV => return error.NotSameFileSystem,
1762 EINVAL => unreachable,1763 .INVAL => unreachable,
1763 else => |err| return unexpectedErrno(err),1764 else => |err| return unexpectedErrno(err),
1764 }1765 }
1765}1766}
...@@ -1822,20 +1823,20 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {...@@ -1822,20 +1823,20 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
1822 return unlinkW(file_path_w.span());1823 return unlinkW(file_path_w.span());
1823 }1824 }
1824 switch (errno(system.unlink(file_path))) {1825 switch (errno(system.unlink(file_path))) {
1825 0 => return,1826 .SUCCESS => return,
1826 EACCES => return error.AccessDenied,1827 .ACCES => return error.AccessDenied,
1827 EPERM => return error.AccessDenied,1828 .PERM => return error.AccessDenied,
1828 EBUSY => return error.FileBusy,1829 .BUSY => return error.FileBusy,
1829 EFAULT => unreachable,1830 .FAULT => unreachable,
1830 EINVAL => unreachable,1831 .INVAL => unreachable,
1831 EIO => return error.FileSystem,1832 .IO => return error.FileSystem,
1832 EISDIR => return error.IsDir,1833 .ISDIR => return error.IsDir,
1833 ELOOP => return error.SymLinkLoop,1834 .LOOP => return error.SymLinkLoop,
1834 ENAMETOOLONG => return error.NameTooLong,1835 .NAMETOOLONG => return error.NameTooLong,
1835 ENOENT => return error.FileNotFound,1836 .NOENT => return error.FileNotFound,
1836 ENOTDIR => return error.NotDir,1837 .NOTDIR => return error.NotDir,
1837 ENOMEM => return error.SystemResources,1838 .NOMEM => return error.SystemResources,
1838 EROFS => return error.ReadOnlyFileSystem,1839 .ROFS => return error.ReadOnlyFileSystem,
1839 else => |err| return unexpectedErrno(err),1840 else => |err| return unexpectedErrno(err),
1840 }1841 }
1841}1842}
...@@ -1875,24 +1876,24 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro...@@ -1875,24 +1876,24 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro
1875 else1876 else
1876 wasi.path_unlink_file(dirfd, file_path.ptr, file_path.len);1877 wasi.path_unlink_file(dirfd, file_path.ptr, file_path.len);
1877 switch (res) {1878 switch (res) {
1878 wasi.ESUCCESS => return,1879 .SUCCESS => return,
1879 wasi.EACCES => return error.AccessDenied,1880 .ACCES => return error.AccessDenied,
1880 wasi.EPERM => return error.AccessDenied,1881 .PERM => return error.AccessDenied,
1881 wasi.EBUSY => return error.FileBusy,1882 .BUSY => return error.FileBusy,
1882 wasi.EFAULT => unreachable,1883 .FAULT => unreachable,
1883 wasi.EIO => return error.FileSystem,1884 .IO => return error.FileSystem,
1884 wasi.EISDIR => return error.IsDir,1885 .ISDIR => return error.IsDir,
1885 wasi.ELOOP => return error.SymLinkLoop,1886 .LOOP => return error.SymLinkLoop,
1886 wasi.ENAMETOOLONG => return error.NameTooLong,1887 .NAMETOOLONG => return error.NameTooLong,
1887 wasi.ENOENT => return error.FileNotFound,1888 .NOENT => return error.FileNotFound,
1888 wasi.ENOTDIR => return error.NotDir,1889 .NOTDIR => return error.NotDir,
1889 wasi.ENOMEM => return error.SystemResources,1890 .NOMEM => return error.SystemResources,
1890 wasi.EROFS => return error.ReadOnlyFileSystem,1891 .ROFS => return error.ReadOnlyFileSystem,
1891 wasi.ENOTEMPTY => return error.DirNotEmpty,1892 .NOTEMPTY => return error.DirNotEmpty,
1892 wasi.ENOTCAPABLE => return error.AccessDenied,1893 .NOTCAPABLE => return error.AccessDenied,
18931894
1894 wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component1895 .INVAL => unreachable, // invalid flags, or pathname has . as last component
1895 wasi.EBADF => unreachable, // always a race condition1896 .BADF => unreachable, // always a race condition
18961897
1897 else => |err| return unexpectedErrno(err),1898 else => |err| return unexpectedErrno(err),
1898 }1899 }
...@@ -1905,23 +1906,23 @@ pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatEr...@@ -1905,23 +1906,23 @@ pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatEr
1905 return unlinkatW(dirfd, file_path_w.span(), flags);1906 return unlinkatW(dirfd, file_path_w.span(), flags);
1906 }1907 }
1907 switch (errno(system.unlinkat(dirfd, file_path_c, flags))) {1908 switch (errno(system.unlinkat(dirfd, file_path_c, flags))) {
1908 0 => return,1909 .SUCCESS => return,
1909 EACCES => return error.AccessDenied,1910 .ACCES => return error.AccessDenied,
1910 EPERM => return error.AccessDenied,1911 .PERM => return error.AccessDenied,
1911 EBUSY => return error.FileBusy,1912 .BUSY => return error.FileBusy,
1912 EFAULT => unreachable,1913 .FAULT => unreachable,
1913 EIO => return error.FileSystem,1914 .IO => return error.FileSystem,
1914 EISDIR => return error.IsDir,1915 .ISDIR => return error.IsDir,
1915 ELOOP => return error.SymLinkLoop,1916 .LOOP => return error.SymLinkLoop,
1916 ENAMETOOLONG => return error.NameTooLong,1917 .NAMETOOLONG => return error.NameTooLong,
1917 ENOENT => return error.FileNotFound,1918 .NOENT => return error.FileNotFound,
1918 ENOTDIR => return error.NotDir,1919 .NOTDIR => return error.NotDir,
1919 ENOMEM => return error.SystemResources,1920 .NOMEM => return error.SystemResources,
1920 EROFS => return error.ReadOnlyFileSystem,1921 .ROFS => return error.ReadOnlyFileSystem,
1921 ENOTEMPTY => return error.DirNotEmpty,1922 .NOTEMPTY => return error.DirNotEmpty,
19221923
1923 EINVAL => unreachable, // invalid flags, or pathname has . as last component1924 .INVAL => unreachable, // invalid flags, or pathname has . as last component
1924 EBADF => unreachable, // always a race condition1925 .BADF => unreachable, // always a race condition
19251926
1926 else => |err| return unexpectedErrno(err),1927 else => |err| return unexpectedErrno(err),
1927 }1928 }
...@@ -1982,25 +1983,25 @@ pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!voi...@@ -1982,25 +1983,25 @@ pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!voi
1982 return renameW(old_path_w.span().ptr, new_path_w.span().ptr);1983 return renameW(old_path_w.span().ptr, new_path_w.span().ptr);
1983 }1984 }
1984 switch (errno(system.rename(old_path, new_path))) {1985 switch (errno(system.rename(old_path, new_path))) {
1985 0 => return,1986 .SUCCESS => return,
1986 EACCES => return error.AccessDenied,1987 .ACCES => return error.AccessDenied,
1987 EPERM => return error.AccessDenied,1988 .PERM => return error.AccessDenied,
1988 EBUSY => return error.FileBusy,1989 .BUSY => return error.FileBusy,
1989 EDQUOT => return error.DiskQuota,1990 .DQUOT => return error.DiskQuota,
1990 EFAULT => unreachable,1991 .FAULT => unreachable,
1991 EINVAL => unreachable,1992 .INVAL => unreachable,
1992 EISDIR => return error.IsDir,1993 .ISDIR => return error.IsDir,
1993 ELOOP => return error.SymLinkLoop,1994 .LOOP => return error.SymLinkLoop,
1994 EMLINK => return error.LinkQuotaExceeded,1995 .MLINK => return error.LinkQuotaExceeded,
1995 ENAMETOOLONG => return error.NameTooLong,1996 .NAMETOOLONG => return error.NameTooLong,
1996 ENOENT => return error.FileNotFound,1997 .NOENT => return error.FileNotFound,
1997 ENOTDIR => return error.NotDir,1998 .NOTDIR => return error.NotDir,
1998 ENOMEM => return error.SystemResources,1999 .NOMEM => return error.SystemResources,
1999 ENOSPC => return error.NoSpaceLeft,2000 .NOSPC => return error.NoSpaceLeft,
2000 EEXIST => return error.PathAlreadyExists,2001 .EXIST => return error.PathAlreadyExists,
2001 ENOTEMPTY => return error.PathAlreadyExists,2002 .NOTEMPTY => return error.PathAlreadyExists,
2002 EROFS => return error.ReadOnlyFileSystem,2003 .ROFS => return error.ReadOnlyFileSystem,
2003 EXDEV => return error.RenameAcrossMountPoints,2004 .XDEV => return error.RenameAcrossMountPoints,
2004 else => |err| return unexpectedErrno(err),2005 else => |err| return unexpectedErrno(err),
2005 }2006 }
2006}2007}
...@@ -2036,26 +2037,26 @@ pub fn renameat(...@@ -2036,26 +2037,26 @@ pub fn renameat(
2036/// See also `renameat`.2037/// See also `renameat`.
2037pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void {2038pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void {
2038 switch (wasi.path_rename(old_dir_fd, old_path.ptr, old_path.len, new_dir_fd, new_path.ptr, new_path.len)) {2039 switch (wasi.path_rename(old_dir_fd, old_path.ptr, old_path.len, new_dir_fd, new_path.ptr, new_path.len)) {
2039 wasi.ESUCCESS => return,2040 .SUCCESS => return,
2040 wasi.EACCES => return error.AccessDenied,2041 .ACCES => return error.AccessDenied,
2041 wasi.EPERM => return error.AccessDenied,2042 .PERM => return error.AccessDenied,
2042 wasi.EBUSY => return error.FileBusy,2043 .BUSY => return error.FileBusy,
2043 wasi.EDQUOT => return error.DiskQuota,2044 .DQUOT => return error.DiskQuota,
2044 wasi.EFAULT => unreachable,2045 .FAULT => unreachable,
2045 wasi.EINVAL => unreachable,2046 .INVAL => unreachable,
2046 wasi.EISDIR => return error.IsDir,2047 .ISDIR => return error.IsDir,
2047 wasi.ELOOP => return error.SymLinkLoop,2048 .LOOP => return error.SymLinkLoop,
2048 wasi.EMLINK => return error.LinkQuotaExceeded,2049 .MLINK => return error.LinkQuotaExceeded,
2049 wasi.ENAMETOOLONG => return error.NameTooLong,2050 .NAMETOOLONG => return error.NameTooLong,
2050 wasi.ENOENT => return error.FileNotFound,2051 .NOENT => return error.FileNotFound,
2051 wasi.ENOTDIR => return error.NotDir,2052 .NOTDIR => return error.NotDir,
2052 wasi.ENOMEM => return error.SystemResources,2053 .NOMEM => return error.SystemResources,
2053 wasi.ENOSPC => return error.NoSpaceLeft,2054 .NOSPC => return error.NoSpaceLeft,
2054 wasi.EEXIST => return error.PathAlreadyExists,2055 .EXIST => return error.PathAlreadyExists,
2055 wasi.ENOTEMPTY => return error.PathAlreadyExists,2056 .NOTEMPTY => return error.PathAlreadyExists,
2056 wasi.EROFS => return error.ReadOnlyFileSystem,2057 .ROFS => return error.ReadOnlyFileSystem,
2057 wasi.EXDEV => return error.RenameAcrossMountPoints,2058 .XDEV => return error.RenameAcrossMountPoints,
2058 wasi.ENOTCAPABLE => return error.AccessDenied,2059 .NOTCAPABLE => return error.AccessDenied,
2059 else => |err| return unexpectedErrno(err),2060 else => |err| return unexpectedErrno(err),
2060 }2061 }
2061}2062}
...@@ -2074,25 +2075,25 @@ pub fn renameatZ(...@@ -2074,25 +2075,25 @@ pub fn renameatZ(
2074 }2075 }
20752076
2076 switch (errno(system.renameat(old_dir_fd, old_path, new_dir_fd, new_path))) {2077 switch (errno(system.renameat(old_dir_fd, old_path, new_dir_fd, new_path))) {
2077 0 => return,2078 .SUCCESS => return,
2078 EACCES => return error.AccessDenied,2079 .ACCES => return error.AccessDenied,
2079 EPERM => return error.AccessDenied,2080 .PERM => return error.AccessDenied,
2080 EBUSY => return error.FileBusy,2081 .BUSY => return error.FileBusy,
2081 EDQUOT => return error.DiskQuota,2082 .DQUOT => return error.DiskQuota,
2082 EFAULT => unreachable,2083 .FAULT => unreachable,
2083 EINVAL => unreachable,2084 .INVAL => unreachable,
2084 EISDIR => return error.IsDir,2085 .ISDIR => return error.IsDir,
2085 ELOOP => return error.SymLinkLoop,2086 .LOOP => return error.SymLinkLoop,
2086 EMLINK => return error.LinkQuotaExceeded,2087 .MLINK => return error.LinkQuotaExceeded,
2087 ENAMETOOLONG => return error.NameTooLong,2088 .NAMETOOLONG => return error.NameTooLong,
2088 ENOENT => return error.FileNotFound,2089 .NOENT => return error.FileNotFound,
2089 ENOTDIR => return error.NotDir,2090 .NOTDIR => return error.NotDir,
2090 ENOMEM => return error.SystemResources,2091 .NOMEM => return error.SystemResources,
2091 ENOSPC => return error.NoSpaceLeft,2092 .NOSPC => return error.NoSpaceLeft,
2092 EEXIST => return error.PathAlreadyExists,2093 .EXIST => return error.PathAlreadyExists,
2093 ENOTEMPTY => return error.PathAlreadyExists,2094 .NOTEMPTY => return error.PathAlreadyExists,
2094 EROFS => return error.ReadOnlyFileSystem,2095 .ROFS => return error.ReadOnlyFileSystem,
2095 EXDEV => return error.RenameAcrossMountPoints,2096 .XDEV => return error.RenameAcrossMountPoints,
2096 else => |err| return unexpectedErrno(err),2097 else => |err| return unexpectedErrno(err),
2097 }2098 }
2098}2099}
...@@ -2172,22 +2173,22 @@ pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");...@@ -2172,22 +2173,22 @@ pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
2172pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {2173pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
2173 _ = mode;2174 _ = mode;
2174 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {2175 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {
2175 wasi.ESUCCESS => return,2176 .SUCCESS => return,
2176 wasi.EACCES => return error.AccessDenied,2177 .ACCES => return error.AccessDenied,
2177 wasi.EBADF => unreachable,2178 .BADF => unreachable,
2178 wasi.EPERM => return error.AccessDenied,2179 .PERM => return error.AccessDenied,
2179 wasi.EDQUOT => return error.DiskQuota,2180 .DQUOT => return error.DiskQuota,
2180 wasi.EEXIST => return error.PathAlreadyExists,2181 .EXIST => return error.PathAlreadyExists,
2181 wasi.EFAULT => unreachable,2182 .FAULT => unreachable,
2182 wasi.ELOOP => return error.SymLinkLoop,2183 .LOOP => return error.SymLinkLoop,
2183 wasi.EMLINK => return error.LinkQuotaExceeded,2184 .MLINK => return error.LinkQuotaExceeded,
2184 wasi.ENAMETOOLONG => return error.NameTooLong,2185 .NAMETOOLONG => return error.NameTooLong,
2185 wasi.ENOENT => return error.FileNotFound,2186 .NOENT => return error.FileNotFound,
2186 wasi.ENOMEM => return error.SystemResources,2187 .NOMEM => return error.SystemResources,
2187 wasi.ENOSPC => return error.NoSpaceLeft,2188 .NOSPC => return error.NoSpaceLeft,
2188 wasi.ENOTDIR => return error.NotDir,2189 .NOTDIR => return error.NotDir,
2189 wasi.EROFS => return error.ReadOnlyFileSystem,2190 .ROFS => return error.ReadOnlyFileSystem,
2190 wasi.ENOTCAPABLE => return error.AccessDenied,2191 .NOTCAPABLE => return error.AccessDenied,
2191 else => |err| return unexpectedErrno(err),2192 else => |err| return unexpectedErrno(err),
2192 }2193 }
2193}2194}
...@@ -2198,21 +2199,21 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirErr...@@ -2198,21 +2199,21 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirErr
2198 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);2199 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);
2199 }2200 }
2200 switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) {2201 switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) {
2201 0 => return,2202 .SUCCESS => return,
2202 EACCES => return error.AccessDenied,2203 .ACCES => return error.AccessDenied,
2203 EBADF => unreachable,2204 .BADF => unreachable,
2204 EPERM => return error.AccessDenied,2205 .PERM => return error.AccessDenied,
2205 EDQUOT => return error.DiskQuota,2206 .DQUOT => return error.DiskQuota,
2206 EEXIST => return error.PathAlreadyExists,2207 .EXIST => return error.PathAlreadyExists,
2207 EFAULT => unreachable,2208 .FAULT => unreachable,
2208 ELOOP => return error.SymLinkLoop,2209 .LOOP => return error.SymLinkLoop,
2209 EMLINK => return error.LinkQuotaExceeded,2210 .MLINK => return error.LinkQuotaExceeded,
2210 ENAMETOOLONG => return error.NameTooLong,2211 .NAMETOOLONG => return error.NameTooLong,
2211 ENOENT => return error.FileNotFound,2212 .NOENT => return error.FileNotFound,
2212 ENOMEM => return error.SystemResources,2213 .NOMEM => return error.SystemResources,
2213 ENOSPC => return error.NoSpaceLeft,2214 .NOSPC => return error.NoSpaceLeft,
2214 ENOTDIR => return error.NotDir,2215 .NOTDIR => return error.NotDir,
2215 EROFS => return error.ReadOnlyFileSystem,2216 .ROFS => return error.ReadOnlyFileSystem,
2216 else => |err| return unexpectedErrno(err),2217 else => |err| return unexpectedErrno(err),
2217 }2218 }
2218}2219}
...@@ -2274,20 +2275,20 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: u32) MakeDirError!void {...@@ -2274,20 +2275,20 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
2274 return mkdirW(dir_path_w.span(), mode);2275 return mkdirW(dir_path_w.span(), mode);
2275 }2276 }
2276 switch (errno(system.mkdir(dir_path, mode))) {2277 switch (errno(system.mkdir(dir_path, mode))) {
2277 0 => return,2278 .SUCCESS => return,
2278 EACCES => return error.AccessDenied,2279 .ACCES => return error.AccessDenied,
2279 EPERM => return error.AccessDenied,2280 .PERM => return error.AccessDenied,
2280 EDQUOT => return error.DiskQuota,2281 .DQUOT => return error.DiskQuota,
2281 EEXIST => return error.PathAlreadyExists,2282 .EXIST => return error.PathAlreadyExists,
2282 EFAULT => unreachable,2283 .FAULT => unreachable,
2283 ELOOP => return error.SymLinkLoop,2284 .LOOP => return error.SymLinkLoop,
2284 EMLINK => return error.LinkQuotaExceeded,2285 .MLINK => return error.LinkQuotaExceeded,
2285 ENAMETOOLONG => return error.NameTooLong,2286 .NAMETOOLONG => return error.NameTooLong,
2286 ENOENT => return error.FileNotFound,2287 .NOENT => return error.FileNotFound,
2287 ENOMEM => return error.SystemResources,2288 .NOMEM => return error.SystemResources,
2288 ENOSPC => return error.NoSpaceLeft,2289 .NOSPC => return error.NoSpaceLeft,
2289 ENOTDIR => return error.NotDir,2290 .NOTDIR => return error.NotDir,
2290 EROFS => return error.ReadOnlyFileSystem,2291 .ROFS => return error.ReadOnlyFileSystem,
2291 else => |err| return unexpectedErrno(err),2292 else => |err| return unexpectedErrno(err),
2292 }2293 }
2293}2294}
...@@ -2346,20 +2347,20 @@ pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {...@@ -2346,20 +2347,20 @@ pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {
2346 return rmdirW(dir_path_w.span());2347 return rmdirW(dir_path_w.span());
2347 }2348 }
2348 switch (errno(system.rmdir(dir_path))) {2349 switch (errno(system.rmdir(dir_path))) {
2349 0 => return,2350 .SUCCESS => return,
2350 EACCES => return error.AccessDenied,2351 .ACCES => return error.AccessDenied,
2351 EPERM => return error.AccessDenied,2352 .PERM => return error.AccessDenied,
2352 EBUSY => return error.FileBusy,2353 .BUSY => return error.FileBusy,
2353 EFAULT => unreachable,2354 .FAULT => unreachable,
2354 EINVAL => unreachable,2355 .INVAL => unreachable,
2355 ELOOP => return error.SymLinkLoop,2356 .LOOP => return error.SymLinkLoop,
2356 ENAMETOOLONG => return error.NameTooLong,2357 .NAMETOOLONG => return error.NameTooLong,
2357 ENOENT => return error.FileNotFound,2358 .NOENT => return error.FileNotFound,
2358 ENOMEM => return error.SystemResources,2359 .NOMEM => return error.SystemResources,
2359 ENOTDIR => return error.NotDir,2360 .NOTDIR => return error.NotDir,
2360 EEXIST => return error.DirNotEmpty,2361 .EXIST => return error.DirNotEmpty,
2361 ENOTEMPTY => return error.DirNotEmpty,2362 .NOTEMPTY => return error.DirNotEmpty,
2362 EROFS => return error.ReadOnlyFileSystem,2363 .ROFS => return error.ReadOnlyFileSystem,
2363 else => |err| return unexpectedErrno(err),2364 else => |err| return unexpectedErrno(err),
2364 }2365 }
2365}2366}
...@@ -2413,15 +2414,15 @@ pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {...@@ -2413,15 +2414,15 @@ pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {
2413 return chdirW(utf16_dir_path[0..len]);2414 return chdirW(utf16_dir_path[0..len]);
2414 }2415 }
2415 switch (errno(system.chdir(dir_path))) {2416 switch (errno(system.chdir(dir_path))) {
2416 0 => return,2417 .SUCCESS => return,
2417 EACCES => return error.AccessDenied,2418 .ACCES => return error.AccessDenied,
2418 EFAULT => unreachable,2419 .FAULT => unreachable,
2419 EIO => return error.FileSystem,2420 .IO => return error.FileSystem,
2420 ELOOP => return error.SymLinkLoop,2421 .LOOP => return error.SymLinkLoop,
2421 ENAMETOOLONG => return error.NameTooLong,2422 .NAMETOOLONG => return error.NameTooLong,
2422 ENOENT => return error.FileNotFound,2423 .NOENT => return error.FileNotFound,
2423 ENOMEM => return error.SystemResources,2424 .NOMEM => return error.SystemResources,
2424 ENOTDIR => return error.NotDir,2425 .NOTDIR => return error.NotDir,
2425 else => |err| return unexpectedErrno(err),2426 else => |err| return unexpectedErrno(err),
2426 }2427 }
2427}2428}
...@@ -2443,12 +2444,12 @@ pub const FchdirError = error{...@@ -2443,12 +2444,12 @@ pub const FchdirError = error{
2443pub fn fchdir(dirfd: fd_t) FchdirError!void {2444pub fn fchdir(dirfd: fd_t) FchdirError!void {
2444 while (true) {2445 while (true) {
2445 switch (errno(system.fchdir(dirfd))) {2446 switch (errno(system.fchdir(dirfd))) {
2446 0 => return,2447 .SUCCESS => return,
2447 EACCES => return error.AccessDenied,2448 .ACCES => return error.AccessDenied,
2448 EBADF => unreachable,2449 .BADF => unreachable,
2449 ENOTDIR => return error.NotDir,2450 .NOTDIR => return error.NotDir,
2450 EINTR => continue,2451 .INTR => continue,
2451 EIO => return error.FileSystem,2452 .IO => return error.FileSystem,
2452 else => |err| return unexpectedErrno(err),2453 else => |err| return unexpectedErrno(err),
2453 }2454 }
2454 }2455 }
...@@ -2501,16 +2502,16 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8...@@ -2501,16 +2502,16 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
2501 }2502 }
2502 const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len);2503 const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len);
2503 switch (errno(rc)) {2504 switch (errno(rc)) {
2504 0 => return out_buffer[0..@bitCast(usize, rc)],2505 .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
2505 EACCES => return error.AccessDenied,2506 .ACCES => return error.AccessDenied,
2506 EFAULT => unreachable,2507 .FAULT => unreachable,
2507 EINVAL => unreachable,2508 .INVAL => unreachable,
2508 EIO => return error.FileSystem,2509 .IO => return error.FileSystem,
2509 ELOOP => return error.SymLinkLoop,2510 .LOOP => return error.SymLinkLoop,
2510 ENAMETOOLONG => return error.NameTooLong,2511 .NAMETOOLONG => return error.NameTooLong,
2511 ENOENT => return error.FileNotFound,2512 .NOENT => return error.FileNotFound,
2512 ENOMEM => return error.SystemResources,2513 .NOMEM => return error.SystemResources,
2513 ENOTDIR => return error.NotDir,2514 .NOTDIR => return error.NotDir,
2514 else => |err| return unexpectedErrno(err),2515 else => |err| return unexpectedErrno(err),
2515 }2516 }
2516}2517}
...@@ -2537,17 +2538,17 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");...@@ -2537,17 +2538,17 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
2537pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {2538pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
2538 var bufused: usize = undefined;2539 var bufused: usize = undefined;
2539 switch (wasi.path_readlink(dirfd, file_path.ptr, file_path.len, out_buffer.ptr, out_buffer.len, &bufused)) {2540 switch (wasi.path_readlink(dirfd, file_path.ptr, file_path.len, out_buffer.ptr, out_buffer.len, &bufused)) {
2540 wasi.ESUCCESS => return out_buffer[0..bufused],2541 .SUCCESS => return out_buffer[0..bufused],
2541 wasi.EACCES => return error.AccessDenied,2542 .ACCES => return error.AccessDenied,
2542 wasi.EFAULT => unreachable,2543 .FAULT => unreachable,
2543 wasi.EINVAL => unreachable,2544 .INVAL => unreachable,
2544 wasi.EIO => return error.FileSystem,2545 .IO => return error.FileSystem,
2545 wasi.ELOOP => return error.SymLinkLoop,2546 .LOOP => return error.SymLinkLoop,
2546 wasi.ENAMETOOLONG => return error.NameTooLong,2547 .NAMETOOLONG => return error.NameTooLong,
2547 wasi.ENOENT => return error.FileNotFound,2548 .NOENT => return error.FileNotFound,
2548 wasi.ENOMEM => return error.SystemResources,2549 .NOMEM => return error.SystemResources,
2549 wasi.ENOTDIR => return error.NotDir,2550 .NOTDIR => return error.NotDir,
2550 wasi.ENOTCAPABLE => return error.AccessDenied,2551 .NOTCAPABLE => return error.AccessDenied,
2551 else => |err| return unexpectedErrno(err),2552 else => |err| return unexpectedErrno(err),
2552 }2553 }
2553}2554}
...@@ -2567,16 +2568,16 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read...@@ -2567,16 +2568,16 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read
2567 }2568 }
2568 const rc = system.readlinkat(dirfd, file_path, out_buffer.ptr, out_buffer.len);2569 const rc = system.readlinkat(dirfd, file_path, out_buffer.ptr, out_buffer.len);
2569 switch (errno(rc)) {2570 switch (errno(rc)) {
2570 0 => return out_buffer[0..@bitCast(usize, rc)],2571 .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
2571 EACCES => return error.AccessDenied,2572 .ACCES => return error.AccessDenied,
2572 EFAULT => unreachable,2573 .FAULT => unreachable,
2573 EINVAL => unreachable,2574 .INVAL => unreachable,
2574 EIO => return error.FileSystem,2575 .IO => return error.FileSystem,
2575 ELOOP => return error.SymLinkLoop,2576 .LOOP => return error.SymLinkLoop,
2576 ENAMETOOLONG => return error.NameTooLong,2577 .NAMETOOLONG => return error.NameTooLong,
2577 ENOENT => return error.FileNotFound,2578 .NOENT => return error.FileNotFound,
2578 ENOMEM => return error.SystemResources,2579 .NOMEM => return error.SystemResources,
2579 ENOTDIR => return error.NotDir,2580 .NOTDIR => return error.NotDir,
2580 else => |err| return unexpectedErrno(err),2581 else => |err| return unexpectedErrno(err),
2581 }2582 }
2582}2583}
...@@ -2590,58 +2591,58 @@ pub const SetIdError = error{ResourceLimitReached} || SetEidError;...@@ -2590,58 +2591,58 @@ pub const SetIdError = error{ResourceLimitReached} || SetEidError;
25902591
2591pub fn setuid(uid: uid_t) SetIdError!void {2592pub fn setuid(uid: uid_t) SetIdError!void {
2592 switch (errno(system.setuid(uid))) {2593 switch (errno(system.setuid(uid))) {
2593 0 => return,2594 .SUCCESS => return,
2594 EAGAIN => return error.ResourceLimitReached,2595 .AGAIN => return error.ResourceLimitReached,
2595 EINVAL => return error.InvalidUserId,2596 .INVAL => return error.InvalidUserId,
2596 EPERM => return error.PermissionDenied,2597 .PERM => return error.PermissionDenied,
2597 else => |err| return unexpectedErrno(err),2598 else => |err| return unexpectedErrno(err),
2598 }2599 }
2599}2600}
26002601
2601pub fn seteuid(uid: uid_t) SetEidError!void {2602pub fn seteuid(uid: uid_t) SetEidError!void {
2602 switch (errno(system.seteuid(uid))) {2603 switch (errno(system.seteuid(uid))) {
2603 0 => return,2604 .SUCCESS => return,
2604 EINVAL => return error.InvalidUserId,2605 .INVAL => return error.InvalidUserId,
2605 EPERM => return error.PermissionDenied,2606 .PERM => return error.PermissionDenied,
2606 else => |err| return unexpectedErrno(err),2607 else => |err| return unexpectedErrno(err),
2607 }2608 }
2608}2609}
26092610
2610pub fn setreuid(ruid: uid_t, euid: uid_t) SetIdError!void {2611pub fn setreuid(ruid: uid_t, euid: uid_t) SetIdError!void {
2611 switch (errno(system.setreuid(ruid, euid))) {2612 switch (errno(system.setreuid(ruid, euid))) {
2612 0 => return,2613 .SUCCESS => return,
2613 EAGAIN => return error.ResourceLimitReached,2614 .AGAIN => return error.ResourceLimitReached,
2614 EINVAL => return error.InvalidUserId,2615 .INVAL => return error.InvalidUserId,
2615 EPERM => return error.PermissionDenied,2616 .PERM => return error.PermissionDenied,
2616 else => |err| return unexpectedErrno(err),2617 else => |err| return unexpectedErrno(err),
2617 }2618 }
2618}2619}
26192620
2620pub fn setgid(gid: gid_t) SetIdError!void {2621pub fn setgid(gid: gid_t) SetIdError!void {
2621 switch (errno(system.setgid(gid))) {2622 switch (errno(system.setgid(gid))) {
2622 0 => return,2623 .SUCCESS => return,
2623 EAGAIN => return error.ResourceLimitReached,2624 .AGAIN => return error.ResourceLimitReached,
2624 EINVAL => return error.InvalidUserId,2625 .INVAL => return error.InvalidUserId,
2625 EPERM => return error.PermissionDenied,2626 .PERM => return error.PermissionDenied,
2626 else => |err| return unexpectedErrno(err),2627 else => |err| return unexpectedErrno(err),
2627 }2628 }
2628}2629}
26292630
2630pub fn setegid(uid: uid_t) SetEidError!void {2631pub fn setegid(uid: uid_t) SetEidError!void {
2631 switch (errno(system.setegid(uid))) {2632 switch (errno(system.setegid(uid))) {
2632 0 => return,2633 .SUCCESS => return,
2633 EINVAL => return error.InvalidUserId,2634 .INVAL => return error.InvalidUserId,
2634 EPERM => return error.PermissionDenied,2635 .PERM => return error.PermissionDenied,
2635 else => |err| return unexpectedErrno(err),2636 else => |err| return unexpectedErrno(err),
2636 }2637 }
2637}2638}
26382639
2639pub fn setregid(rgid: gid_t, egid: gid_t) SetIdError!void {2640pub fn setregid(rgid: gid_t, egid: gid_t) SetIdError!void {
2640 switch (errno(system.setregid(rgid, egid))) {2641 switch (errno(system.setregid(rgid, egid))) {
2641 0 => return,2642 .SUCCESS => return,
2642 EAGAIN => return error.ResourceLimitReached,2643 .AGAIN => return error.ResourceLimitReached,
2643 EINVAL => return error.InvalidUserId,2644 .INVAL => return error.InvalidUserId,
2644 EPERM => return error.PermissionDenied,2645 .PERM => return error.PermissionDenied,
2645 else => |err| return unexpectedErrno(err),2646 else => |err| return unexpectedErrno(err),
2646 }2647 }
2647}2648}
...@@ -2680,9 +2681,10 @@ pub fn isatty(handle: fd_t) bool {...@@ -2680,9 +2681,10 @@ pub fn isatty(handle: fd_t) bool {
2680 while (true) {2681 while (true) {
2681 var wsz: linux.winsize = undefined;2682 var wsz: linux.winsize = undefined;
2682 const fd = @bitCast(usize, @as(isize, handle));2683 const fd = @bitCast(usize, @as(isize, handle));
2683 switch (linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz))) {2684 const rc = linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz));
2684 0 => return true,2685 switch (linux.getErrno(rc)) {
2685 EINTR => continue,2686 .SUCCESS => return true,
2687 .INTR => continue,
2686 else => return false,2688 else => return false,
2687 }2689 }
2688 }2690 }
...@@ -2777,22 +2779,22 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t...@@ -2777,22 +2779,22 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
2777 socket_type;2779 socket_type;
2778 const rc = system.socket(domain, filtered_sock_type, protocol);2780 const rc = system.socket(domain, filtered_sock_type, protocol);
2779 switch (errno(rc)) {2781 switch (errno(rc)) {
2780 0 => {2782 .SUCCESS => {
2781 const fd = @intCast(fd_t, rc);2783 const fd = @intCast(fd_t, rc);
2782 if (!have_sock_flags) {2784 if (!have_sock_flags) {
2783 try setSockFlags(fd, socket_type);2785 try setSockFlags(fd, socket_type);
2784 }2786 }
2785 return fd;2787 return fd;
2786 },2788 },
2787 EACCES => return error.PermissionDenied,2789 .ACCES => return error.PermissionDenied,
2788 EAFNOSUPPORT => return error.AddressFamilyNotSupported,2790 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
2789 EINVAL => return error.ProtocolFamilyNotAvailable,2791 .INVAL => return error.ProtocolFamilyNotAvailable,
2790 EMFILE => return error.ProcessFdQuotaExceeded,2792 .MFILE => return error.ProcessFdQuotaExceeded,
2791 ENFILE => return error.SystemFdQuotaExceeded,2793 .NFILE => return error.SystemFdQuotaExceeded,
2792 ENOBUFS => return error.SystemResources,2794 .NOBUFS => return error.SystemResources,
2793 ENOMEM => return error.SystemResources,2795 .NOMEM => return error.SystemResources,
2794 EPROTONOSUPPORT => return error.ProtocolNotSupported,2796 .PROTONOSUPPORT => return error.ProtocolNotSupported,
2795 EPROTOTYPE => return error.SocketTypeNotSupported,2797 .PROTOTYPE => return error.SocketTypeNotSupported,
2796 else => |err| return unexpectedErrno(err),2798 else => |err| return unexpectedErrno(err),
2797 }2799 }
2798}2800}
...@@ -2840,12 +2842,12 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {...@@ -2840,12 +2842,12 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {
2840 .both => SHUT_RDWR,2842 .both => SHUT_RDWR,
2841 });2843 });
2842 switch (errno(rc)) {2844 switch (errno(rc)) {
2843 0 => return,2845 .SUCCESS => return,
2844 EBADF => unreachable,2846 .BADF => unreachable,
2845 EINVAL => unreachable,2847 .INVAL => unreachable,
2846 ENOTCONN => return error.SocketNotConnected,2848 .NOTCONN => return error.SocketNotConnected,
2847 ENOTSOCK => unreachable,2849 .NOTSOCK => unreachable,
2848 ENOBUFS => return error.SystemResources,2850 .NOBUFS => return error.SystemResources,
2849 else => |err| return unexpectedErrno(err),2851 else => |err| return unexpectedErrno(err),
2850 }2852 }
2851 }2853 }
...@@ -2924,20 +2926,20 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi...@@ -2924,20 +2926,20 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi
2924 } else {2926 } else {
2925 const rc = system.bind(sock, addr, len);2927 const rc = system.bind(sock, addr, len);
2926 switch (errno(rc)) {2928 switch (errno(rc)) {
2927 0 => return,2929 .SUCCESS => return,
2928 EACCES => return error.AccessDenied,2930 .ACCES => return error.AccessDenied,
2929 EADDRINUSE => return error.AddressInUse,2931 .ADDRINUSE => return error.AddressInUse,
2930 EBADF => unreachable, // always a race condition if this error is returned2932 .BADF => unreachable, // always a race condition if this error is returned
2931 EINVAL => unreachable, // invalid parameters2933 .INVAL => unreachable, // invalid parameters
2932 ENOTSOCK => unreachable, // invalid `sockfd`2934 .NOTSOCK => unreachable, // invalid `sockfd`
2933 EADDRNOTAVAIL => return error.AddressNotAvailable,2935 .ADDRNOTAVAIL => return error.AddressNotAvailable,
2934 EFAULT => unreachable, // invalid `addr` pointer2936 .FAULT => unreachable, // invalid `addr` pointer
2935 ELOOP => return error.SymLinkLoop,2937 .LOOP => return error.SymLinkLoop,
2936 ENAMETOOLONG => return error.NameTooLong,2938 .NAMETOOLONG => return error.NameTooLong,
2937 ENOENT => return error.FileNotFound,2939 .NOENT => return error.FileNotFound,
2938 ENOMEM => return error.SystemResources,2940 .NOMEM => return error.SystemResources,
2939 ENOTDIR => return error.NotDir,2941 .NOTDIR => return error.NotDir,
2940 EROFS => return error.ReadOnlyFileSystem,2942 .ROFS => return error.ReadOnlyFileSystem,
2941 else => |err| return unexpectedErrno(err),2943 else => |err| return unexpectedErrno(err),
2942 }2944 }
2943 }2945 }
...@@ -2993,11 +2995,11 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void {...@@ -2993,11 +2995,11 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void {
2993 } else {2995 } else {
2994 const rc = system.listen(sock, backlog);2996 const rc = system.listen(sock, backlog);
2995 switch (errno(rc)) {2997 switch (errno(rc)) {
2996 0 => return,2998 .SUCCESS => return,
2997 EADDRINUSE => return error.AddressInUse,2999 .ADDRINUSE => return error.AddressInUse,
2998 EBADF => unreachable,3000 .BADF => unreachable,
2999 ENOTSOCK => return error.FileDescriptorNotASocket,3001 .NOTSOCK => return error.FileDescriptorNotASocket,
3000 EOPNOTSUPP => return error.OperationNotSupported,3002 .OPNOTSUPP => return error.OperationNotSupported,
3001 else => |err| return unexpectedErrno(err),3003 else => |err| return unexpectedErrno(err),
3002 }3004 }
3003 }3005 }
...@@ -3099,23 +3101,23 @@ pub fn accept(...@@ -3099,23 +3101,23 @@ pub fn accept(
3099 }3101 }
3100 } else {3102 } else {
3101 switch (errno(rc)) {3103 switch (errno(rc)) {
3102 0 => {3104 .SUCCESS => {
3103 break @intCast(socket_t, rc);3105 break @intCast(socket_t, rc);
3104 },3106 },
3105 EINTR => continue,3107 .INTR => continue,
3106 EAGAIN => return error.WouldBlock,3108 .AGAIN => return error.WouldBlock,
3107 EBADF => unreachable, // always a race condition3109 .BADF => unreachable, // always a race condition
3108 ECONNABORTED => return error.ConnectionAborted,3110 .CONNABORTED => return error.ConnectionAborted,
3109 EFAULT => unreachable,3111 .FAULT => unreachable,
3110 EINVAL => return error.SocketNotListening,3112 .INVAL => return error.SocketNotListening,
3111 ENOTSOCK => unreachable,3113 .NOTSOCK => unreachable,
3112 EMFILE => return error.ProcessFdQuotaExceeded,3114 .MFILE => return error.ProcessFdQuotaExceeded,
3113 ENFILE => return error.SystemFdQuotaExceeded,3115 .NFILE => return error.SystemFdQuotaExceeded,
3114 ENOBUFS => return error.SystemResources,3116 .NOBUFS => return error.SystemResources,
3115 ENOMEM => return error.SystemResources,3117 .NOMEM => return error.SystemResources,
3116 EOPNOTSUPP => unreachable,3118 .OPNOTSUPP => unreachable,
3117 EPROTO => return error.ProtocolFailure,3119 .PROTO => return error.ProtocolFailure,
3118 EPERM => return error.BlockedByFirewall,3120 .PERM => return error.BlockedByFirewall,
3119 else => |err| return unexpectedErrno(err),3121 else => |err| return unexpectedErrno(err),
3120 }3122 }
3121 }3123 }
...@@ -3144,13 +3146,13 @@ pub const EpollCreateError = error{...@@ -3144,13 +3146,13 @@ pub const EpollCreateError = error{
3144pub fn epoll_create1(flags: u32) EpollCreateError!i32 {3146pub fn epoll_create1(flags: u32) EpollCreateError!i32 {
3145 const rc = system.epoll_create1(flags);3147 const rc = system.epoll_create1(flags);
3146 switch (errno(rc)) {3148 switch (errno(rc)) {
3147 0 => return @intCast(i32, rc),3149 .SUCCESS => return @intCast(i32, rc),
3148 else => |err| return unexpectedErrno(err),3150 else => |err| return unexpectedErrno(err),
31493151
3150 EINVAL => unreachable,3152 .INVAL => unreachable,
3151 EMFILE => return error.ProcessFdQuotaExceeded,3153 .MFILE => return error.ProcessFdQuotaExceeded,
3152 ENFILE => return error.SystemFdQuotaExceeded,3154 .NFILE => return error.SystemFdQuotaExceeded,
3153 ENOMEM => return error.SystemResources,3155 .NOMEM => return error.SystemResources,
3154 }3156 }
3155}3157}
31563158
...@@ -3183,17 +3185,17 @@ pub const EpollCtlError = error{...@@ -3183,17 +3185,17 @@ pub const EpollCtlError = error{
3183pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void {3185pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void {
3184 const rc = system.epoll_ctl(epfd, op, fd, event);3186 const rc = system.epoll_ctl(epfd, op, fd, event);
3185 switch (errno(rc)) {3187 switch (errno(rc)) {
3186 0 => return,3188 .SUCCESS => return,
3187 else => |err| return unexpectedErrno(err),3189 else => |err| return unexpectedErrno(err),
31883190
3189 EBADF => unreachable, // always a race condition if this happens3191 .BADF => unreachable, // always a race condition if this happens
3190 EEXIST => return error.FileDescriptorAlreadyPresentInSet,3192 .EXIST => return error.FileDescriptorAlreadyPresentInSet,
3191 EINVAL => unreachable,3193 .INVAL => unreachable,
3192 ELOOP => return error.OperationCausesCircularLoop,3194 .LOOP => return error.OperationCausesCircularLoop,
3193 ENOENT => return error.FileDescriptorNotRegistered,3195 .NOENT => return error.FileDescriptorNotRegistered,
3194 ENOMEM => return error.SystemResources,3196 .NOMEM => return error.SystemResources,
3195 ENOSPC => return error.UserResourceLimitReached,3197 .NOSPC => return error.UserResourceLimitReached,
3196 EPERM => return error.FileDescriptorIncompatibleWithEpoll,3198 .PERM => return error.FileDescriptorIncompatibleWithEpoll,
3197 }3199 }
3198}3200}
31993201
...@@ -3205,11 +3207,11 @@ pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize {...@@ -3205,11 +3207,11 @@ pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize {
3205 // TODO get rid of the @intCast3207 // TODO get rid of the @intCast
3206 const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);3208 const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);
3207 switch (errno(rc)) {3209 switch (errno(rc)) {
3208 0 => return @intCast(usize, rc),3210 .SUCCESS => return @intCast(usize, rc),
3209 EINTR => continue,3211 .INTR => continue,
3210 EBADF => unreachable,3212 .BADF => unreachable,
3211 EFAULT => unreachable,3213 .FAULT => unreachable,
3212 EINVAL => unreachable,3214 .INVAL => unreachable,
3213 else => unreachable,3215 else => unreachable,
3214 }3216 }
3215 }3217 }
...@@ -3224,14 +3226,14 @@ pub const EventFdError = error{...@@ -3224,14 +3226,14 @@ pub const EventFdError = error{
3224pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {3226pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {
3225 const rc = system.eventfd(initval, flags);3227 const rc = system.eventfd(initval, flags);
3226 switch (errno(rc)) {3228 switch (errno(rc)) {
3227 0 => return @intCast(i32, rc),3229 .SUCCESS => return @intCast(i32, rc),
3228 else => |err| return unexpectedErrno(err),3230 else => |err| return unexpectedErrno(err),
32293231
3230 EINVAL => unreachable, // invalid parameters3232 .INVAL => unreachable, // invalid parameters
3231 EMFILE => return error.ProcessFdQuotaExceeded,3233 .MFILE => return error.ProcessFdQuotaExceeded,
3232 ENFILE => return error.SystemFdQuotaExceeded,3234 .NFILE => return error.SystemFdQuotaExceeded,
3233 ENODEV => return error.SystemResources,3235 .NODEV => return error.SystemResources,
3234 ENOMEM => return error.SystemResources,3236 .NOMEM => return error.SystemResources,
3235 }3237 }
3236}3238}
32373239
...@@ -3265,14 +3267,14 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock...@@ -3265,14 +3267,14 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
3265 } else {3267 } else {
3266 const rc = system.getsockname(sock, addr, addrlen);3268 const rc = system.getsockname(sock, addr, addrlen);
3267 switch (errno(rc)) {3269 switch (errno(rc)) {
3268 0 => return,3270 .SUCCESS => return,
3269 else => |err| return unexpectedErrno(err),3271 else => |err| return unexpectedErrno(err),
32703272
3271 EBADF => unreachable, // always a race condition3273 .BADF => unreachable, // always a race condition
3272 EFAULT => unreachable,3274 .FAULT => unreachable,
3273 EINVAL => unreachable, // invalid parameters3275 .INVAL => unreachable, // invalid parameters
3274 ENOTSOCK => return error.FileDescriptorNotASocket,3276 .NOTSOCK => return error.FileDescriptorNotASocket,
3275 ENOBUFS => return error.SystemResources,3277 .NOBUFS => return error.SystemResources,
3276 }3278 }
3277 }3279 }
3278}3280}
...@@ -3294,14 +3296,14 @@ pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock...@@ -3294,14 +3296,14 @@ pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
3294 } else {3296 } else {
3295 const rc = system.getpeername(sock, addr, addrlen);3297 const rc = system.getpeername(sock, addr, addrlen);
3296 switch (errno(rc)) {3298 switch (errno(rc)) {
3297 0 => return,3299 .SUCCESS => return,
3298 else => |err| return unexpectedErrno(err),3300 else => |err| return unexpectedErrno(err),
32993301
3300 EBADF => unreachable, // always a race condition3302 .BADF => unreachable, // always a race condition
3301 EFAULT => unreachable,3303 .FAULT => unreachable,
3302 EINVAL => unreachable, // invalid parameters3304 .INVAL => unreachable, // invalid parameters
3303 ENOTSOCK => return error.FileDescriptorNotASocket,3305 .NOTSOCK => return error.FileDescriptorNotASocket,
3304 ENOBUFS => return error.SystemResources,3306 .NOBUFS => return error.SystemResources,
3305 }3307 }
3306 }3308 }
3307}3309}
...@@ -3384,61 +3386,61 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne...@@ -3384,61 +3386,61 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
33843386
3385 while (true) {3387 while (true) {
3386 switch (errno(system.connect(sock, sock_addr, len))) {3388 switch (errno(system.connect(sock, sock_addr, len))) {
3387 0 => return,3389 .SUCCESS => return,
3388 EACCES => return error.PermissionDenied,3390 .ACCES => return error.PermissionDenied,
3389 EPERM => return error.PermissionDenied,3391 .PERM => return error.PermissionDenied,
3390 EADDRINUSE => return error.AddressInUse,3392 .ADDRINUSE => return error.AddressInUse,
3391 EADDRNOTAVAIL => return error.AddressNotAvailable,3393 .ADDRNOTAVAIL => return error.AddressNotAvailable,
3392 EAFNOSUPPORT => return error.AddressFamilyNotSupported,3394 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
3393 EAGAIN, EINPROGRESS => return error.WouldBlock,3395 .AGAIN, .INPROGRESS => return error.WouldBlock,
3394 EALREADY => return error.ConnectionPending,3396 .ALREADY => return error.ConnectionPending,
3395 EBADF => unreachable, // sockfd is not a valid open file descriptor.3397 .BADF => unreachable, // sockfd is not a valid open file descriptor.
3396 ECONNREFUSED => return error.ConnectionRefused,3398 .CONNREFUSED => return error.ConnectionRefused,
3397 ECONNRESET => return error.ConnectionResetByPeer,3399 .CONNRESET => return error.ConnectionResetByPeer,
3398 EFAULT => unreachable, // The socket structure address is outside the user's address space.3400 .FAULT => unreachable, // The socket structure address is outside the user's address space.
3399 EINTR => continue,3401 .INTR => continue,
3400 EISCONN => unreachable, // The socket is already connected.3402 .ISCONN => unreachable, // The socket is already connected.
3401 ENETUNREACH => return error.NetworkUnreachable,3403 .NETUNREACH => return error.NetworkUnreachable,
3402 ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.3404 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
3403 EPROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.3405 .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
3404 ETIMEDOUT => return error.ConnectionTimedOut,3406 .TIMEDOUT => return error.ConnectionTimedOut,
3405 ENOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist.3407 .NOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist.
3406 else => |err| return unexpectedErrno(err),3408 else => |err| return unexpectedErrno(err),
3407 }3409 }
3408 }3410 }
3409}3411}
34103412
3411pub fn getsockoptError(sockfd: fd_t) ConnectError!void {3413pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
3412 var err_code: u32 = undefined;3414 var err_code: i32 = undefined;
3413 var size: u32 = @sizeOf(u32);3415 var size: u32 = @sizeOf(u32);
3414 const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size);3416 const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size);
3415 assert(size == 4);3417 assert(size == 4);
3416 switch (errno(rc)) {3418 switch (errno(rc)) {
3417 0 => switch (err_code) {3419 .SUCCESS => switch (@intToEnum(E, err_code)) {
3418 0 => return,3420 .SUCCESS => return,
3419 EACCES => return error.PermissionDenied,3421 .ACCES => return error.PermissionDenied,
3420 EPERM => return error.PermissionDenied,3422 .PERM => return error.PermissionDenied,
3421 EADDRINUSE => return error.AddressInUse,3423 .ADDRINUSE => return error.AddressInUse,
3422 EADDRNOTAVAIL => return error.AddressNotAvailable,3424 .ADDRNOTAVAIL => return error.AddressNotAvailable,
3423 EAFNOSUPPORT => return error.AddressFamilyNotSupported,3425 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
3424 EAGAIN => return error.SystemResources,3426 .AGAIN => return error.SystemResources,
3425 EALREADY => return error.ConnectionPending,3427 .ALREADY => return error.ConnectionPending,
3426 EBADF => unreachable, // sockfd is not a valid open file descriptor.3428 .BADF => unreachable, // sockfd is not a valid open file descriptor.
3427 ECONNREFUSED => return error.ConnectionRefused,3429 .CONNREFUSED => return error.ConnectionRefused,
3428 EFAULT => unreachable, // The socket structure address is outside the user's address space.3430 .FAULT => unreachable, // The socket structure address is outside the user's address space.
3429 EISCONN => unreachable, // The socket is already connected.3431 .ISCONN => unreachable, // The socket is already connected.
3430 ENETUNREACH => return error.NetworkUnreachable,3432 .NETUNREACH => return error.NetworkUnreachable,
3431 ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.3433 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
3432 EPROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.3434 .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
3433 ETIMEDOUT => return error.ConnectionTimedOut,3435 .TIMEDOUT => return error.ConnectionTimedOut,
3434 ECONNRESET => return error.ConnectionResetByPeer,3436 .CONNRESET => return error.ConnectionResetByPeer,
3435 else => |err| return unexpectedErrno(err),3437 else => |err| return unexpectedErrno(err),
3436 },3438 },
3437 EBADF => unreachable, // The argument sockfd is not a valid file descriptor.3439 .BADF => unreachable, // The argument sockfd is not a valid file descriptor.
3438 EFAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.3440 .FAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.
3439 EINVAL => unreachable,3441 .INVAL => unreachable,
3440 ENOPROTOOPT => unreachable, // The option is unknown at the level indicated.3442 .NOPROTOOPT => unreachable, // The option is unknown at the level indicated.
3441 ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.3443 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
3442 else => |err| return unexpectedErrno(err),3444 else => |err| return unexpectedErrno(err),
3443 }3445 }
3444}3446}
...@@ -3454,13 +3456,13 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {...@@ -3454,13 +3456,13 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
3454 while (true) {3456 while (true) {
3455 const rc = system.waitpid(pid, &status, if (builtin.link_libc) @intCast(c_int, flags) else flags);3457 const rc = system.waitpid(pid, &status, if (builtin.link_libc) @intCast(c_int, flags) else flags);
3456 switch (errno(rc)) {3458 switch (errno(rc)) {
3457 0 => return .{3459 .SUCCESS => return .{
3458 .pid = @intCast(pid_t, rc),3460 .pid = @intCast(pid_t, rc),
3459 .status = @bitCast(u32, status),3461 .status = @bitCast(u32, status),
3460 },3462 },
3461 EINTR => continue,3463 .INTR => continue,
3462 ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.3464 .CHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
3463 EINVAL => unreachable, // Invalid flags.3465 .INVAL => unreachable, // Invalid flags.
3464 else => unreachable,3466 else => unreachable,
3465 }3467 }
3466 }3468 }
...@@ -3484,12 +3486,12 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -3484,12 +3486,12 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
3484 if (builtin.os.tag == .wasi and !builtin.link_libc) {3486 if (builtin.os.tag == .wasi and !builtin.link_libc) {
3485 var stat: wasi.filestat_t = undefined;3487 var stat: wasi.filestat_t = undefined;
3486 switch (wasi.fd_filestat_get(fd, &stat)) {3488 switch (wasi.fd_filestat_get(fd, &stat)) {
3487 wasi.ESUCCESS => return Stat.fromFilestat(stat),3489 .SUCCESS => return Stat.fromFilestat(stat),
3488 wasi.EINVAL => unreachable,3490 .INVAL => unreachable,
3489 wasi.EBADF => unreachable, // Always a race condition.3491 .BADF => unreachable, // Always a race condition.
3490 wasi.ENOMEM => return error.SystemResources,3492 .NOMEM => return error.SystemResources,
3491 wasi.EACCES => return error.AccessDenied,3493 .ACCES => return error.AccessDenied,
3492 wasi.ENOTCAPABLE => return error.AccessDenied,3494 .NOTCAPABLE => return error.AccessDenied,
3493 else => |err| return unexpectedErrno(err),3495 else => |err| return unexpectedErrno(err),
3494 }3496 }
3495 }3497 }
...@@ -3504,11 +3506,11 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -3504,11 +3506,11 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
35043506
3505 var stat = mem.zeroes(Stat);3507 var stat = mem.zeroes(Stat);
3506 switch (errno(fstat_sym(fd, &stat))) {3508 switch (errno(fstat_sym(fd, &stat))) {
3507 0 => return stat,3509 .SUCCESS => return stat,
3508 EINVAL => unreachable,3510 .INVAL => unreachable,
3509 EBADF => unreachable, // Always a race condition.3511 .BADF => unreachable, // Always a race condition.
3510 ENOMEM => return error.SystemResources,3512 .NOMEM => return error.SystemResources,
3511 EACCES => return error.AccessDenied,3513 .ACCES => return error.AccessDenied,
3512 else => |err| return unexpectedErrno(err),3514 else => |err| return unexpectedErrno(err),
3513 }3515 }
3514}3516}
...@@ -3536,16 +3538,16 @@ pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");...@@ -3536,16 +3538,16 @@ pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");
3536pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {3538pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
3537 var stat: wasi.filestat_t = undefined;3539 var stat: wasi.filestat_t = undefined;
3538 switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {3540 switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
3539 wasi.ESUCCESS => return Stat.fromFilestat(stat),3541 .SUCCESS => return Stat.fromFilestat(stat),
3540 wasi.EINVAL => unreachable,3542 .INVAL => unreachable,
3541 wasi.EBADF => unreachable, // Always a race condition.3543 .BADF => unreachable, // Always a race condition.
3542 wasi.ENOMEM => return error.SystemResources,3544 .NOMEM => return error.SystemResources,
3543 wasi.EACCES => return error.AccessDenied,3545 .ACCES => return error.AccessDenied,
3544 wasi.EFAULT => unreachable,3546 .FAULT => unreachable,
3545 wasi.ENAMETOOLONG => return error.NameTooLong,3547 .NAMETOOLONG => return error.NameTooLong,
3546 wasi.ENOENT => return error.FileNotFound,3548 .NOENT => return error.FileNotFound,
3547 wasi.ENOTDIR => return error.FileNotFound,3549 .NOTDIR => return error.FileNotFound,
3548 wasi.ENOTCAPABLE => return error.AccessDenied,3550 .NOTCAPABLE => return error.AccessDenied,
3549 else => |err| return unexpectedErrno(err),3551 else => |err| return unexpectedErrno(err),
3550 }3552 }
3551}3553}
...@@ -3560,17 +3562,17 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S...@@ -3560,17 +3562,17 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
35603562
3561 var stat = mem.zeroes(Stat);3563 var stat = mem.zeroes(Stat);
3562 switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) {3564 switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) {
3563 0 => return stat,3565 .SUCCESS => return stat,
3564 EINVAL => unreachable,3566 .INVAL => unreachable,
3565 EBADF => unreachable, // Always a race condition.3567 .BADF => unreachable, // Always a race condition.
3566 ENOMEM => return error.SystemResources,3568 .NOMEM => return error.SystemResources,
3567 EACCES => return error.AccessDenied,3569 .ACCES => return error.AccessDenied,
3568 EPERM => return error.AccessDenied,3570 .PERM => return error.AccessDenied,
3569 EFAULT => unreachable,3571 .FAULT => unreachable,
3570 ENAMETOOLONG => return error.NameTooLong,3572 .NAMETOOLONG => return error.NameTooLong,
3571 ELOOP => return error.SymLinkLoop,3573 .LOOP => return error.SymLinkLoop,
3572 ENOENT => return error.FileNotFound,3574 .NOENT => return error.FileNotFound,
3573 ENOTDIR => return error.FileNotFound,3575 .NOTDIR => return error.FileNotFound,
3574 else => |err| return unexpectedErrno(err),3576 else => |err| return unexpectedErrno(err),
3575 }3577 }
3576}3578}
...@@ -3586,9 +3588,9 @@ pub const KQueueError = error{...@@ -3586,9 +3588,9 @@ pub const KQueueError = error{
3586pub fn kqueue() KQueueError!i32 {3588pub fn kqueue() KQueueError!i32 {
3587 const rc = system.kqueue();3589 const rc = system.kqueue();
3588 switch (errno(rc)) {3590 switch (errno(rc)) {
3589 0 => return @intCast(i32, rc),3591 .SUCCESS => return @intCast(i32, rc),
3590 EMFILE => return error.ProcessFdQuotaExceeded,3592 .MFILE => return error.ProcessFdQuotaExceeded,
3591 ENFILE => return error.SystemFdQuotaExceeded,3593 .NFILE => return error.SystemFdQuotaExceeded,
3592 else => |err| return unexpectedErrno(err),3594 else => |err| return unexpectedErrno(err),
3593 }3595 }
3594}3596}
...@@ -3627,15 +3629,15 @@ pub fn kevent(...@@ -3627,15 +3629,15 @@ pub fn kevent(
3627 timeout,3629 timeout,
3628 );3630 );
3629 switch (errno(rc)) {3631 switch (errno(rc)) {
3630 0 => return @intCast(usize, rc),3632 .SUCCESS => return @intCast(usize, rc),
3631 EACCES => return error.AccessDenied,3633 .ACCES => return error.AccessDenied,
3632 EFAULT => unreachable,3634 .FAULT => unreachable,
3633 EBADF => unreachable, // Always a race condition.3635 .BADF => unreachable, // Always a race condition.
3634 EINTR => continue,3636 .INTR => continue,
3635 EINVAL => unreachable,3637 .INVAL => unreachable,
3636 ENOENT => return error.EventNotFound,3638 .NOENT => return error.EventNotFound,
3637 ENOMEM => return error.SystemResources,3639 .NOMEM => return error.SystemResources,
3638 ESRCH => return error.ProcessNotFound,3640 .SRCH => return error.ProcessNotFound,
3639 else => unreachable,3641 else => unreachable,
3640 }3642 }
3641 }3643 }
...@@ -3651,11 +3653,11 @@ pub const INotifyInitError = error{...@@ -3651,11 +3653,11 @@ pub const INotifyInitError = error{
3651pub fn inotify_init1(flags: u32) INotifyInitError!i32 {3653pub fn inotify_init1(flags: u32) INotifyInitError!i32 {
3652 const rc = system.inotify_init1(flags);3654 const rc = system.inotify_init1(flags);
3653 switch (errno(rc)) {3655 switch (errno(rc)) {
3654 0 => return @intCast(i32, rc),3656 .SUCCESS => return @intCast(i32, rc),
3655 EINVAL => unreachable,3657 .INVAL => unreachable,
3656 EMFILE => return error.ProcessFdQuotaExceeded,3658 .MFILE => return error.ProcessFdQuotaExceeded,
3657 ENFILE => return error.SystemFdQuotaExceeded,3659 .NFILE => return error.SystemFdQuotaExceeded,
3658 ENOMEM => return error.SystemResources,3660 .NOMEM => return error.SystemResources,
3659 else => |err| return unexpectedErrno(err),3661 else => |err| return unexpectedErrno(err),
3660 }3662 }
3661}3663}
...@@ -3681,16 +3683,16 @@ pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add...@@ -3681,16 +3683,16 @@ pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add
3681pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {3683pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
3682 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);3684 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
3683 switch (errno(rc)) {3685 switch (errno(rc)) {
3684 0 => return @intCast(i32, rc),3686 .SUCCESS => return @intCast(i32, rc),
3685 EACCES => return error.AccessDenied,3687 .ACCES => return error.AccessDenied,
3686 EBADF => unreachable,3688 .BADF => unreachable,
3687 EFAULT => unreachable,3689 .FAULT => unreachable,
3688 EINVAL => unreachable,3690 .INVAL => unreachable,
3689 ENAMETOOLONG => return error.NameTooLong,3691 .NAMETOOLONG => return error.NameTooLong,
3690 ENOENT => return error.FileNotFound,3692 .NOENT => return error.FileNotFound,
3691 ENOMEM => return error.SystemResources,3693 .NOMEM => return error.SystemResources,
3692 ENOSPC => return error.UserResourceLimitReached,3694 .NOSPC => return error.UserResourceLimitReached,
3693 ENOTDIR => return error.NotDir,3695 .NOTDIR => return error.NotDir,
3694 else => |err| return unexpectedErrno(err),3696 else => |err| return unexpectedErrno(err),
3695 }3697 }
3696}3698}
...@@ -3698,9 +3700,9 @@ pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) I...@@ -3698,9 +3700,9 @@ pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) I
3698/// remove an existing watch from an inotify instance3700/// remove an existing watch from an inotify instance
3699pub fn inotify_rm_watch(inotify_fd: i32, wd: i32) void {3701pub fn inotify_rm_watch(inotify_fd: i32, wd: i32) void {
3700 switch (errno(system.inotify_rm_watch(inotify_fd, wd))) {3702 switch (errno(system.inotify_rm_watch(inotify_fd, wd))) {
3701 0 => return,3703 .SUCCESS => return,
3702 EBADF => unreachable,3704 .BADF => unreachable,
3703 EINVAL => unreachable,3705 .INVAL => unreachable,
3704 else => unreachable,3706 else => unreachable,
3705 }3707 }
3706}3708}
...@@ -3723,10 +3725,10 @@ pub const MProtectError = error{...@@ -3723,10 +3725,10 @@ pub const MProtectError = error{
3723pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void {3725pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void {
3724 assert(mem.isAligned(memory.len, mem.page_size));3726 assert(mem.isAligned(memory.len, mem.page_size));
3725 switch (errno(system.mprotect(memory.ptr, memory.len, protection))) {3727 switch (errno(system.mprotect(memory.ptr, memory.len, protection))) {
3726 0 => return,3728 .SUCCESS => return,
3727 EINVAL => unreachable,3729 .INVAL => unreachable,
3728 EACCES => return error.AccessDenied,3730 .ACCES => return error.AccessDenied,
3729 ENOMEM => return error.OutOfMemory,3731 .NOMEM => return error.OutOfMemory,
3730 else => |err| return unexpectedErrno(err),3732 else => |err| return unexpectedErrno(err),
3731 }3733 }
3732}3734}
...@@ -3736,9 +3738,9 @@ pub const ForkError = error{SystemResources} || UnexpectedError;...@@ -3736,9 +3738,9 @@ pub const ForkError = error{SystemResources} || UnexpectedError;
3736pub fn fork() ForkError!pid_t {3738pub fn fork() ForkError!pid_t {
3737 const rc = system.fork();3739 const rc = system.fork();
3738 switch (errno(rc)) {3740 switch (errno(rc)) {
3739 0 => return @intCast(pid_t, rc),3741 .SUCCESS => return @intCast(pid_t, rc),
3740 EAGAIN => return error.SystemResources,3742 .AGAIN => return error.SystemResources,
3741 ENOMEM => return error.SystemResources,3743 .NOMEM => return error.SystemResources,
3742 else => |err| return unexpectedErrno(err),3744 else => |err| return unexpectedErrno(err),
3743 }3745 }
3744}3746}
...@@ -3782,22 +3784,23 @@ pub fn mmap(...@@ -3782,22 +3784,23 @@ pub fn mmap(
3782 const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);3784 const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);
3783 const err = if (builtin.link_libc) blk: {3785 const err = if (builtin.link_libc) blk: {
3784 if (rc != std.c.MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];3786 if (rc != std.c.MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];
3785 break :blk system._errno().*;3787 break :blk @intToEnum(E, system._errno().*);
3786 } else blk: {3788 } else blk: {
3787 const err = errno(rc);3789 const err = errno(rc);
3788 if (err == 0) return @intToPtr([*]align(mem.page_size) u8, rc)[0..length];3790 if (err == .SUCCESS) return @intToPtr([*]align(mem.page_size) u8, rc)[0..length];
3789 break :blk err;3791 break :blk err;
3790 };3792 };
3791 switch (err) {3793 switch (err) {
3792 ETXTBSY => return error.AccessDenied,3794 .SUCCESS => unreachable,
3793 EACCES => return error.AccessDenied,3795 .TXTBSY => return error.AccessDenied,
3794 EPERM => return error.PermissionDenied,3796 .ACCES => return error.AccessDenied,
3795 EAGAIN => return error.LockedMemoryLimitExceeded,3797 .PERM => return error.PermissionDenied,
3796 EBADF => unreachable, // Always a race condition.3798 .AGAIN => return error.LockedMemoryLimitExceeded,
3797 EOVERFLOW => unreachable, // The number of pages used for length + offset would overflow.3799 .BADF => unreachable, // Always a race condition.
3798 ENODEV => return error.MemoryMappingNotSupported,3800 .OVERFLOW => unreachable, // The number of pages used for length + offset would overflow.
3799 EINVAL => unreachable, // Invalid parameters to mmap()3801 .NODEV => return error.MemoryMappingNotSupported,
3800 ENOMEM => return error.OutOfMemory,3802 .INVAL => unreachable, // Invalid parameters to mmap()
3803 .NOMEM => return error.OutOfMemory,
3801 else => return unexpectedErrno(err),3804 else => return unexpectedErrno(err),
3802 }3805 }
3803}3806}
...@@ -3810,9 +3813,9 @@ pub fn mmap(...@@ -3810,9 +3813,9 @@ pub fn mmap(
3810/// * The Windows function, VirtualFree, has this restriction.3813/// * The Windows function, VirtualFree, has this restriction.
3811pub fn munmap(memory: []align(mem.page_size) const u8) void {3814pub fn munmap(memory: []align(mem.page_size) const u8) void {
3812 switch (errno(system.munmap(memory.ptr, memory.len))) {3815 switch (errno(system.munmap(memory.ptr, memory.len))) {
3813 0 => return,3816 .SUCCESS => return,
3814 EINVAL => unreachable, // Invalid parameters.3817 .INVAL => unreachable, // Invalid parameters.
3815 ENOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping.3818 .NOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping.
3816 else => unreachable,3819 else => unreachable,
3817 }3820 }
3818}3821}
...@@ -3854,18 +3857,18 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {...@@ -3854,18 +3857,18 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
3854 return;3857 return;
3855 }3858 }
3856 switch (errno(system.access(path, mode))) {3859 switch (errno(system.access(path, mode))) {
3857 0 => return,3860 .SUCCESS => return,
3858 EACCES => return error.PermissionDenied,3861 .ACCES => return error.PermissionDenied,
3859 EROFS => return error.ReadOnlyFileSystem,3862 .ROFS => return error.ReadOnlyFileSystem,
3860 ELOOP => return error.SymLinkLoop,3863 .LOOP => return error.SymLinkLoop,
3861 ETXTBSY => return error.FileBusy,3864 .TXTBSY => return error.FileBusy,
3862 ENOTDIR => return error.FileNotFound,3865 .NOTDIR => return error.FileNotFound,
3863 ENOENT => return error.FileNotFound,3866 .NOENT => return error.FileNotFound,
3864 ENAMETOOLONG => return error.NameTooLong,3867 .NAMETOOLONG => return error.NameTooLong,
3865 EINVAL => unreachable,3868 .INVAL => unreachable,
3866 EFAULT => unreachable,3869 .FAULT => unreachable,
3867 EIO => return error.InputOutput,3870 .IO => return error.InputOutput,
3868 ENOMEM => return error.SystemResources,3871 .NOMEM => return error.SystemResources,
3869 else => |err| return unexpectedErrno(err),3872 else => |err| return unexpectedErrno(err),
3870 }3873 }
3871}3874}
...@@ -3905,18 +3908,18 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces...@@ -3905,18 +3908,18 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
3905 return faccessatW(dirfd, path_w.span().ptr, mode, flags);3908 return faccessatW(dirfd, path_w.span().ptr, mode, flags);
3906 }3909 }
3907 switch (errno(system.faccessat(dirfd, path, mode, flags))) {3910 switch (errno(system.faccessat(dirfd, path, mode, flags))) {
3908 0 => return,3911 .SUCCESS => return,
3909 EACCES => return error.PermissionDenied,3912 .ACCES => return error.PermissionDenied,
3910 EROFS => return error.ReadOnlyFileSystem,3913 .ROFS => return error.ReadOnlyFileSystem,
3911 ELOOP => return error.SymLinkLoop,3914 .LOOP => return error.SymLinkLoop,
3912 ETXTBSY => return error.FileBusy,3915 .TXTBSY => return error.FileBusy,
3913 ENOTDIR => return error.FileNotFound,3916 .NOTDIR => return error.FileNotFound,
3914 ENOENT => return error.FileNotFound,3917 .NOENT => return error.FileNotFound,
3915 ENAMETOOLONG => return error.NameTooLong,3918 .NAMETOOLONG => return error.NameTooLong,
3916 EINVAL => unreachable,3919 .INVAL => unreachable,
3917 EFAULT => unreachable,3920 .FAULT => unreachable,
3918 EIO => return error.InputOutput,3921 .IO => return error.InputOutput,
3919 ENOMEM => return error.SystemResources,3922 .NOMEM => return error.SystemResources,
3920 else => |err| return unexpectedErrno(err),3923 else => |err| return unexpectedErrno(err),
3921 }3924 }
3922}3925}
...@@ -3972,11 +3975,11 @@ pub const PipeError = error{...@@ -3972,11 +3975,11 @@ pub const PipeError = error{
3972pub fn pipe() PipeError![2]fd_t {3975pub fn pipe() PipeError![2]fd_t {
3973 var fds: [2]fd_t = undefined;3976 var fds: [2]fd_t = undefined;
3974 switch (errno(system.pipe(&fds))) {3977 switch (errno(system.pipe(&fds))) {
3975 0 => return fds,3978 .SUCCESS => return fds,
3976 EINVAL => unreachable, // Invalid parameters to pipe()3979 .INVAL => unreachable, // Invalid parameters to pipe()
3977 EFAULT => unreachable, // Invalid fds pointer3980 .FAULT => unreachable, // Invalid fds pointer
3978 ENFILE => return error.SystemFdQuotaExceeded,3981 .NFILE => return error.SystemFdQuotaExceeded,
3979 EMFILE => return error.ProcessFdQuotaExceeded,3982 .MFILE => return error.ProcessFdQuotaExceeded,
3980 else => |err| return unexpectedErrno(err),3983 else => |err| return unexpectedErrno(err),
3981 }3984 }
3982}3985}
...@@ -3985,11 +3988,11 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {...@@ -3985,11 +3988,11 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
3985 if (@hasDecl(system, "pipe2")) {3988 if (@hasDecl(system, "pipe2")) {
3986 var fds: [2]fd_t = undefined;3989 var fds: [2]fd_t = undefined;
3987 switch (errno(system.pipe2(&fds, flags))) {3990 switch (errno(system.pipe2(&fds, flags))) {
3988 0 => return fds,3991 .SUCCESS => return fds,
3989 EINVAL => unreachable, // Invalid flags3992 .INVAL => unreachable, // Invalid flags
3990 EFAULT => unreachable, // Invalid fds pointer3993 .FAULT => unreachable, // Invalid fds pointer
3991 ENFILE => return error.SystemFdQuotaExceeded,3994 .NFILE => return error.SystemFdQuotaExceeded,
3992 EMFILE => return error.ProcessFdQuotaExceeded,3995 .MFILE => return error.ProcessFdQuotaExceeded,
3993 else => |err| return unexpectedErrno(err),3996 else => |err| return unexpectedErrno(err),
3994 }3997 }
3995 }3998 }
...@@ -4008,9 +4011,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {...@@ -4008,9 +4011,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
4008 if (flags & O_CLOEXEC != 0) {4011 if (flags & O_CLOEXEC != 0) {
4009 for (fds) |fd| {4012 for (fds) |fd| {
4010 switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) {4013 switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) {
4011 0 => {},4014 .SUCCESS => {},
4012 EINVAL => unreachable, // Invalid flags4015 .INVAL => unreachable, // Invalid flags
4013 EBADF => unreachable, // Always a race condition4016 .BADF => unreachable, // Always a race condition
4014 else => |err| return unexpectedErrno(err),4017 else => |err| return unexpectedErrno(err),
4015 }4018 }
4016 }4019 }
...@@ -4021,9 +4024,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {...@@ -4021,9 +4024,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
4021 if (new_flags != 0) {4024 if (new_flags != 0) {
4022 for (fds) |fd| {4025 for (fds) |fd| {
4023 switch (errno(system.fcntl(fd, F_SETFL, new_flags))) {4026 switch (errno(system.fcntl(fd, F_SETFL, new_flags))) {
4024 0 => {},4027 .SUCCESS => {},
4025 EINVAL => unreachable, // Invalid flags4028 .INVAL => unreachable, // Invalid flags
4026 EBADF => unreachable, // Always a race condition4029 .BADF => unreachable, // Always a race condition
4027 else => |err| return unexpectedErrno(err),4030 else => |err| return unexpectedErrno(err),
4028 }4031 }
4029 }4032 }
...@@ -4055,11 +4058,11 @@ pub fn sysctl(...@@ -4055,11 +4058,11 @@ pub fn sysctl(
40554058
4056 const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong;4059 const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong;
4057 switch (errno(system.sysctl(name.ptr, name_len, oldp, oldlenp, newp, newlen))) {4060 switch (errno(system.sysctl(name.ptr, name_len, oldp, oldlenp, newp, newlen))) {
4058 0 => return,4061 .SUCCESS => return,
4059 EFAULT => unreachable,4062 .FAULT => unreachable,
4060 EPERM => return error.PermissionDenied,4063 .PERM => return error.PermissionDenied,
4061 ENOMEM => return error.SystemResources,4064 .NOMEM => return error.SystemResources,
4062 ENOENT => return error.UnknownName,4065 .NOENT => return error.UnknownName,
4063 else => |err| return unexpectedErrno(err),4066 else => |err| return unexpectedErrno(err),
4064 }4067 }
4065}4068}
...@@ -4081,19 +4084,19 @@ pub fn sysctlbynameZ(...@@ -4081,19 +4084,19 @@ pub fn sysctlbynameZ(
4081 }4084 }
40824085
4083 switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) {4086 switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) {
4084 0 => return,4087 .SUCCESS => return,
4085 EFAULT => unreachable,4088 .FAULT => unreachable,
4086 EPERM => return error.PermissionDenied,4089 .PERM => return error.PermissionDenied,
4087 ENOMEM => return error.SystemResources,4090 .NOMEM => return error.SystemResources,
4088 ENOENT => return error.UnknownName,4091 .NOENT => return error.UnknownName,
4089 else => |err| return unexpectedErrno(err),4092 else => |err| return unexpectedErrno(err),
4090 }4093 }
4091}4094}
40924095
4093pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {4096pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
4094 switch (errno(system.gettimeofday(tv, tz))) {4097 switch (errno(system.gettimeofday(tv, tz))) {
4095 0 => return,4098 .SUCCESS => return,
4096 EINVAL => unreachable,4099 .INVAL => unreachable,
4097 else => unreachable,4100 else => unreachable,
4098 }4101 }
4099}4102}
...@@ -4111,12 +4114,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -4111,12 +4114,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
4111 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {4114 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
4112 var result: u64 = undefined;4115 var result: u64 = undefined;
4113 switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) {4116 switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) {
4114 0 => return,4117 .SUCCESS => return,
4115 EBADF => unreachable, // always a race condition4118 .BADF => unreachable, // always a race condition
4116 EINVAL => return error.Unseekable,4119 .INVAL => return error.Unseekable,
4117 EOVERFLOW => return error.Unseekable,4120 .OVERFLOW => return error.Unseekable,
4118 ESPIPE => return error.Unseekable,4121 .SPIPE => return error.Unseekable,
4119 ENXIO => return error.Unseekable,4122 .NXIO => return error.Unseekable,
4120 else => |err| return unexpectedErrno(err),4123 else => |err| return unexpectedErrno(err),
4121 }4124 }
4122 }4125 }
...@@ -4126,13 +4129,13 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -4126,13 +4129,13 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
4126 if (builtin.os.tag == .wasi and !builtin.link_libc) {4129 if (builtin.os.tag == .wasi and !builtin.link_libc) {
4127 var new_offset: wasi.filesize_t = undefined;4130 var new_offset: wasi.filesize_t = undefined;
4128 switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), wasi.WHENCE_SET, &new_offset)) {4131 switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), wasi.WHENCE_SET, &new_offset)) {
4129 wasi.ESUCCESS => return,4132 .SUCCESS => return,
4130 wasi.EBADF => unreachable, // always a race condition4133 .BADF => unreachable, // always a race condition
4131 wasi.EINVAL => return error.Unseekable,4134 .INVAL => return error.Unseekable,
4132 wasi.EOVERFLOW => return error.Unseekable,4135 .OVERFLOW => return error.Unseekable,
4133 wasi.ESPIPE => return error.Unseekable,4136 .SPIPE => return error.Unseekable,
4134 wasi.ENXIO => return error.Unseekable,4137 .NXIO => return error.Unseekable,
4135 wasi.ENOTCAPABLE => return error.AccessDenied,4138 .NOTCAPABLE => return error.AccessDenied,
4136 else => |err| return unexpectedErrno(err),4139 else => |err| return unexpectedErrno(err),
4137 }4140 }
4138 }4141 }
...@@ -4144,12 +4147,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -4144,12 +4147,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
41444147
4145 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4148 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4146 switch (errno(lseek_sym(fd, ioffset, SEEK_SET))) {4149 switch (errno(lseek_sym(fd, ioffset, SEEK_SET))) {
4147 0 => return,4150 .SUCCESS => return,
4148 EBADF => unreachable, // always a race condition4151 .BADF => unreachable, // always a race condition
4149 EINVAL => return error.Unseekable,4152 .INVAL => return error.Unseekable,
4150 EOVERFLOW => return error.Unseekable,4153 .OVERFLOW => return error.Unseekable,
4151 ESPIPE => return error.Unseekable,4154 .SPIPE => return error.Unseekable,
4152 ENXIO => return error.Unseekable,4155 .NXIO => return error.Unseekable,
4153 else => |err| return unexpectedErrno(err),4156 else => |err| return unexpectedErrno(err),
4154 }4157 }
4155}4158}
...@@ -4159,12 +4162,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {...@@ -4159,12 +4162,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
4159 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {4162 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
4160 var result: u64 = undefined;4163 var result: u64 = undefined;
4161 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) {4164 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) {
4162 0 => return,4165 .SUCCESS => return,
4163 EBADF => unreachable, // always a race condition4166 .BADF => unreachable, // always a race condition
4164 EINVAL => return error.Unseekable,4167 .INVAL => return error.Unseekable,
4165 EOVERFLOW => return error.Unseekable,4168 .OVERFLOW => return error.Unseekable,
4166 ESPIPE => return error.Unseekable,4169 .SPIPE => return error.Unseekable,
4167 ENXIO => return error.Unseekable,4170 .NXIO => return error.Unseekable,
4168 else => |err| return unexpectedErrno(err),4171 else => |err| return unexpectedErrno(err),
4169 }4172 }
4170 }4173 }
...@@ -4174,13 +4177,13 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {...@@ -4174,13 +4177,13 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
4174 if (builtin.os.tag == .wasi and !builtin.link_libc) {4177 if (builtin.os.tag == .wasi and !builtin.link_libc) {
4175 var new_offset: wasi.filesize_t = undefined;4178 var new_offset: wasi.filesize_t = undefined;
4176 switch (wasi.fd_seek(fd, offset, wasi.WHENCE_CUR, &new_offset)) {4179 switch (wasi.fd_seek(fd, offset, wasi.WHENCE_CUR, &new_offset)) {
4177 wasi.ESUCCESS => return,4180 .SUCCESS => return,
4178 wasi.EBADF => unreachable, // always a race condition4181 .BADF => unreachable, // always a race condition
4179 wasi.EINVAL => return error.Unseekable,4182 .INVAL => return error.Unseekable,
4180 wasi.EOVERFLOW => return error.Unseekable,4183 .OVERFLOW => return error.Unseekable,
4181 wasi.ESPIPE => return error.Unseekable,4184 .SPIPE => return error.Unseekable,
4182 wasi.ENXIO => return error.Unseekable,4185 .NXIO => return error.Unseekable,
4183 wasi.ENOTCAPABLE => return error.AccessDenied,4186 .NOTCAPABLE => return error.AccessDenied,
4184 else => |err| return unexpectedErrno(err),4187 else => |err| return unexpectedErrno(err),
4185 }4188 }
4186 }4189 }
...@@ -4191,12 +4194,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {...@@ -4191,12 +4194,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
41914194
4192 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4195 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4193 switch (errno(lseek_sym(fd, ioffset, SEEK_CUR))) {4196 switch (errno(lseek_sym(fd, ioffset, SEEK_CUR))) {
4194 0 => return,4197 .SUCCESS => return,
4195 EBADF => unreachable, // always a race condition4198 .BADF => unreachable, // always a race condition
4196 EINVAL => return error.Unseekable,4199 .INVAL => return error.Unseekable,
4197 EOVERFLOW => return error.Unseekable,4200 .OVERFLOW => return error.Unseekable,
4198 ESPIPE => return error.Unseekable,4201 .SPIPE => return error.Unseekable,
4199 ENXIO => return error.Unseekable,4202 .NXIO => return error.Unseekable,
4200 else => |err| return unexpectedErrno(err),4203 else => |err| return unexpectedErrno(err),
4201 }4204 }
4202}4205}
...@@ -4206,12 +4209,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {...@@ -4206,12 +4209,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
4206 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {4209 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
4207 var result: u64 = undefined;4210 var result: u64 = undefined;
4208 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) {4211 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) {
4209 0 => return,4212 .SUCCESS => return,
4210 EBADF => unreachable, // always a race condition4213 .BADF => unreachable, // always a race condition
4211 EINVAL => return error.Unseekable,4214 .INVAL => return error.Unseekable,
4212 EOVERFLOW => return error.Unseekable,4215 .OVERFLOW => return error.Unseekable,
4213 ESPIPE => return error.Unseekable,4216 .SPIPE => return error.Unseekable,
4214 ENXIO => return error.Unseekable,4217 .NXIO => return error.Unseekable,
4215 else => |err| return unexpectedErrno(err),4218 else => |err| return unexpectedErrno(err),
4216 }4219 }
4217 }4220 }
...@@ -4221,13 +4224,13 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {...@@ -4221,13 +4224,13 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
4221 if (builtin.os.tag == .wasi and !builtin.link_libc) {4224 if (builtin.os.tag == .wasi and !builtin.link_libc) {
4222 var new_offset: wasi.filesize_t = undefined;4225 var new_offset: wasi.filesize_t = undefined;
4223 switch (wasi.fd_seek(fd, offset, wasi.WHENCE_END, &new_offset)) {4226 switch (wasi.fd_seek(fd, offset, wasi.WHENCE_END, &new_offset)) {
4224 wasi.ESUCCESS => return,4227 .SUCCESS => return,
4225 wasi.EBADF => unreachable, // always a race condition4228 .BADF => unreachable, // always a race condition
4226 wasi.EINVAL => return error.Unseekable,4229 .INVAL => return error.Unseekable,
4227 wasi.EOVERFLOW => return error.Unseekable,4230 .OVERFLOW => return error.Unseekable,
4228 wasi.ESPIPE => return error.Unseekable,4231 .SPIPE => return error.Unseekable,
4229 wasi.ENXIO => return error.Unseekable,4232 .NXIO => return error.Unseekable,
4230 wasi.ENOTCAPABLE => return error.AccessDenied,4233 .NOTCAPABLE => return error.AccessDenied,
4231 else => |err| return unexpectedErrno(err),4234 else => |err| return unexpectedErrno(err),
4232 }4235 }
4233 }4236 }
...@@ -4238,12 +4241,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {...@@ -4238,12 +4241,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
42384241
4239 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4242 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4240 switch (errno(lseek_sym(fd, ioffset, SEEK_END))) {4243 switch (errno(lseek_sym(fd, ioffset, SEEK_END))) {
4241 0 => return,4244 .SUCCESS => return,
4242 EBADF => unreachable, // always a race condition4245 .BADF => unreachable, // always a race condition
4243 EINVAL => return error.Unseekable,4246 .INVAL => return error.Unseekable,
4244 EOVERFLOW => return error.Unseekable,4247 .OVERFLOW => return error.Unseekable,
4245 ESPIPE => return error.Unseekable,4248 .SPIPE => return error.Unseekable,
4246 ENXIO => return error.Unseekable,4249 .NXIO => return error.Unseekable,
4247 else => |err| return unexpectedErrno(err),4250 else => |err| return unexpectedErrno(err),
4248 }4251 }
4249}4252}
...@@ -4253,12 +4256,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {...@@ -4253,12 +4256,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
4253 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {4256 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
4254 var result: u64 = undefined;4257 var result: u64 = undefined;
4255 switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) {4258 switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) {
4256 0 => return result,4259 .SUCCESS => return result,
4257 EBADF => unreachable, // always a race condition4260 .BADF => unreachable, // always a race condition
4258 EINVAL => return error.Unseekable,4261 .INVAL => return error.Unseekable,
4259 EOVERFLOW => return error.Unseekable,4262 .OVERFLOW => return error.Unseekable,
4260 ESPIPE => return error.Unseekable,4263 .SPIPE => return error.Unseekable,
4261 ENXIO => return error.Unseekable,4264 .NXIO => return error.Unseekable,
4262 else => |err| return unexpectedErrno(err),4265 else => |err| return unexpectedErrno(err),
4263 }4266 }
4264 }4267 }
...@@ -4268,13 +4271,13 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {...@@ -4268,13 +4271,13 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
4268 if (builtin.os.tag == .wasi and !builtin.link_libc) {4271 if (builtin.os.tag == .wasi and !builtin.link_libc) {
4269 var new_offset: wasi.filesize_t = undefined;4272 var new_offset: wasi.filesize_t = undefined;
4270 switch (wasi.fd_seek(fd, 0, wasi.WHENCE_CUR, &new_offset)) {4273 switch (wasi.fd_seek(fd, 0, wasi.WHENCE_CUR, &new_offset)) {
4271 wasi.ESUCCESS => return new_offset,4274 .SUCCESS => return new_offset,
4272 wasi.EBADF => unreachable, // always a race condition4275 .BADF => unreachable, // always a race condition
4273 wasi.EINVAL => return error.Unseekable,4276 .INVAL => return error.Unseekable,
4274 wasi.EOVERFLOW => return error.Unseekable,4277 .OVERFLOW => return error.Unseekable,
4275 wasi.ESPIPE => return error.Unseekable,4278 .SPIPE => return error.Unseekable,
4276 wasi.ENXIO => return error.Unseekable,4279 .NXIO => return error.Unseekable,
4277 wasi.ENOTCAPABLE => return error.AccessDenied,4280 .NOTCAPABLE => return error.AccessDenied,
4278 else => |err| return unexpectedErrno(err),4281 else => |err| return unexpectedErrno(err),
4279 }4282 }
4280 }4283 }
...@@ -4285,12 +4288,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {...@@ -4285,12 +4288,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
42854288
4286 const rc = lseek_sym(fd, 0, SEEK_CUR);4289 const rc = lseek_sym(fd, 0, SEEK_CUR);
4287 switch (errno(rc)) {4290 switch (errno(rc)) {
4288 0 => return @bitCast(u64, rc),4291 .SUCCESS => return @bitCast(u64, rc),
4289 EBADF => unreachable, // always a race condition4292 .BADF => unreachable, // always a race condition
4290 EINVAL => return error.Unseekable,4293 .INVAL => return error.Unseekable,
4291 EOVERFLOW => return error.Unseekable,4294 .OVERFLOW => return error.Unseekable,
4292 ESPIPE => return error.Unseekable,4295 .SPIPE => return error.Unseekable,
4293 ENXIO => return error.Unseekable,4296 .NXIO => return error.Unseekable,
4294 else => |err| return unexpectedErrno(err),4297 else => |err| return unexpectedErrno(err),
4295 }4298 }
4296}4299}
...@@ -4306,15 +4309,15 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {...@@ -4306,15 +4309,15 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
4306 while (true) {4309 while (true) {
4307 const rc = system.fcntl(fd, cmd, arg);4310 const rc = system.fcntl(fd, cmd, arg);
4308 switch (errno(rc)) {4311 switch (errno(rc)) {
4309 0 => return @intCast(usize, rc),4312 .SUCCESS => return @intCast(usize, rc),
4310 EINTR => continue,4313 .INTR => continue,
4311 EACCES => return error.Locked,4314 .ACCES => return error.Locked,
4312 EBADF => unreachable,4315 .BADF => unreachable,
4313 EBUSY => return error.FileBusy,4316 .BUSY => return error.FileBusy,
4314 EINVAL => unreachable, // invalid parameters4317 .INVAL => unreachable, // invalid parameters
4315 EPERM => return error.PermissionDenied,4318 .PERM => return error.PermissionDenied,
4316 EMFILE => return error.ProcessFdQuotaExceeded,4319 .MFILE => return error.ProcessFdQuotaExceeded,
4317 ENOTDIR => unreachable, // invalid parameter4320 .NOTDIR => unreachable, // invalid parameter
4318 else => |err| return unexpectedErrno(err),4321 else => |err| return unexpectedErrno(err),
4319 }4322 }
4320 }4323 }
...@@ -4381,12 +4384,12 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void {...@@ -4381,12 +4384,12 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void {
4381 while (true) {4384 while (true) {
4382 const rc = system.flock(fd, operation);4385 const rc = system.flock(fd, operation);
4383 switch (errno(rc)) {4386 switch (errno(rc)) {
4384 0 => return,4387 .SUCCESS => return,
4385 EBADF => unreachable,4388 .BADF => unreachable,
4386 EINTR => continue,4389 .INTR => continue,
4387 EINVAL => unreachable, // invalid parameters4390 .INVAL => unreachable, // invalid parameters
4388 ENOLCK => return error.SystemResources,4391 .NOLCK => return error.SystemResources,
4389 EWOULDBLOCK => return error.WouldBlock, // TODO: integrate with async instead of just returning an error4392 .AGAIN => return error.WouldBlock, // TODO: integrate with async instead of just returning an error
4390 else => |err| return unexpectedErrno(err),4393 else => |err| return unexpectedErrno(err),
4391 }4394 }
4392 }4395 }
...@@ -4456,17 +4459,18 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP...@@ -4456,17 +4459,18 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
44564459
4457 return getFdPath(fd, out_buffer);4460 return getFdPath(fd, out_buffer);
4458 }4461 }
4459 const result_path = std.c.realpath(pathname, out_buffer) orelse switch (std.c._errno().*) {4462 const result_path = std.c.realpath(pathname, out_buffer) orelse switch (@intToEnum(E, std.c._errno().*)) {
4460 EINVAL => unreachable,4463 .SUCCESS => unreachable,
4461 EBADF => unreachable,4464 .INVAL => unreachable,
4462 EFAULT => unreachable,4465 .BADF => unreachable,
4463 EACCES => return error.AccessDenied,4466 .FAULT => unreachable,
4464 ENOENT => return error.FileNotFound,4467 .ACCES => return error.AccessDenied,
4465 ENOTSUP => return error.NotSupported,4468 .NOENT => return error.FileNotFound,
4466 ENOTDIR => return error.NotDir,4469 .OPNOTSUPP => return error.NotSupported,
4467 ENAMETOOLONG => return error.NameTooLong,4470 .NOTDIR => return error.NotDir,
4468 ELOOP => return error.SymLinkLoop,4471 .NAMETOOLONG => return error.NameTooLong,
4469 EIO => return error.InputOutput,4472 .LOOP => return error.SymLinkLoop,
4473 .IO => return error.InputOutput,
4470 else => |err| return unexpectedErrno(err),4474 else => |err| return unexpectedErrno(err),
4471 };4475 };
4472 return mem.spanZ(result_path);4476 return mem.spanZ(result_path);
...@@ -4528,8 +4532,8 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {...@@ -4528,8 +4532,8 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
4528 // the path to the file descriptor.4532 // the path to the file descriptor.
4529 @memset(out_buffer, 0, MAX_PATH_BYTES);4533 @memset(out_buffer, 0, MAX_PATH_BYTES);
4530 switch (errno(system.fcntl(fd, F_GETPATH, out_buffer))) {4534 switch (errno(system.fcntl(fd, F_GETPATH, out_buffer))) {
4531 0 => {},4535 .SUCCESS => {},
4532 EBADF => return error.FileNotFound,4536 .BADF => return error.FileNotFound,
4533 // TODO man pages for fcntl on macOS don't really tell you what4537 // TODO man pages for fcntl on macOS don't really tell you what
4534 // errno values to expect when command is F_GETPATH...4538 // errno values to expect when command is F_GETPATH...
4535 else => |err| return unexpectedErrno(err),4539 else => |err| return unexpectedErrno(err),
...@@ -4562,13 +4566,13 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void {...@@ -4562,13 +4566,13 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
4562 var rem: timespec = undefined;4566 var rem: timespec = undefined;
4563 while (true) {4567 while (true) {
4564 switch (errno(system.nanosleep(&req, &rem))) {4568 switch (errno(system.nanosleep(&req, &rem))) {
4565 EFAULT => unreachable,4569 .FAULT => unreachable,
4566 EINVAL => {4570 .INVAL => {
4567 // Sometimes Darwin returns EINVAL for no reason.4571 // Sometimes Darwin returns EINVAL for no reason.
4568 // We treat it as a spurious wakeup.4572 // We treat it as a spurious wakeup.
4569 return;4573 return;
4570 },4574 },
4571 EINTR => {4575 .INTR => {
4572 req = rem;4576 req = rem;
4573 continue;4577 continue;
4574 },4578 },
...@@ -4668,13 +4672,13 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -4668,13 +4672,13 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
4668 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {4672 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
4669 var ts: timestamp_t = undefined;4673 var ts: timestamp_t = undefined;
4670 switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) {4674 switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) {
4671 0 => {4675 .SUCCESS => {
4672 tp.* = .{4676 tp.* = .{
4673 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),4677 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),
4674 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),4678 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),
4675 };4679 };
4676 },4680 },
4677 EINVAL => return error.UnsupportedClock,4681 .INVAL => return error.UnsupportedClock,
4678 else => |err| return unexpectedErrno(err),4682 else => |err| return unexpectedErrno(err),
4679 }4683 }
4680 return;4684 return;
...@@ -4698,9 +4702,9 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -4698,9 +4702,9 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
4698 }4702 }
46994703
4700 switch (errno(system.clock_gettime(clk_id, tp))) {4704 switch (errno(system.clock_gettime(clk_id, tp))) {
4701 0 => return,4705 .SUCCESS => return,
4702 EFAULT => unreachable,4706 .FAULT => unreachable,
4703 EINVAL => return error.UnsupportedClock,4707 .INVAL => return error.UnsupportedClock,
4704 else => |err| return unexpectedErrno(err),4708 else => |err| return unexpectedErrno(err),
4705 }4709 }
4706}4710}
...@@ -4709,20 +4713,20 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {...@@ -4709,20 +4713,20 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
4709 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {4713 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
4710 var ts: timestamp_t = undefined;4714 var ts: timestamp_t = undefined;
4711 switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) {4715 switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) {
4712 0 => res.* = .{4716 .SUCCESS => res.* = .{
4713 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),4717 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),
4714 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),4718 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),
4715 },4719 },
4716 EINVAL => return error.UnsupportedClock,4720 .INVAL => return error.UnsupportedClock,
4717 else => |err| return unexpectedErrno(err),4721 else => |err| return unexpectedErrno(err),
4718 }4722 }
4719 return;4723 return;
4720 }4724 }
47214725
4722 switch (errno(system.clock_getres(clk_id, res))) {4726 switch (errno(system.clock_getres(clk_id, res))) {
4723 0 => return,4727 .SUCCESS => return,
4724 EFAULT => unreachable,4728 .FAULT => unreachable,
4725 EINVAL => return error.UnsupportedClock,4729 .INVAL => return error.UnsupportedClock,
4726 else => |err| return unexpectedErrno(err),4730 else => |err| return unexpectedErrno(err),
4727 }4731 }
4728}4732}
...@@ -4732,11 +4736,11 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;...@@ -4732,11 +4736,11 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
4732pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {4736pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
4733 var set: cpu_set_t = undefined;4737 var set: cpu_set_t = undefined;
4734 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {4738 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
4735 0 => return set,4739 .SUCCESS => return set,
4736 EFAULT => unreachable,4740 .FAULT => unreachable,
4737 EINVAL => unreachable,4741 .INVAL => unreachable,
4738 ESRCH => unreachable,4742 .SRCH => unreachable,
4739 EPERM => return error.PermissionDenied,4743 .PERM => return error.PermissionDenied,
4740 else => |err| return unexpectedErrno(err),4744 else => |err| return unexpectedErrno(err),
4741 }4745 }
4742}4746}
...@@ -4768,13 +4772,9 @@ pub const UnexpectedError = error{...@@ -4768,13 +4772,9 @@ pub const UnexpectedError = error{
47684772
4769/// Call this when you made a syscall or something that sets errno4773/// Call this when you made a syscall or something that sets errno
4770/// and you get an unexpected error.4774/// and you get an unexpected error.
4771pub fn unexpectedErrno(err: anytype) UnexpectedError {4775pub fn unexpectedErrno(err: E) UnexpectedError {
4772 if (@typeInfo(@TypeOf(err)) != .Int) {
4773 @compileError("err is expected to be an integer");
4774 }
4775
4776 if (unexpected_error_tracing) {4776 if (unexpected_error_tracing) {
4777 std.debug.warn("unexpected errno: {d}\n", .{err});4777 std.debug.warn("unexpected errno: {d}\n", .{@enumToInt(err)});
4778 std.debug.dumpCurrentStackTrace(null);4778 std.debug.dumpCurrentStackTrace(null);
4779 }4779 }
4780 return error.Unexpected;4780 return error.Unexpected;
...@@ -4790,11 +4790,11 @@ pub const SigaltstackError = error{...@@ -4790,11 +4790,11 @@ pub const SigaltstackError = error{
47904790
4791pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {4791pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
4792 switch (errno(system.sigaltstack(ss, old_ss))) {4792 switch (errno(system.sigaltstack(ss, old_ss))) {
4793 0 => return,4793 .SUCCESS => return,
4794 EFAULT => unreachable,4794 .FAULT => unreachable,
4795 EINVAL => unreachable,4795 .INVAL => unreachable,
4796 ENOMEM => return error.SizeTooSmall,4796 .NOMEM => return error.SizeTooSmall,
4797 EPERM => return error.PermissionDenied,4797 .PERM => return error.PermissionDenied,
4798 else => |err| return unexpectedErrno(err),4798 else => |err| return unexpectedErrno(err),
4799 }4799 }
4800}4800}
...@@ -4802,9 +4802,9 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {...@@ -4802,9 +4802,9 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
4802/// Examine and change a signal action.4802/// Examine and change a signal action.
4803pub fn sigaction(sig: u6, act: ?*const Sigaction, oact: ?*Sigaction) void {4803pub fn sigaction(sig: u6, act: ?*const Sigaction, oact: ?*Sigaction) void {
4804 switch (errno(system.sigaction(sig, act, oact))) {4804 switch (errno(system.sigaction(sig, act, oact))) {
4805 0 => return,4805 .SUCCESS => return,
4806 EFAULT => unreachable,4806 .FAULT => unreachable,
4807 EINVAL => unreachable,4807 .INVAL => unreachable,
4808 else => unreachable,4808 else => unreachable,
4809 }4809 }
4810}4810}
...@@ -4841,25 +4841,25 @@ pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void {...@@ -4841,25 +4841,25 @@ pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void {
4841 const atim = times[0].toTimestamp();4841 const atim = times[0].toTimestamp();
4842 const mtim = times[1].toTimestamp();4842 const mtim = times[1].toTimestamp();
4843 switch (wasi.fd_filestat_set_times(fd, atim, mtim, wasi.FILESTAT_SET_ATIM | wasi.FILESTAT_SET_MTIM)) {4843 switch (wasi.fd_filestat_set_times(fd, atim, mtim, wasi.FILESTAT_SET_ATIM | wasi.FILESTAT_SET_MTIM)) {
4844 wasi.ESUCCESS => return,4844 .SUCCESS => return,
4845 wasi.EACCES => return error.AccessDenied,4845 .ACCES => return error.AccessDenied,
4846 wasi.EPERM => return error.PermissionDenied,4846 .PERM => return error.PermissionDenied,
4847 wasi.EBADF => unreachable, // always a race condition4847 .BADF => unreachable, // always a race condition
4848 wasi.EFAULT => unreachable,4848 .FAULT => unreachable,
4849 wasi.EINVAL => unreachable,4849 .INVAL => unreachable,
4850 wasi.EROFS => return error.ReadOnlyFileSystem,4850 .ROFS => return error.ReadOnlyFileSystem,
4851 else => |err| return unexpectedErrno(err),4851 else => |err| return unexpectedErrno(err),
4852 }4852 }
4853 }4853 }
48544854
4855 switch (errno(system.futimens(fd, times))) {4855 switch (errno(system.futimens(fd, times))) {
4856 0 => return,4856 .SUCCESS => return,
4857 EACCES => return error.AccessDenied,4857 .ACCES => return error.AccessDenied,
4858 EPERM => return error.PermissionDenied,4858 .PERM => return error.PermissionDenied,
4859 EBADF => unreachable, // always a race condition4859 .BADF => unreachable, // always a race condition
4860 EFAULT => unreachable,4860 .FAULT => unreachable,
4861 EINVAL => unreachable,4861 .INVAL => unreachable,
4862 EROFS => return error.ReadOnlyFileSystem,4862 .ROFS => return error.ReadOnlyFileSystem,
4863 else => |err| return unexpectedErrno(err),4863 else => |err| return unexpectedErrno(err),
4864 }4864 }
4865}4865}
...@@ -4869,10 +4869,10 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;...@@ -4869,10 +4869,10 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;
4869pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {4869pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
4870 if (builtin.link_libc) {4870 if (builtin.link_libc) {
4871 switch (errno(system.gethostname(name_buffer, name_buffer.len))) {4871 switch (errno(system.gethostname(name_buffer, name_buffer.len))) {
4872 0 => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)),4872 .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)),
4873 EFAULT => unreachable,4873 .FAULT => unreachable,
4874 ENAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this4874 .NAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
4875 EPERM => return error.PermissionDenied,4875 .PERM => return error.PermissionDenied,
4876 else => |err| return unexpectedErrno(err),4876 else => |err| return unexpectedErrno(err),
4877 }4877 }
4878 }4878 }
...@@ -4889,8 +4889,8 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {...@@ -4889,8 +4889,8 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
4889pub fn uname() utsname {4889pub fn uname() utsname {
4890 var uts: utsname = undefined;4890 var uts: utsname = undefined;
4891 switch (errno(system.uname(&uts))) {4891 switch (errno(system.uname(&uts))) {
4892 0 => return uts,4892 .SUCCESS => return uts,
4893 EFAULT => unreachable,4893 .FAULT => unreachable,
4894 else => unreachable,4894 else => unreachable,
4895 }4895 }
4896}4896}
...@@ -5049,33 +5049,33 @@ pub fn sendmsg(...@@ -5049,33 +5049,33 @@ pub fn sendmsg(
5049 }5049 }
5050 } else {5050 } else {
5051 switch (errno(rc)) {5051 switch (errno(rc)) {
5052 0 => return @intCast(usize, rc),5052 .SUCCESS => return @intCast(usize, rc),
50535053
5054 EACCES => return error.AccessDenied,5054 .ACCES => return error.AccessDenied,
5055 EAGAIN => return error.WouldBlock,5055 .AGAIN => return error.WouldBlock,
5056 EALREADY => return error.FastOpenAlreadyInProgress,5056 .ALREADY => return error.FastOpenAlreadyInProgress,
5057 EBADF => unreachable, // always a race condition5057 .BADF => unreachable, // always a race condition
5058 ECONNRESET => return error.ConnectionResetByPeer,5058 .CONNRESET => return error.ConnectionResetByPeer,
5059 EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.5059 .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
5060 EFAULT => unreachable, // An invalid user space address was specified for an argument.5060 .FAULT => unreachable, // An invalid user space address was specified for an argument.
5061 EINTR => continue,5061 .INTR => continue,
5062 EINVAL => unreachable, // Invalid argument passed.5062 .INVAL => unreachable, // Invalid argument passed.
5063 EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified5063 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
5064 EMSGSIZE => return error.MessageTooBig,5064 .MSGSIZE => return error.MessageTooBig,
5065 ENOBUFS => return error.SystemResources,5065 .NOBUFS => return error.SystemResources,
5066 ENOMEM => return error.SystemResources,5066 .NOMEM => return error.SystemResources,
5067 ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.5067 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
5068 EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.5068 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
5069 EPIPE => return error.BrokenPipe,5069 .PIPE => return error.BrokenPipe,
5070 EAFNOSUPPORT => return error.AddressFamilyNotSupported,5070 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
5071 ELOOP => return error.SymLinkLoop,5071 .LOOP => return error.SymLinkLoop,
5072 ENAMETOOLONG => return error.NameTooLong,5072 .NAMETOOLONG => return error.NameTooLong,
5073 ENOENT => return error.FileNotFound,5073 .NOENT => return error.FileNotFound,
5074 ENOTDIR => return error.NotDir,5074 .NOTDIR => return error.NotDir,
5075 EHOSTUNREACH => return error.NetworkUnreachable,5075 .HOSTUNREACH => return error.NetworkUnreachable,
5076 ENETUNREACH => return error.NetworkUnreachable,5076 .NETUNREACH => return error.NetworkUnreachable,
5077 ENOTCONN => return error.SocketNotConnected,5077 .NOTCONN => return error.SocketNotConnected,
5078 ENETDOWN => return error.NetworkSubsystemFailed,5078 .NETDOWN => return error.NetworkSubsystemFailed,
5079 else => |err| return unexpectedErrno(err),5079 else => |err| return unexpectedErrno(err),
5080 }5080 }
5081 }5081 }
...@@ -5149,33 +5149,33 @@ pub fn sendto(...@@ -5149,33 +5149,33 @@ pub fn sendto(
5149 }5149 }
5150 } else {5150 } else {
5151 switch (errno(rc)) {5151 switch (errno(rc)) {
5152 0 => return @intCast(usize, rc),5152 .SUCCESS => return @intCast(usize, rc),
51535153
5154 EACCES => return error.AccessDenied,5154 .ACCES => return error.AccessDenied,
5155 EAGAIN => return error.WouldBlock,5155 .AGAIN => return error.WouldBlock,
5156 EALREADY => return error.FastOpenAlreadyInProgress,5156 .ALREADY => return error.FastOpenAlreadyInProgress,
5157 EBADF => unreachable, // always a race condition5157 .BADF => unreachable, // always a race condition
5158 ECONNRESET => return error.ConnectionResetByPeer,5158 .CONNRESET => return error.ConnectionResetByPeer,
5159 EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.5159 .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
5160 EFAULT => unreachable, // An invalid user space address was specified for an argument.5160 .FAULT => unreachable, // An invalid user space address was specified for an argument.
5161 EINTR => continue,5161 .INTR => continue,
5162 EINVAL => unreachable, // Invalid argument passed.5162 .INVAL => unreachable, // Invalid argument passed.
5163 EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified5163 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
5164 EMSGSIZE => return error.MessageTooBig,5164 .MSGSIZE => return error.MessageTooBig,
5165 ENOBUFS => return error.SystemResources,5165 .NOBUFS => return error.SystemResources,
5166 ENOMEM => return error.SystemResources,5166 .NOMEM => return error.SystemResources,
5167 ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.5167 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
5168 EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.5168 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
5169 EPIPE => return error.BrokenPipe,5169 .PIPE => return error.BrokenPipe,
5170 EAFNOSUPPORT => return error.AddressFamilyNotSupported,5170 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
5171 ELOOP => return error.SymLinkLoop,5171 .LOOP => return error.SymLinkLoop,
5172 ENAMETOOLONG => return error.NameTooLong,5172 .NAMETOOLONG => return error.NameTooLong,
5173 ENOENT => return error.FileNotFound,5173 .NOENT => return error.FileNotFound,
5174 ENOTDIR => return error.NotDir,5174 .NOTDIR => return error.NotDir,
5175 EHOSTUNREACH => return error.NetworkUnreachable,5175 .HOSTUNREACH => return error.NetworkUnreachable,
5176 ENETUNREACH => return error.NetworkUnreachable,5176 .NETUNREACH => return error.NetworkUnreachable,
5177 ENOTCONN => return error.SocketNotConnected,5177 .NOTCONN => return error.SocketNotConnected,
5178 ENETDOWN => return error.NetworkSubsystemFailed,5178 .NETDOWN => return error.NetworkSubsystemFailed,
5179 else => |err| return unexpectedErrno(err),5179 else => |err| return unexpectedErrno(err),
5180 }5180 }
5181 }5181 }
...@@ -5312,7 +5312,7 @@ pub fn sendfile(...@@ -5312,7 +5312,7 @@ pub fn sendfile(
5312 var offset: off_t = @bitCast(off_t, in_offset);5312 var offset: off_t = @bitCast(off_t, in_offset);
5313 const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);5313 const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);
5314 switch (errno(rc)) {5314 switch (errno(rc)) {
5315 0 => {5315 .SUCCESS => {
5316 const amt = @bitCast(usize, rc);5316 const amt = @bitCast(usize, rc);
5317 total_written += amt;5317 total_written += amt;
5318 if (in_len == 0 and amt == 0) {5318 if (in_len == 0 and amt == 0) {
...@@ -5325,12 +5325,12 @@ pub fn sendfile(...@@ -5325,12 +5325,12 @@ pub fn sendfile(
5325 }5325 }
5326 },5326 },
53275327
5328 EBADF => unreachable, // Always a race condition.5328 .BADF => unreachable, // Always a race condition.
5329 EFAULT => unreachable, // Segmentation fault.5329 .FAULT => unreachable, // Segmentation fault.
5330 EOVERFLOW => unreachable, // We avoid passing too large of a `count`.5330 .OVERFLOW => unreachable, // We avoid passing too large of a `count`.
5331 ENOTCONN => unreachable, // `out_fd` is an unconnected socket.5331 .NOTCONN => unreachable, // `out_fd` is an unconnected socket.
53325332
5333 EINVAL, ENOSYS => {5333 .INVAL, .NOSYS => {
5334 // EINVAL could be any of the following situations:5334 // EINVAL could be any of the following situations:
5335 // * Descriptor is not valid or locked5335 // * Descriptor is not valid or locked
5336 // * an mmap(2)-like operation is not available for in_fd5336 // * an mmap(2)-like operation is not available for in_fd
...@@ -5340,17 +5340,17 @@ pub fn sendfile(...@@ -5340,17 +5340,17 @@ pub fn sendfile(
5340 // manually, the same as ENOSYS.5340 // manually, the same as ENOSYS.
5341 break :sf;5341 break :sf;
5342 },5342 },
5343 EAGAIN => if (std.event.Loop.instance) |loop| {5343 .AGAIN => if (std.event.Loop.instance) |loop| {
5344 loop.waitUntilFdWritable(out_fd);5344 loop.waitUntilFdWritable(out_fd);
5345 continue;5345 continue;
5346 } else {5346 } else {
5347 return error.WouldBlock;5347 return error.WouldBlock;
5348 },5348 },
5349 EIO => return error.InputOutput,5349 .IO => return error.InputOutput,
5350 EPIPE => return error.BrokenPipe,5350 .PIPE => return error.BrokenPipe,
5351 ENOMEM => return error.SystemResources,5351 .NOMEM => return error.SystemResources,
5352 ENXIO => return error.Unseekable,5352 .NXIO => return error.Unseekable,
5353 ESPIPE => return error.Unseekable,5353 .SPIPE => return error.Unseekable,
5354 else => |err| {5354 else => |err| {
5355 unexpectedErrno(err) catch {};5355 unexpectedErrno(err) catch {};
5356 break :sf;5356 break :sf;
...@@ -5392,13 +5392,13 @@ pub fn sendfile(...@@ -5392,13 +5392,13 @@ pub fn sendfile(
5392 const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags));5392 const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags));
5393 const amt = @bitCast(usize, sbytes);5393 const amt = @bitCast(usize, sbytes);
5394 switch (err) {5394 switch (err) {
5395 0 => return amt,5395 .SUCCESS => return amt,
53965396
5397 EBADF => unreachable, // Always a race condition.5397 .BADF => unreachable, // Always a race condition.
5398 EFAULT => unreachable, // Segmentation fault.5398 .FAULT => unreachable, // Segmentation fault.
5399 ENOTCONN => unreachable, // `out_fd` is an unconnected socket.5399 .NOTCONN => unreachable, // `out_fd` is an unconnected socket.
54005400
5401 EINVAL, EOPNOTSUPP, ENOTSOCK, ENOSYS => {5401 .INVAL, .OPNOTSUPP, .NOTSOCK, .NOSYS => {
5402 // EINVAL could be any of the following situations:5402 // EINVAL could be any of the following situations:
5403 // * The fd argument is not a regular file.5403 // * The fd argument is not a regular file.
5404 // * The s argument is not a SOCK_STREAM type socket.5404 // * The s argument is not a SOCK_STREAM type socket.
...@@ -5408,9 +5408,9 @@ pub fn sendfile(...@@ -5408,9 +5408,9 @@ pub fn sendfile(
5408 break :sf;5408 break :sf;
5409 },5409 },
54105410
5411 EINTR => if (amt != 0) return amt else continue,5411 .INTR => if (amt != 0) return amt else continue,
54125412
5413 EAGAIN => if (amt != 0) {5413 .AGAIN => if (amt != 0) {
5414 return amt;5414 return amt;
5415 } else if (std.event.Loop.instance) |loop| {5415 } else if (std.event.Loop.instance) |loop| {
5416 loop.waitUntilFdWritable(out_fd);5416 loop.waitUntilFdWritable(out_fd);
...@@ -5419,7 +5419,7 @@ pub fn sendfile(...@@ -5419,7 +5419,7 @@ pub fn sendfile(
5419 return error.WouldBlock;5419 return error.WouldBlock;
5420 },5420 },
54215421
5422 EBUSY => if (amt != 0) {5422 .BUSY => if (amt != 0) {
5423 return amt;5423 return amt;
5424 } else if (std.event.Loop.instance) |loop| {5424 } else if (std.event.Loop.instance) |loop| {
5425 loop.waitUntilFdReadable(in_fd);5425 loop.waitUntilFdReadable(in_fd);
...@@ -5428,9 +5428,9 @@ pub fn sendfile(...@@ -5428,9 +5428,9 @@ pub fn sendfile(
5428 return error.WouldBlock;5428 return error.WouldBlock;
5429 },5429 },
54305430
5431 EIO => return error.InputOutput,5431 .IO => return error.InputOutput,
5432 ENOBUFS => return error.SystemResources,5432 .NOBUFS => return error.SystemResources,
5433 EPIPE => return error.BrokenPipe,5433 .PIPE => return error.BrokenPipe,
54345434
5435 else => {5435 else => {
5436 unexpectedErrno(err) catch {};5436 unexpectedErrno(err) catch {};
...@@ -5471,18 +5471,18 @@ pub fn sendfile(...@@ -5471,18 +5471,18 @@ pub fn sendfile(
5471 const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags));5471 const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags));
5472 const amt = @bitCast(usize, sbytes);5472 const amt = @bitCast(usize, sbytes);
5473 switch (err) {5473 switch (err) {
5474 0 => return amt,5474 .SUCCESS => return amt,
54755475
5476 EBADF => unreachable, // Always a race condition.5476 .BADF => unreachable, // Always a race condition.
5477 EFAULT => unreachable, // Segmentation fault.5477 .FAULT => unreachable, // Segmentation fault.
5478 EINVAL => unreachable,5478 .INVAL => unreachable,
5479 ENOTCONN => unreachable, // `out_fd` is an unconnected socket.5479 .NOTCONN => unreachable, // `out_fd` is an unconnected socket.
54805480
5481 ENOTSUP, ENOTSOCK, ENOSYS => break :sf,5481 .OPNOTSUPP, .NOTSOCK, .NOSYS => break :sf,
54825482
5483 EINTR => if (amt != 0) return amt else continue,5483 .INTR => if (amt != 0) return amt else continue,
54845484
5485 EAGAIN => if (amt != 0) {5485 .AGAIN => if (amt != 0) {
5486 return amt;5486 return amt;
5487 } else if (std.event.Loop.instance) |loop| {5487 } else if (std.event.Loop.instance) |loop| {
5488 loop.waitUntilFdWritable(out_fd);5488 loop.waitUntilFdWritable(out_fd);
...@@ -5491,8 +5491,8 @@ pub fn sendfile(...@@ -5491,8 +5491,8 @@ pub fn sendfile(
5491 return error.WouldBlock;5491 return error.WouldBlock;
5492 },5492 },
54935493
5494 EIO => return error.InputOutput,5494 .IO => return error.InputOutput,
5495 EPIPE => return error.BrokenPipe,5495 .PIPE => return error.BrokenPipe,
54965496
5497 else => {5497 else => {
5498 unexpectedErrno(err) catch {};5498 unexpectedErrno(err) catch {};
...@@ -5595,22 +5595,22 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len...@@ -5595,22 +5595,22 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len
55955595
5596 const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);5596 const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
5597 switch (system.getErrno(rc)) {5597 switch (system.getErrno(rc)) {
5598 0 => return @intCast(usize, rc),5598 .SUCCESS => return @intCast(usize, rc),
5599 EBADF => return error.FilesOpenedWithWrongFlags,5599 .BADF => return error.FilesOpenedWithWrongFlags,
5600 EFBIG => return error.FileTooBig,5600 .FBIG => return error.FileTooBig,
5601 EIO => return error.InputOutput,5601 .IO => return error.InputOutput,
5602 EISDIR => return error.IsDir,5602 .ISDIR => return error.IsDir,
5603 ENOMEM => return error.OutOfMemory,5603 .NOMEM => return error.OutOfMemory,
5604 ENOSPC => return error.NoSpaceLeft,5604 .NOSPC => return error.NoSpaceLeft,
5605 EOVERFLOW => return error.Unseekable,5605 .OVERFLOW => return error.Unseekable,
5606 EPERM => return error.PermissionDenied,5606 .PERM => return error.PermissionDenied,
5607 ETXTBSY => return error.FileBusy,5607 .TXTBSY => return error.FileBusy,
5608 // these may not be regular files, try fallback5608 // these may not be regular files, try fallback
5609 EINVAL => {},5609 .INVAL => {},
5610 // support for cross-filesystem copy added in Linux 5.3, use fallback5610 // support for cross-filesystem copy added in Linux 5.3, use fallback
5611 EXDEV => {},5611 .XDEV => {},
5612 // syscall added in Linux 4.5, use fallback5612 // syscall added in Linux 4.5, use fallback
5613 ENOSYS => {5613 .NOSYS => {
5614 has_copy_file_range_syscall.store(false, .Monotonic);5614 has_copy_file_range_syscall.store(false, .Monotonic);
5615 },5615 },
5616 else => |err| return unexpectedErrno(err),5616 else => |err| return unexpectedErrno(err),
...@@ -5652,11 +5652,11 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {...@@ -5652,11 +5652,11 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {
5652 }5652 }
5653 } else {5653 } else {
5654 switch (errno(rc)) {5654 switch (errno(rc)) {
5655 0 => return @intCast(usize, rc),5655 .SUCCESS => return @intCast(usize, rc),
5656 EFAULT => unreachable,5656 .FAULT => unreachable,
5657 EINTR => continue,5657 .INTR => continue,
5658 EINVAL => unreachable,5658 .INVAL => unreachable,
5659 ENOMEM => return error.SystemResources,5659 .NOMEM => return error.SystemResources,
5660 else => |err| return unexpectedErrno(err),5660 else => |err| return unexpectedErrno(err),
5661 }5661 }
5662 }5662 }
...@@ -5681,11 +5681,11 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P...@@ -5681,11 +5681,11 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P
5681 }5681 }
5682 const rc = system.ppoll(fds.ptr, fds.len, ts_ptr, mask);5682 const rc = system.ppoll(fds.ptr, fds.len, ts_ptr, mask);
5683 switch (errno(rc)) {5683 switch (errno(rc)) {
5684 0 => return @intCast(usize, rc),5684 .SUCCESS => return @intCast(usize, rc),
5685 EFAULT => unreachable,5685 .FAULT => unreachable,
5686 EINTR => return error.SignalInterrupt,5686 .INTR => return error.SignalInterrupt,
5687 EINVAL => unreachable,5687 .INVAL => unreachable,
5688 ENOMEM => return error.SystemResources,5688 .NOMEM => return error.SystemResources,
5689 else => |err| return unexpectedErrno(err),5689 else => |err| return unexpectedErrno(err),
5690 }5690 }
5691}5691}
...@@ -5750,17 +5750,17 @@ pub fn recvfrom(...@@ -5750,17 +5750,17 @@ pub fn recvfrom(
5750 }5750 }
5751 } else {5751 } else {
5752 switch (errno(rc)) {5752 switch (errno(rc)) {
5753 0 => return @intCast(usize, rc),5753 .SUCCESS => return @intCast(usize, rc),
5754 EBADF => unreachable, // always a race condition5754 .BADF => unreachable, // always a race condition
5755 EFAULT => unreachable,5755 .FAULT => unreachable,
5756 EINVAL => unreachable,5756 .INVAL => unreachable,
5757 ENOTCONN => unreachable,5757 .NOTCONN => unreachable,
5758 ENOTSOCK => unreachable,5758 .NOTSOCK => unreachable,
5759 EINTR => continue,5759 .INTR => continue,
5760 EAGAIN => return error.WouldBlock,5760 .AGAIN => return error.WouldBlock,
5761 ENOMEM => return error.SystemResources,5761 .NOMEM => return error.SystemResources,
5762 ECONNREFUSED => return error.ConnectionRefused,5762 .CONNREFUSED => return error.ConnectionRefused,
5763 ECONNRESET => return error.ConnectionResetByPeer,5763 .CONNRESET => return error.ConnectionResetByPeer,
5764 else => |err| return unexpectedErrno(err),5764 else => |err| return unexpectedErrno(err),
5765 }5765 }
5766 }5766 }
...@@ -5830,8 +5830,8 @@ pub fn sched_yield() SchedYieldError!void {...@@ -5830,8 +5830,8 @@ pub fn sched_yield() SchedYieldError!void {
5830 return;5830 return;
5831 }5831 }
5832 switch (errno(system.sched_yield())) {5832 switch (errno(system.sched_yield())) {
5833 0 => return,5833 .SUCCESS => return,
5834 ENOSYS => return error.SystemCannotYield,5834 .NOSYS => return error.SystemCannotYield,
5835 else => return error.SystemCannotYield,5835 else => return error.SystemCannotYield,
5836 }5836 }
5837}5837}
...@@ -5874,17 +5874,17 @@ pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSo...@@ -5874,17 +5874,17 @@ pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSo
5874 return;5874 return;
5875 } else {5875 } else {
5876 switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {5876 switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {
5877 0 => {},5877 .SUCCESS => {},
5878 EBADF => unreachable, // always a race condition5878 .BADF => unreachable, // always a race condition
5879 ENOTSOCK => unreachable, // always a race condition5879 .NOTSOCK => unreachable, // always a race condition
5880 EINVAL => unreachable,5880 .INVAL => unreachable,
5881 EFAULT => unreachable,5881 .FAULT => unreachable,
5882 EDOM => return error.TimeoutTooBig,5882 .DOM => return error.TimeoutTooBig,
5883 EISCONN => return error.AlreadyConnected,5883 .ISCONN => return error.AlreadyConnected,
5884 ENOPROTOOPT => return error.InvalidProtocolOption,5884 .NOPROTOOPT => return error.InvalidProtocolOption,
5885 ENOMEM => return error.SystemResources,5885 .NOMEM => return error.SystemResources,
5886 ENOBUFS => return error.SystemResources,5886 .NOBUFS => return error.SystemResources,
5887 EPERM => return error.PermissionDenied,5887 .PERM => return error.PermissionDenied,
5888 else => |err| return unexpectedErrno(err),5888 else => |err| return unexpectedErrno(err),
5889 }5889 }
5890 }5890 }
...@@ -5909,13 +5909,13 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {...@@ -5909,13 +5909,13 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
5909 const getErrno = if (use_c) std.c.getErrno else linux.getErrno;5909 const getErrno = if (use_c) std.c.getErrno else linux.getErrno;
5910 const rc = sys.memfd_create(name, flags);5910 const rc = sys.memfd_create(name, flags);
5911 switch (getErrno(rc)) {5911 switch (getErrno(rc)) {
5912 0 => return @intCast(fd_t, rc),5912 .SUCCESS => return @intCast(fd_t, rc),
5913 EFAULT => unreachable, // name has invalid memory5913 .FAULT => unreachable, // name has invalid memory
5914 EINVAL => unreachable, // name/flags are faulty5914 .INVAL => unreachable, // name/flags are faulty
5915 ENFILE => return error.SystemFdQuotaExceeded,5915 .NFILE => return error.SystemFdQuotaExceeded,
5916 EMFILE => return error.ProcessFdQuotaExceeded,5916 .MFILE => return error.ProcessFdQuotaExceeded,
5917 ENOMEM => return error.OutOfMemory,5917 .NOMEM => return error.OutOfMemory,
5918 ENOSYS => return error.SystemOutdated,5918 .NOSYS => return error.SystemOutdated,
5919 else => |err| return unexpectedErrno(err),5919 else => |err| return unexpectedErrno(err),
5920 }5920 }
5921}5921}
...@@ -5940,9 +5940,9 @@ pub fn getrusage(who: i32) rusage {...@@ -5940,9 +5940,9 @@ pub fn getrusage(who: i32) rusage {
5940 var result: rusage = undefined;5940 var result: rusage = undefined;
5941 const rc = system.getrusage(who, &result);5941 const rc = system.getrusage(who, &result);
5942 switch (errno(rc)) {5942 switch (errno(rc)) {
5943 0 => return result,5943 .SUCCESS => return result,
5944 EINVAL => unreachable,5944 .INVAL => unreachable,
5945 EFAULT => unreachable,5945 .FAULT => unreachable,
5946 else => unreachable,5946 else => unreachable,
5947 }5947 }
5948}5948}
...@@ -5953,10 +5953,10 @@ pub fn tcgetattr(handle: fd_t) TermiosGetError!termios {...@@ -5953,10 +5953,10 @@ pub fn tcgetattr(handle: fd_t) TermiosGetError!termios {
5953 while (true) {5953 while (true) {
5954 var term: termios = undefined;5954 var term: termios = undefined;
5955 switch (errno(system.tcgetattr(handle, &term))) {5955 switch (errno(system.tcgetattr(handle, &term))) {
5956 0 => return term,5956 .SUCCESS => return term,
5957 EINTR => continue,5957 .INTR => continue,
5958 EBADF => unreachable,5958 .BADF => unreachable,
5959 ENOTTY => return error.NotATerminal,5959 .NOTTY => return error.NotATerminal,
5960 else => |err| return unexpectedErrno(err),5960 else => |err| return unexpectedErrno(err),
5961 }5961 }
5962 }5962 }
...@@ -5967,12 +5967,12 @@ pub const TermiosSetError = TermiosGetError || error{ProcessOrphaned};...@@ -5967,12 +5967,12 @@ pub const TermiosSetError = TermiosGetError || error{ProcessOrphaned};
5967pub fn tcsetattr(handle: fd_t, optional_action: TCSA, termios_p: termios) TermiosSetError!void {5967pub fn tcsetattr(handle: fd_t, optional_action: TCSA, termios_p: termios) TermiosSetError!void {
5968 while (true) {5968 while (true) {
5969 switch (errno(system.tcsetattr(handle, optional_action, &termios_p))) {5969 switch (errno(system.tcsetattr(handle, optional_action, &termios_p))) {
5970 0 => return,5970 .SUCCESS => return,
5971 EBADF => unreachable,5971 .BADF => unreachable,
5972 EINTR => continue,5972 .INTR => continue,
5973 EINVAL => unreachable,5973 .INVAL => unreachable,
5974 ENOTTY => return error.NotATerminal,5974 .NOTTY => return error.NotATerminal,
5975 EIO => return error.ProcessOrphaned,5975 .IO => return error.ProcessOrphaned,
5976 else => |err| return unexpectedErrno(err),5976 else => |err| return unexpectedErrno(err),
5977 }5977 }
5978 }5978 }
...@@ -5986,15 +5986,15 @@ pub const IoCtl_SIOCGIFINDEX_Error = error{...@@ -5986,15 +5986,15 @@ pub const IoCtl_SIOCGIFINDEX_Error = error{
5986pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {5986pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {
5987 while (true) {5987 while (true) {
5988 switch (errno(system.ioctl(fd, SIOCGIFINDEX, @ptrToInt(ifr)))) {5988 switch (errno(system.ioctl(fd, SIOCGIFINDEX, @ptrToInt(ifr)))) {
5989 0 => return,5989 .SUCCESS => return,
5990 EINVAL => unreachable, // Bad parameters.5990 .INVAL => unreachable, // Bad parameters.
5991 ENOTTY => unreachable,5991 .NOTTY => unreachable,
5992 ENXIO => unreachable,5992 .NXIO => unreachable,
5993 EBADF => unreachable, // Always a race condition.5993 .BADF => unreachable, // Always a race condition.
5994 EFAULT => unreachable, // Bad pointer parameter.5994 .FAULT => unreachable, // Bad pointer parameter.
5995 EINTR => continue,5995 .INTR => continue,
5996 EIO => return error.FileSystem,5996 .IO => return error.FileSystem,
5997 ENODEV => return error.InterfaceNotFound,5997 .NODEV => return error.InterfaceNotFound,
5998 else => |err| return unexpectedErrno(err),5998 else => |err| return unexpectedErrno(err),
5999 }5999 }
6000 }6000 }
...@@ -6003,13 +6003,13 @@ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {...@@ -6003,13 +6003,13 @@ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {
6003pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {6003pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
6004 const rc = system.signalfd(fd, mask, flags);6004 const rc = system.signalfd(fd, mask, flags);
6005 switch (errno(rc)) {6005 switch (errno(rc)) {
6006 0 => return @intCast(fd_t, rc),6006 .SUCCESS => return @intCast(fd_t, rc),
6007 EBADF, EINVAL => unreachable,6007 .BADF, .INVAL => unreachable,
6008 ENFILE => return error.SystemFdQuotaExceeded,6008 .NFILE => return error.SystemFdQuotaExceeded,
6009 ENOMEM => return error.SystemResources,6009 .NOMEM => return error.SystemResources,
6010 EMFILE => return error.ProcessResources,6010 .MFILE => return error.ProcessResources,
6011 ENODEV => return error.InodeMountFail,6011 .NODEV => return error.InodeMountFail,
6012 ENOSYS => return error.SystemOutdated,6012 .NOSYS => return error.SystemOutdated,
6013 else => |err| return unexpectedErrno(err),6013 else => |err| return unexpectedErrno(err),
6014 }6014 }
6015}6015}
...@@ -6030,11 +6030,11 @@ pub fn sync() void {...@@ -6030,11 +6030,11 @@ pub fn sync() void {
6030pub fn syncfs(fd: fd_t) SyncError!void {6030pub fn syncfs(fd: fd_t) SyncError!void {
6031 const rc = system.syncfs(fd);6031 const rc = system.syncfs(fd);
6032 switch (errno(rc)) {6032 switch (errno(rc)) {
6033 0 => return,6033 .SUCCESS => return,
6034 EBADF, EINVAL, EROFS => unreachable,6034 .BADF, .INVAL, .ROFS => unreachable,
6035 EIO => return error.InputOutput,6035 .IO => return error.InputOutput,
6036 ENOSPC => return error.NoSpaceLeft,6036 .NOSPC => return error.NoSpaceLeft,
6037 EDQUOT => return error.DiskQuota,6037 .DQUOT => return error.DiskQuota,
6038 else => |err| return unexpectedErrno(err),6038 else => |err| return unexpectedErrno(err),
6039 }6039 }
6040}6040}
...@@ -6054,11 +6054,11 @@ pub fn fsync(fd: fd_t) SyncError!void {...@@ -6054,11 +6054,11 @@ pub fn fsync(fd: fd_t) SyncError!void {
6054 }6054 }
6055 const rc = system.fsync(fd);6055 const rc = system.fsync(fd);
6056 switch (errno(rc)) {6056 switch (errno(rc)) {
6057 0 => return,6057 .SUCCESS => return,
6058 EBADF, EINVAL, EROFS => unreachable,6058 .BADF, .INVAL, .ROFS => unreachable,
6059 EIO => return error.InputOutput,6059 .IO => return error.InputOutput,
6060 ENOSPC => return error.NoSpaceLeft,6060 .NOSPC => return error.NoSpaceLeft,
6061 EDQUOT => return error.DiskQuota,6061 .DQUOT => return error.DiskQuota,
6062 else => |err| return unexpectedErrno(err),6062 else => |err| return unexpectedErrno(err),
6063 }6063 }
6064}6064}
...@@ -6073,11 +6073,11 @@ pub fn fdatasync(fd: fd_t) SyncError!void {...@@ -6073,11 +6073,11 @@ pub fn fdatasync(fd: fd_t) SyncError!void {
6073 }6073 }
6074 const rc = system.fdatasync(fd);6074 const rc = system.fdatasync(fd);
6075 switch (errno(rc)) {6075 switch (errno(rc)) {
6076 0 => return,6076 .SUCCESS => return,
6077 EBADF, EINVAL, EROFS => unreachable,6077 .BADF, .INVAL, .ROFS => unreachable,
6078 EIO => return error.InputOutput,6078 .IO => return error.InputOutput,
6079 ENOSPC => return error.NoSpaceLeft,6079 .NOSPC => return error.NoSpaceLeft,
6080 EDQUOT => return error.DiskQuota,6080 .DQUOT => return error.DiskQuota,
6081 else => |err| return unexpectedErrno(err),6081 else => |err| return unexpectedErrno(err),
6082 }6082 }
6083}6083}
...@@ -6111,15 +6111,15 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {...@@ -6111,15 +6111,15 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {
61116111
6112 const rc = system.prctl(@enumToInt(option), buf[0], buf[1], buf[2], buf[3]);6112 const rc = system.prctl(@enumToInt(option), buf[0], buf[1], buf[2], buf[3]);
6113 switch (errno(rc)) {6113 switch (errno(rc)) {
6114 0 => return @intCast(u31, rc),6114 .SUCCESS => return @intCast(u31, rc),
6115 EACCES => return error.AccessDenied,6115 .ACCES => return error.AccessDenied,
6116 EBADF => return error.InvalidFileDescriptor,6116 .BADF => return error.InvalidFileDescriptor,
6117 EFAULT => return error.InvalidAddress,6117 .FAULT => return error.InvalidAddress,
6118 EINVAL => unreachable,6118 .INVAL => unreachable,
6119 ENODEV, ENXIO => return error.UnsupportedFeature,6119 .NODEV, .NXIO => return error.UnsupportedFeature,
6120 EOPNOTSUPP => return error.OperationNotSupported,6120 .OPNOTSUPP => return error.OperationNotSupported,
6121 EPERM, EBUSY => return error.PermissionDenied,6121 .PERM, .BUSY => return error.PermissionDenied,
6122 ERANGE => unreachable,6122 .RANGE => unreachable,
6123 else => |err| return unexpectedErrno(err),6123 else => |err| return unexpectedErrno(err),
6124 }6124 }
6125}6125}
...@@ -6134,9 +6134,9 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {...@@ -6134,9 +6134,9 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
61346134
6135 var limits: rlimit = undefined;6135 var limits: rlimit = undefined;
6136 switch (errno(getrlimit_sym(resource, &limits))) {6136 switch (errno(getrlimit_sym(resource, &limits))) {
6137 0 => return limits,6137 .SUCCESS => return limits,
6138 EFAULT => unreachable, // bogus pointer6138 .FAULT => unreachable, // bogus pointer
6139 EINVAL => unreachable,6139 .INVAL => unreachable,
6140 else => |err| return unexpectedErrno(err),6140 else => |err| return unexpectedErrno(err),
6141 }6141 }
6142}6142}
...@@ -6150,10 +6150,10 @@ pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void...@@ -6150,10 +6150,10 @@ pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void
6150 system.setrlimit;6150 system.setrlimit;
61516151
6152 switch (errno(setrlimit_sym(resource, &limits))) {6152 switch (errno(setrlimit_sym(resource, &limits))) {
6153 0 => return,6153 .SUCCESS => return,
6154 EFAULT => unreachable, // bogus pointer6154 .FAULT => unreachable, // bogus pointer
6155 EINVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable6155 .INVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable
6156 EPERM => return error.PermissionDenied,6156 .PERM => return error.PermissionDenied,
6157 else => |err| return unexpectedErrno(err),6157 else => |err| return unexpectedErrno(err),
6158 }6158 }
6159}6159}
...@@ -6194,14 +6194,14 @@ pub const MadviseError = error{...@@ -6194,14 +6194,14 @@ pub const MadviseError = error{
6194/// This syscall is optional and is sometimes configured to be disabled.6194/// This syscall is optional and is sometimes configured to be disabled.
6195pub fn madvise(ptr: [*]align(mem.page_size) u8, length: usize, advice: u32) MadviseError!void {6195pub fn madvise(ptr: [*]align(mem.page_size) u8, length: usize, advice: u32) MadviseError!void {
6196 switch (errno(system.madvise(ptr, length, advice))) {6196 switch (errno(system.madvise(ptr, length, advice))) {
6197 0 => return,6197 .SUCCESS => return,
6198 EACCES => return error.AccessDenied,6198 .ACCES => return error.AccessDenied,
6199 EAGAIN => return error.SystemResources,6199 .AGAIN => return error.SystemResources,
6200 EBADF => unreachable, // The map exists, but the area maps something that isn't a file.6200 .BADF => unreachable, // The map exists, but the area maps something that isn't a file.
6201 EINVAL => return error.InvalidSyscall,6201 .INVAL => return error.InvalidSyscall,
6202 EIO => return error.WouldExceedMaximumResidentSetSize,6202 .IO => return error.WouldExceedMaximumResidentSetSize,
6203 ENOMEM => return error.OutOfMemory,6203 .NOMEM => return error.OutOfMemory,
6204 ENOSYS => return error.MadviseUnavailable,6204 .NOSYS => return error.MadviseUnavailable,
6205 else => |err| return unexpectedErrno(err),6205 else => |err| return unexpectedErrno(err),
6206 }6206 }
6207}6207}
lib/std/os/bits/darwin.zig+229-224
...@@ -866,337 +866,342 @@ pub fn WIFSIGNALED(x: u32) bool {...@@ -866,337 +866,342 @@ pub fn WIFSIGNALED(x: u32) bool {
866 return wstatus(x) != wstopped and wstatus(x) != 0;866 return wstatus(x) != wstopped and wstatus(x) != 0;
867}867}
868868
869/// Operation not permitted869pub const E = enum(u16) {
870pub const EPERM = 1;870 /// No error occurred.
871 SUCCESS = 0,
871872
872/// No such file or directory873 /// Operation not permitted
873pub const ENOENT = 2;874 PERM = 1,
874875
875/// No such process876 /// No such file or directory
876pub const ESRCH = 3;877 NOENT = 2,
877878
878/// Interrupted system call879 /// No such process
879pub const EINTR = 4;880 SRCH = 3,
880881
881/// Input/output error882 /// Interrupted system call
882pub const EIO = 5;883 INTR = 4,
883884
884/// Device not configured885 /// Input/output error
885pub const ENXIO = 6;886 IO = 5,
886887
887/// Argument list too long888 /// Device not configured
888pub const E2BIG = 7;889 NXIO = 6,
889890
890/// Exec format error891 /// Argument list too long
891pub const ENOEXEC = 8;892 @"2BIG" = 7,
892893
893/// Bad file descriptor894 /// Exec format error
894pub const EBADF = 9;895 NOEXEC = 8,
895896
896/// No child processes897 /// Bad file descriptor
897pub const ECHILD = 10;898 BADF = 9,
898899
899/// Resource deadlock avoided900 /// No child processes
900pub const EDEADLK = 11;901 CHILD = 10,
901902
902/// Cannot allocate memory903 /// Resource deadlock avoided
903pub const ENOMEM = 12;904 DEADLK = 11,
904905
905/// Permission denied906 /// Cannot allocate memory
906pub const EACCES = 13;907 NOMEM = 12,
907908
908/// Bad address909 /// Permission denied
909pub const EFAULT = 14;910 ACCES = 13,
910911
911/// Block device required912 /// Bad address
912pub const ENOTBLK = 15;913 FAULT = 14,
913914
914/// Device / Resource busy915 /// Block device required
915pub const EBUSY = 16;916 NOTBLK = 15,
916917
917/// File exists918 /// Device / Resource busy
918pub const EEXIST = 17;919 BUSY = 16,
919920
920/// Cross-device link921 /// File exists
921pub const EXDEV = 18;922 EXIST = 17,
922923
923/// Operation not supported by device924 /// Cross-device link
924pub const ENODEV = 19;925 XDEV = 18,
925926
926/// Not a directory927 /// Operation not supported by device
927pub const ENOTDIR = 20;928 NODEV = 19,
928929
929/// Is a directory930 /// Not a directory
930pub const EISDIR = 21;931 NOTDIR = 20,
931932
932/// Invalid argument933 /// Is a directory
933pub const EINVAL = 22;934 ISDIR = 21,
934935
935/// Too many open files in system936 /// Invalid argument
936pub const ENFILE = 23;937 INVAL = 22,
937938
938/// Too many open files939 /// Too many open files in system
939pub const EMFILE = 24;940 NFILE = 23,
940941
941/// Inappropriate ioctl for device942 /// Too many open files
942pub const ENOTTY = 25;943 MFILE = 24,
943944
944/// Text file busy945 /// Inappropriate ioctl for device
945pub const ETXTBSY = 26;946 NOTTY = 25,
946947
947/// File too large948 /// Text file busy
948pub const EFBIG = 27;949 TXTBSY = 26,
949950
950/// No space left on device951 /// File too large
951pub const ENOSPC = 28;952 FBIG = 27,
952953
953/// Illegal seek954 /// No space left on device
954pub const ESPIPE = 29;955 NOSPC = 28,
955956
956/// Read-only file system957 /// Illegal seek
957pub const EROFS = 30;958 SPIPE = 29,
958959
959/// Too many links960 /// Read-only file system
960pub const EMLINK = 31;961 ROFS = 30,
961/// Broken pipe
962962
963// math software963 /// Too many links
964pub const EPIPE = 32;964 MLINK = 31,
965965
966/// Numerical argument out of domain966 /// Broken pipe
967pub const EDOM = 33;967 PIPE = 32,
968/// Result too large
969968
970// non-blocking and interrupt i/o969 // math software
971pub const ERANGE = 34;
972970
973/// Resource temporarily unavailable971 /// Numerical argument out of domain
974pub const EAGAIN = 35;972 DOM = 33,
975973
976/// Operation would block974 /// Result too large
977pub const EWOULDBLOCK = EAGAIN;975 RANGE = 34,
978976
979/// Operation now in progress977 // non-blocking and interrupt i/o
980pub const EINPROGRESS = 36;
981/// Operation already in progress
982978
983// ipc/network software -- argument errors979 /// Resource temporarily unavailable
984pub const EALREADY = 37;980 /// This is the same code used for `WOULDBLOCK`.
981 AGAIN = 35,
985982
986/// Socket operation on non-socket983 /// Operation now in progress
987pub const ENOTSOCK = 38;984 INPROGRESS = 36,
988985
989/// Destination address required986 /// Operation already in progress
990pub const EDESTADDRREQ = 39;987 ALREADY = 37,
991988
992/// Message too long989 // ipc/network software -- argument errors
993pub const EMSGSIZE = 40;
994990
995/// Protocol wrong type for socket991 /// Socket operation on non-socket
996pub const EPROTOTYPE = 41;992 NOTSOCK = 38,
997993
998/// Protocol not available994 /// Destination address required
999pub const ENOPROTOOPT = 42;995 DESTADDRREQ = 39,
1000996
1001/// Protocol not supported997 /// Message too long
1002pub const EPROTONOSUPPORT = 43;998 MSGSIZE = 40,
1003999
1004/// Socket type not supported1000 /// Protocol wrong type for socket
1005pub const ESOCKTNOSUPPORT = 44;1001 PROTOTYPE = 41,
10061002
1007/// Operation not supported1003 /// Protocol not available
1008pub const ENOTSUP = 45;1004 NOPROTOOPT = 42,
10091005
1010/// Operation not supported. Alias of `ENOTSUP`.1006 /// Protocol not supported
1011pub const EOPNOTSUPP = ENOTSUP;1007 PROTONOSUPPORT = 43,
10121008
1013/// Protocol family not supported1009 /// Socket type not supported
1014pub const EPFNOSUPPORT = 46;1010 SOCKTNOSUPPORT = 44,
10151011
1016/// Address family not supported by protocol family1012 /// Operation not supported
1017pub const EAFNOSUPPORT = 47;1013 /// The same code is used for `NOTSUP`.
1014 OPNOTSUPP = 45,
10181015
1019/// Address already in use1016 /// Protocol family not supported
1020pub const EADDRINUSE = 48;1017 PFNOSUPPORT = 46,
1021/// Can't assign requested address
10221018
1023// ipc/network software -- operational errors1019 /// Address family not supported by protocol family
1024pub const EADDRNOTAVAIL = 49;1020 AFNOSUPPORT = 47,
10251021
1026/// Network is down1022 /// Address already in use
1027pub const ENETDOWN = 50;1023 ADDRINUSE = 48,
1024 /// Can't assign requested address
10281025
1029/// Network is unreachable1026 // ipc/network software -- operational errors
1030pub const ENETUNREACH = 51;1027 ADDRNOTAVAIL = 49,
10311028
1032/// Network dropped connection on reset1029 /// Network is down
1033pub const ENETRESET = 52;1030 NETDOWN = 50,
10341031
1035/// Software caused connection abort1032 /// Network is unreachable
1036pub const ECONNABORTED = 53;1033 NETUNREACH = 51,
10371034
1038/// Connection reset by peer1035 /// Network dropped connection on reset
1039pub const ECONNRESET = 54;1036 NETRESET = 52,
10401037
1041/// No buffer space available1038 /// Software caused connection abort
1042pub const ENOBUFS = 55;1039 CONNABORTED = 53,
10431040
1044/// Socket is already connected1041 /// Connection reset by peer
1045pub const EISCONN = 56;1042 CONNRESET = 54,
10461043
1047/// Socket is not connected1044 /// No buffer space available
1048pub const ENOTCONN = 57;1045 NOBUFS = 55,
10491046
1050/// Can't send after socket shutdown1047 /// Socket is already connected
1051pub const ESHUTDOWN = 58;1048 ISCONN = 56,
10521049
1053/// Too many references: can't splice1050 /// Socket is not connected
1054pub const ETOOMANYREFS = 59;1051 NOTCONN = 57,
10551052
1056/// Operation timed out1053 /// Can't send after socket shutdown
1057pub const ETIMEDOUT = 60;1054 SHUTDOWN = 58,
10581055
1059/// Connection refused1056 /// Too many references: can't splice
1060pub const ECONNREFUSED = 61;1057 TOOMANYREFS = 59,
10611058
1062/// Too many levels of symbolic links1059 /// Operation timed out
1063pub const ELOOP = 62;1060 TIMEDOUT = 60,
10641061
1065/// File name too long1062 /// Connection refused
1066pub const ENAMETOOLONG = 63;1063 CONNREFUSED = 61,
10671064
1068/// Host is down1065 /// Too many levels of symbolic links
1069pub const EHOSTDOWN = 64;1066 LOOP = 62,
10701067
1071/// No route to host1068 /// File name too long
1072pub const EHOSTUNREACH = 65;1069 NAMETOOLONG = 63,
1073/// Directory not empty
10741070
1075// quotas & mush1071 /// Host is down
1076pub const ENOTEMPTY = 66;1072 HOSTDOWN = 64,
10771073
1078/// Too many processes1074 /// No route to host
1079pub const EPROCLIM = 67;1075 HOSTUNREACH = 65,
1076 /// Directory not empty
10801077
1081/// Too many users1078 // quotas & mush
1082pub const EUSERS = 68;1079 NOTEMPTY = 66,
1083/// Disc quota exceeded
10841080
1085// Network File System1081 /// Too many processes
1086pub const EDQUOT = 69;1082 PROCLIM = 67,
10871083
1088/// Stale NFS file handle1084 /// Too many users
1089pub const ESTALE = 70;1085 USERS = 68,
1086 /// Disc quota exceeded
10901087
1091/// Too many levels of remote in path1088 // Network File System
1092pub const EREMOTE = 71;1089 DQUOT = 69,
10931090
1094/// RPC struct is bad1091 /// Stale NFS file handle
1095pub const EBADRPC = 72;1092 STALE = 70,
10961093
1097/// RPC version wrong1094 /// Too many levels of remote in path
1098pub const ERPCMISMATCH = 73;1095 REMOTE = 71,
10991096
1100/// RPC prog. not avail1097 /// RPC struct is bad
1101pub const EPROGUNAVAIL = 74;1098 BADRPC = 72,
11021099
1103/// Program version wrong1100 /// RPC version wrong
1104pub const EPROGMISMATCH = 75;1101 RPCMISMATCH = 73,
11051102
1106/// Bad procedure for program1103 /// RPC prog. not avail
1107pub const EPROCUNAVAIL = 76;1104 PROGUNAVAIL = 74,
11081105
1109/// No locks available1106 /// Program version wrong
1110pub const ENOLCK = 77;1107 PROGMISMATCH = 75,
11111108
1112/// Function not implemented1109 /// Bad procedure for program
1113pub const ENOSYS = 78;1110 PROCUNAVAIL = 76,
11141111
1115/// Inappropriate file type or format1112 /// No locks available
1116pub const EFTYPE = 79;1113 NOLCK = 77,
11171114
1118/// Authentication error1115 /// Function not implemented
1119pub const EAUTH = 80;1116 NOSYS = 78,
1120/// Need authenticator
11211117
1122// Intelligent device errors1118 /// Inappropriate file type or format
1123pub const ENEEDAUTH = 81;1119 FTYPE = 79,
11241120
1125/// Device power is off1121 /// Authentication error
1126pub const EPWROFF = 82;1122 AUTH = 80,
11271123
1128/// Device error, e.g. paper out1124 /// Need authenticator
1129pub const EDEVERR = 83;1125 NEEDAUTH = 81,
1130/// Value too large to be stored in data type
11311126
1132// Program loading errors1127 // Intelligent device errors
1133pub const EOVERFLOW = 84;
11341128
1135/// Bad executable1129 /// Device power is off
1136pub const EBADEXEC = 85;1130 PWROFF = 82,
11371131
1138/// Bad CPU type in executable1132 /// Device error, e.g. paper out
1139pub const EBADARCH = 86;1133 DEVERR = 83,
11401134
1141/// Shared library version mismatch1135 /// Value too large to be stored in data type
1142pub const ESHLIBVERS = 87;1136 OVERFLOW = 84,
11431137
1144/// Malformed Macho file1138 // Program loading errors
1145pub const EBADMACHO = 88;
11461139
1147/// Operation canceled1140 /// Bad executable
1148pub const ECANCELED = 89;1141 BADEXEC = 85,
11491142
1150/// Identifier removed1143 /// Bad CPU type in executable
1151pub const EIDRM = 90;1144 BADARCH = 86,
11521145
1153/// No message of desired type1146 /// Shared library version mismatch
1154pub const ENOMSG = 91;1147 SHLIBVERS = 87,
11551148
1156/// Illegal byte sequence1149 /// Malformed Macho file
1157pub const EILSEQ = 92;1150 BADMACHO = 88,
11581151
1159/// Attribute not found1152 /// Operation canceled
1160pub const ENOATTR = 93;1153 CANCELED = 89,
11611154
1162/// Bad message1155 /// Identifier removed
1163pub const EBADMSG = 94;1156 IDRM = 90,
11641157
1165/// Reserved1158 /// No message of desired type
1166pub const EMULTIHOP = 95;1159 NOMSG = 91,
11671160
1168/// No message available on STREAM1161 /// Illegal byte sequence
1169pub const ENODATA = 96;1162 ILSEQ = 92,
11701163
1171/// Reserved1164 /// Attribute not found
1172pub const ENOLINK = 97;1165 NOATTR = 93,
11731166
1174/// No STREAM resources1167 /// Bad message
1175pub const ENOSR = 98;1168 BADMSG = 94,
11761169
1177/// Not a STREAM1170 /// Reserved
1178pub const ENOSTR = 99;1171 MULTIHOP = 95,
11791172
1180/// Protocol error1173 /// No message available on STREAM
1181pub const EPROTO = 100;1174 NODATA = 96,
11821175
1183/// STREAM ioctl timeout1176 /// Reserved
1184pub const ETIME = 101;1177 NOLINK = 97,
11851178
1186/// No such policy registered1179 /// No STREAM resources
1187pub const ENOPOLICY = 103;1180 NOSR = 98,
11881181
1189/// State not recoverable1182 /// Not a STREAM
1190pub const ENOTRECOVERABLE = 104;1183 NOSTR = 99,
11911184
1192/// Previous owner died1185 /// Protocol error
1193pub const EOWNERDEAD = 105;1186 PROTO = 100,
11941187
1195/// Interface output queue is full1188 /// STREAM ioctl timeout
1196pub const EQFULL = 106;1189 TIME = 101,
11971190
1198/// Must be equal largest errno1191 /// No such policy registered
1199pub const ELAST = 106;1192 NOPOLICY = 103,
1193
1194 /// State not recoverable
1195 NOTRECOVERABLE = 104,
1196
1197 /// Previous owner died
1198 OWNERDEAD = 105,
1199
1200 /// Interface output queue is full
1201 QFULL = 106,
1202
1203 _,
1204};
12001205
1201pub const SIGSTKSZ = 131072;1206pub const SIGSTKSZ = 131072;
1202pub const MINSIGSTKSZ = 32768;1207pub const MINSIGSTKSZ = 32768;
lib/std/os/bits/dragonfly.zig+102-97
...@@ -25,103 +25,108 @@ pub const gid_t = u32;...@@ -25,103 +25,108 @@ pub const gid_t = u32;
25pub const time_t = isize;25pub const time_t = isize;
26pub const suseconds_t = c_long;26pub const suseconds_t = c_long;
2727
28pub const ENOTSUP = EOPNOTSUPP;28pub const E = enum(u16) {
29pub const EWOULDBLOCK = EAGAIN;29 /// No error occurred.
30pub const EPERM = 1;30 SUCCESS = 0,
31pub const ENOENT = 2;31
32pub const ESRCH = 3;32 PERM = 1,
33pub const EINTR = 4;33 NOENT = 2,
34pub const EIO = 5;34 SRCH = 3,
35pub const ENXIO = 6;35 INTR = 4,
36pub const E2BIG = 7;36 IO = 5,
37pub const ENOEXEC = 8;37 NXIO = 6,
38pub const EBADF = 9;38 @"2BIG" = 7,
39pub const ECHILD = 10;39 NOEXEC = 8,
40pub const EDEADLK = 11;40 BADF = 9,
41pub const ENOMEM = 12;41 CHILD = 10,
42pub const EACCES = 13;42 DEADLK = 11,
43pub const EFAULT = 14;43 NOMEM = 12,
44pub const ENOTBLK = 15;44 ACCES = 13,
45pub const EBUSY = 16;45 FAULT = 14,
46pub const EEXIST = 17;46 NOTBLK = 15,
47pub const EXDEV = 18;47 BUSY = 16,
48pub const ENODEV = 19;48 EXIST = 17,
49pub const ENOTDIR = 20;49 XDEV = 18,
50pub const EISDIR = 21;50 NODEV = 19,
51pub const EINVAL = 22;51 NOTDIR = 20,
52pub const ENFILE = 23;52 ISDIR = 21,
53pub const EMFILE = 24;53 INVAL = 22,
54pub const ENOTTY = 25;54 NFILE = 23,
55pub const ETXTBSY = 26;55 MFILE = 24,
56pub const EFBIG = 27;56 NOTTY = 25,
57pub const ENOSPC = 28;57 TXTBSY = 26,
58pub const ESPIPE = 29;58 FBIG = 27,
59pub const EROFS = 30;59 NOSPC = 28,
60pub const EMLINK = 31;60 SPIPE = 29,
61pub const EPIPE = 32;61 ROFS = 30,
62pub const EDOM = 33;62 MLINK = 31,
63pub const ERANGE = 34;63 PIPE = 32,
64pub const EAGAIN = 35;64 DOM = 33,
65pub const EINPROGRESS = 36;65 RANGE = 34,
66pub const EALREADY = 37;66 /// This code is also used for `WOULDBLOCK`.
67pub const ENOTSOCK = 38;67 AGAIN = 35,
68pub const EDESTADDRREQ = 39;68 INPROGRESS = 36,
69pub const EMSGSIZE = 40;69 ALREADY = 37,
70pub const EPROTOTYPE = 41;70 NOTSOCK = 38,
71pub const ENOPROTOOPT = 42;71 DESTADDRREQ = 39,
72pub const EPROTONOSUPPORT = 43;72 MSGSIZE = 40,
73pub const ESOCKTNOSUPPORT = 44;73 PROTOTYPE = 41,
74pub const EOPNOTSUPP = 45;74 NOPROTOOPT = 42,
75pub const EPFNOSUPPORT = 46;75 PROTONOSUPPORT = 43,
76pub const EAFNOSUPPORT = 47;76 SOCKTNOSUPPORT = 44,
77pub const EADDRINUSE = 48;77 /// This code is also used for `NOTSUP`.
78pub const EADDRNOTAVAIL = 49;78 OPNOTSUPP = 45,
79pub const ENETDOWN = 50;79 PFNOSUPPORT = 46,
80pub const ENETUNREACH = 51;80 AFNOSUPPORT = 47,
81pub const ENETRESET = 52;81 ADDRINUSE = 48,
82pub const ECONNABORTED = 53;82 ADDRNOTAVAIL = 49,
83pub const ECONNRESET = 54;83 NETDOWN = 50,
84pub const ENOBUFS = 55;84 NETUNREACH = 51,
85pub const EISCONN = 56;85 NETRESET = 52,
86pub const ENOTCONN = 57;86 CONNABORTED = 53,
87pub const ESHUTDOWN = 58;87 CONNRESET = 54,
88pub const ETOOMANYREFS = 59;88 NOBUFS = 55,
89pub const ETIMEDOUT = 60;89 ISCONN = 56,
90pub const ECONNREFUSED = 61;90 NOTCONN = 57,
91pub const ELOOP = 62;91 SHUTDOWN = 58,
92pub const ENAMETOOLONG = 63;92 TOOMANYREFS = 59,
93pub const EHOSTDOWN = 64;93 TIMEDOUT = 60,
94pub const EHOSTUNREACH = 65;94 CONNREFUSED = 61,
95pub const ENOTEMPTY = 66;95 LOOP = 62,
96pub const EPROCLIM = 67;96 NAMETOOLONG = 63,
97pub const EUSERS = 68;97 HOSTDOWN = 64,
98pub const EDQUOT = 69;98 HOSTUNREACH = 65,
99pub const ESTALE = 70;99 NOTEMPTY = 66,
100pub const EREMOTE = 71;100 PROCLIM = 67,
101pub const EBADRPC = 72;101 USERS = 68,
102pub const ERPCMISMATCH = 73;102 DQUOT = 69,
103pub const EPROGUNAVAIL = 74;103 STALE = 70,
104pub const EPROGMISMATCH = 75;104 REMOTE = 71,
105pub const EPROCUNAVAIL = 76;105 BADRPC = 72,
106pub const ENOLCK = 77;106 RPCMISMATCH = 73,
107pub const ENOSYS = 78;107 PROGUNAVAIL = 74,
108pub const EFTYPE = 79;108 PROGMISMATCH = 75,
109pub const EAUTH = 80;109 PROCUNAVAIL = 76,
110pub const ENEEDAUTH = 81;110 NOLCK = 77,
111pub const EIDRM = 82;111 NOSYS = 78,
112pub const ENOMSG = 83;112 FTYPE = 79,
113pub const EOVERFLOW = 84;113 AUTH = 80,
114pub const ECANCELED = 85;114 NEEDAUTH = 81,
115pub const EILSEQ = 86;115 IDRM = 82,
116pub const ENOATTR = 87;116 NOMSG = 83,
117pub const EDOOFUS = 88;117 OVERFLOW = 84,
118pub const EBADMSG = 89;118 CANCELED = 85,
119pub const EMULTIHOP = 90;119 ILSEQ = 86,
120pub const ENOLINK = 91;120 NOATTR = 87,
121pub const EPROTO = 92;121 DOOFUS = 88,
122pub const ENOMEDIUM = 93;122 BADMSG = 89,
123pub const ELAST = 99;123 MULTIHOP = 90,
124pub const EASYNC = 99;124 NOLINK = 91,
125 PROTO = 92,
126 NOMEDIUM = 93,
127 ASYNC = 99,
128 _,
129};
125130
126pub const STDIN_FILENO = 0;131pub const STDIN_FILENO = 0;
127pub const STDOUT_FILENO = 1;132pub const STDOUT_FILENO = 1;
lib/std/os/bits/freebsd.zig+128-121
...@@ -887,127 +887,134 @@ pub usingnamespace switch (builtin.target.cpu.arch) {...@@ -887,127 +887,134 @@ pub usingnamespace switch (builtin.target.cpu.arch) {
887 else => struct {},887 else => struct {},
888};888};
889889
890pub const EPERM = 1; // Operation not permitted890pub const E = enum(u16) {
891pub const ENOENT = 2; // No such file or directory891 /// No error occurred.
892pub const ESRCH = 3; // No such process892 SUCCESS = 0,
893pub const EINTR = 4; // Interrupted system call893
894pub const EIO = 5; // Input/output error894 PERM = 1, // Operation not permitted
895pub const ENXIO = 6; // Device not configured895 NOENT = 2, // No such file or directory
896pub const E2BIG = 7; // Argument list too long896 SRCH = 3, // No such process
897pub const ENOEXEC = 8; // Exec format error897 INTR = 4, // Interrupted system call
898pub const EBADF = 9; // Bad file descriptor898 IO = 5, // Input/output error
899pub const ECHILD = 10; // No child processes899 NXIO = 6, // Device not configured
900pub const EDEADLK = 11; // Resource deadlock avoided900 @"2BIG" = 7, // Argument list too long
901// 11 was EAGAIN901 NOEXEC = 8, // Exec format error
902pub const ENOMEM = 12; // Cannot allocate memory902 BADF = 9, // Bad file descriptor
903pub const EACCES = 13; // Permission denied903 CHILD = 10, // No child processes
904pub const EFAULT = 14; // Bad address904 DEADLK = 11, // Resource deadlock avoided
905pub const ENOTBLK = 15; // Block device required905 // 11 was AGAIN
906pub const EBUSY = 16; // Device busy906 NOMEM = 12, // Cannot allocate memory
907pub const EEXIST = 17; // File exists907 ACCES = 13, // Permission denied
908pub const EXDEV = 18; // Cross-device link908 FAULT = 14, // Bad address
909pub const ENODEV = 19; // Operation not supported by device909 NOTBLK = 15, // Block device required
910pub const ENOTDIR = 20; // Not a directory910 BUSY = 16, // Device busy
911pub const EISDIR = 21; // Is a directory911 EXIST = 17, // File exists
912pub const EINVAL = 22; // Invalid argument912 XDEV = 18, // Cross-device link
913pub const ENFILE = 23; // Too many open files in system913 NODEV = 19, // Operation not supported by device
914pub const EMFILE = 24; // Too many open files914 NOTDIR = 20, // Not a directory
915pub const ENOTTY = 25; // Inappropriate ioctl for device915 ISDIR = 21, // Is a directory
916pub const ETXTBSY = 26; // Text file busy916 INVAL = 22, // Invalid argument
917pub const EFBIG = 27; // File too large917 NFILE = 23, // Too many open files in system
918pub const ENOSPC = 28; // No space left on device918 MFILE = 24, // Too many open files
919pub const ESPIPE = 29; // Illegal seek919 NOTTY = 25, // Inappropriate ioctl for device
920pub const EROFS = 30; // Read-only filesystem920 TXTBSY = 26, // Text file busy
921pub const EMLINK = 31; // Too many links921 FBIG = 27, // File too large
922pub const EPIPE = 32; // Broken pipe922 NOSPC = 28, // No space left on device
923923 SPIPE = 29, // Illegal seek
924// math software924 ROFS = 30, // Read-only filesystem
925pub const EDOM = 33; // Numerical argument out of domain925 MLINK = 31, // Too many links
926pub const ERANGE = 34; // Result too large926 PIPE = 32, // Broken pipe
927927
928// non-blocking and interrupt i/o928 // math software
929pub const EAGAIN = 35; // Resource temporarily unavailable929 DOM = 33, // Numerical argument out of domain
930pub const EWOULDBLOCK = EAGAIN; // Operation would block930 RANGE = 34, // Result too large
931pub const EINPROGRESS = 36; // Operation now in progress931
932pub const EALREADY = 37; // Operation already in progress932 // non-blocking and interrupt i/o
933933
934// ipc/network software -- argument errors934 /// Resource temporarily unavailable
935pub const ENOTSOCK = 38; // Socket operation on non-socket935 /// This code is also used for `WOULDBLOCK`: operation would block.
936pub const EDESTADDRREQ = 39; // Destination address required936 AGAIN = 35,
937pub const EMSGSIZE = 40; // Message too long937 INPROGRESS = 36, // Operation now in progress
938pub const EPROTOTYPE = 41; // Protocol wrong type for socket938 ALREADY = 37, // Operation already in progress
939pub const ENOPROTOOPT = 42; // Protocol not available939
940pub const EPROTONOSUPPORT = 43; // Protocol not supported940 // ipc/network software -- argument errors
941pub const ESOCKTNOSUPPORT = 44; // Socket type not supported941 NOTSOCK = 38, // Socket operation on non-socket
942pub const EOPNOTSUPP = 45; // Operation not supported942 DESTADDRREQ = 39, // Destination address required
943pub const ENOTSUP = EOPNOTSUPP; // Operation not supported943 MSGSIZE = 40, // Message too long
944pub const EPFNOSUPPORT = 46; // Protocol family not supported944 PROTOTYPE = 41, // Protocol wrong type for socket
945pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family945 NOPROTOOPT = 42, // Protocol not available
946pub const EADDRINUSE = 48; // Address already in use946 PROTONOSUPPORT = 43, // Protocol not supported
947pub const EADDRNOTAVAIL = 49; // Can't assign requested address947 SOCKTNOSUPPORT = 44, // Socket type not supported
948948 /// Operation not supported
949// ipc/network software -- operational errors949 /// This code is also used for `NOTSUP`.
950pub const ENETDOWN = 50; // Network is down950 OPNOTSUPP = 45,
951pub const ENETUNREACH = 51; // Network is unreachable951 PFNOSUPPORT = 46, // Protocol family not supported
952pub const ENETRESET = 52; // Network dropped connection on reset952 AFNOSUPPORT = 47, // Address family not supported by protocol family
953pub const ECONNABORTED = 53; // Software caused connection abort953 ADDRINUSE = 48, // Address already in use
954pub const ECONNRESET = 54; // Connection reset by peer954 ADDRNOTAVAIL = 49, // Can't assign requested address
955pub const ENOBUFS = 55; // No buffer space available955
956pub const EISCONN = 56; // Socket is already connected956 // ipc/network software -- operational errors
957pub const ENOTCONN = 57; // Socket is not connected957 NETDOWN = 50, // Network is down
958pub const ESHUTDOWN = 58; // Can't send after socket shutdown958 NETUNREACH = 51, // Network is unreachable
959pub const ETOOMANYREFS = 59; // Too many references: can't splice959 NETRESET = 52, // Network dropped connection on reset
960pub const ETIMEDOUT = 60; // Operation timed out960 CONNABORTED = 53, // Software caused connection abort
961pub const ECONNREFUSED = 61; // Connection refused961 CONNRESET = 54, // Connection reset by peer
962962 NOBUFS = 55, // No buffer space available
963pub const ELOOP = 62; // Too many levels of symbolic links963 ISCONN = 56, // Socket is already connected
964pub const ENAMETOOLONG = 63; // File name too long964 NOTCONN = 57, // Socket is not connected
965965 SHUTDOWN = 58, // Can't send after socket shutdown
966// should be rearranged966 TOOMANYREFS = 59, // Too many references: can't splice
967pub const EHOSTDOWN = 64; // Host is down967 TIMEDOUT = 60, // Operation timed out
968pub const EHOSTUNREACH = 65; // No route to host968 CONNREFUSED = 61, // Connection refused
969pub const ENOTEMPTY = 66; // Directory not empty969
970970 LOOP = 62, // Too many levels of symbolic links
971// quotas & mush971 NAMETOOLONG = 63, // File name too long
972pub const EPROCLIM = 67; // Too many processes972
973pub const EUSERS = 68; // Too many users973 // should be rearranged
974pub const EDQUOT = 69; // Disc quota exceeded974 HOSTDOWN = 64, // Host is down
975975 HOSTUNREACH = 65, // No route to host
976// Network File System976 NOTEMPTY = 66, // Directory not empty
977pub const ESTALE = 70; // Stale NFS file handle977
978pub const EREMOTE = 71; // Too many levels of remote in path978 // quotas & mush
979pub const EBADRPC = 72; // RPC struct is bad979 PROCLIM = 67, // Too many processes
980pub const ERPCMISMATCH = 73; // RPC version wrong980 USERS = 68, // Too many users
981pub const EPROGUNAVAIL = 74; // RPC prog. not avail981 DQUOT = 69, // Disc quota exceeded
982pub const EPROGMISMATCH = 75; // Program version wrong982
983pub const EPROCUNAVAIL = 76; // Bad procedure for program983 // Network File System
984984 STALE = 70, // Stale NFS file handle
985pub const ENOLCK = 77; // No locks available985 REMOTE = 71, // Too many levels of remote in path
986pub const ENOSYS = 78; // Function not implemented986 BADRPC = 72, // RPC struct is bad
987987 RPCMISMATCH = 73, // RPC version wrong
988pub const EFTYPE = 79; // Inappropriate file type or format988 PROGUNAVAIL = 74, // RPC prog. not avail
989pub const EAUTH = 80; // Authentication error989 PROGMISMATCH = 75, // Program version wrong
990pub const ENEEDAUTH = 81; // Need authenticator990 PROCUNAVAIL = 76, // Bad procedure for program
991pub const EIDRM = 82; // Identifier removed991
992pub const ENOMSG = 83; // No message of desired type992 NOLCK = 77, // No locks available
993pub const EOVERFLOW = 84; // Value too large to be stored in data type993 NOSYS = 78, // Function not implemented
994pub const ECANCELED = 85; // Operation canceled994
995pub const EILSEQ = 86; // Illegal byte sequence995 FTYPE = 79, // Inappropriate file type or format
996pub const ENOATTR = 87; // Attribute not found996 AUTH = 80, // Authentication error
997997 NEEDAUTH = 81, // Need authenticator
998pub const EDOOFUS = 88; // Programming error998 IDRM = 82, // Identifier removed
999999 NOMSG = 83, // No message of desired type
1000pub const EBADMSG = 89; // Bad message1000 OVERFLOW = 84, // Value too large to be stored in data type
1001pub const EMULTIHOP = 90; // Multihop attempted1001 CANCELED = 85, // Operation canceled
1002pub const ENOLINK = 91; // Link has been severed1002 ILSEQ = 86, // Illegal byte sequence
1003pub const EPROTO = 92; // Protocol error1003 NOATTR = 87, // Attribute not found
10041004
1005pub const ENOTCAPABLE = 93; // Capabilities insufficient1005 DOOFUS = 88, // Programming error
1006pub const ECAPMODE = 94; // Not permitted in capability mode1006
1007pub const ENOTRECOVERABLE = 95; // State not recoverable1007 BADMSG = 89, // Bad message
1008pub const EOWNERDEAD = 96; // Previous owner died1008 MULTIHOP = 90, // Multihop attempted
10091009 NOLINK = 91, // Link has been severed
1010pub const ELAST = 96; // Must be equal largest errno1010 PROTO = 92, // Protocol error
1011
1012 NOTCAPABLE = 93, // Capabilities insufficient
1013 CAPMODE = 94, // Not permitted in capability mode
1014 NOTRECOVERABLE = 95, // State not recoverable
1015 OWNERDEAD = 96, // Previous owner died
1016 _,
1017};
10111018
1012pub const MINSIGSTKSZ = switch (builtin.target.cpu.arch) {1019pub const MINSIGSTKSZ = switch (builtin.target.cpu.arch) {
1013 .i386, .x86_64 => 2048,1020 .i386, .x86_64 => 2048,
lib/std/os/bits/haiku.zig+124-119
...@@ -734,125 +734,130 @@ pub const sigset_t = extern struct {...@@ -734,125 +734,130 @@ pub const sigset_t = extern struct {
734 __bits: [_SIG_WORDS]u32,734 __bits: [_SIG_WORDS]u32,
735};735};
736736
737pub const EPERM = -0x7ffffff1; // Operation not permitted737pub const E = enum(i32) {
738pub const ENOENT = -0x7fff9ffd; // No such file or directory738 /// No error occurred.
739pub const ESRCH = -0x7fff8ff3; // No such process739 SUCCESS = 0,
740pub const EINTR = -0x7ffffff6; // Interrupted system call740 PERM = -0x7ffffff1, // Operation not permitted
741pub const EIO = -0x7fffffff; // Input/output error741 NOENT = -0x7fff9ffd, // No such file or directory
742pub const ENXIO = -0x7fff8ff5; // Device not configured742 SRCH = -0x7fff8ff3, // No such process
743pub const E2BIG = -0x7fff8fff; // Argument list too long743 INTR = -0x7ffffff6, // Interrupted system call
744pub const ENOEXEC = -0x7fffecfe; // Exec format error744 IO = -0x7fffffff, // Input/output error
745pub const ECHILD = -0x7fff8ffe; // No child processes745 NXIO = -0x7fff8ff5, // Device not configured
746pub const EDEADLK = -0x7fff8ffd; // Resource deadlock avoided746 @"2BIG" = -0x7fff8fff, // Argument list too long
747pub const ENOMEM = -0x80000000; // Cannot allocate memory747 NOEXEC = -0x7fffecfe, // Exec format error
748pub const EACCES = -0x7ffffffe; // Permission denied748 CHILD = -0x7fff8ffe, // No child processes
749pub const EFAULT = -0x7fffecff; // Bad address749 DEADLK = -0x7fff8ffd, // Resource deadlock avoided
750pub const EBUSY = -0x7ffffff2; // Device busy750 NOMEM = -0x80000000, // Cannot allocate memory
751pub const EEXIST = -0x7fff9ffe; // File exists751 ACCES = -0x7ffffffe, // Permission denied
752pub const EXDEV = -0x7fff9ff5; // Cross-device link752 FAULT = -0x7fffecff, // Bad address
753pub const ENODEV = -0x7fff8ff9; // Operation not supported by device753 BUSY = -0x7ffffff2, // Device busy
754pub const ENOTDIR = -0x7fff9ffb; // Not a directory754 EXIST = -0x7fff9ffe, // File exists
755pub const EISDIR = -0x7fff9ff7; // Is a directory755 XDEV = -0x7fff9ff5, // Cross-device link
756pub const EINVAL = -0x7ffffffb; // Invalid argument756 NODEV = -0x7fff8ff9, // Operation not supported by device
757pub const ENFILE = -0x7fff8ffa; // Too many open files in system757 NOTDIR = -0x7fff9ffb, // Not a directory
758pub const EMFILE = -0x7fff9ff6; // Too many open files758 ISDIR = -0x7fff9ff7, // Is a directory
759pub const ENOTTY = -0x7fff8ff6; // Inappropriate ioctl for device759 INVAL = -0x7ffffffb, // Invalid argument
760pub const ETXTBSY = -0x7fff8fc5; // Text file busy760 NFILE = -0x7fff8ffa, // Too many open files in system
761pub const EFBIG = -0x7fff8ffc; // File too large761 MFILE = -0x7fff9ff6, // Too many open files
762pub const ENOSPC = -0x7fff9ff9; // No space left on device762 NOTTY = -0x7fff8ff6, // Inappropriate ioctl for device
763pub const ESPIPE = -0x7fff8ff4; // Illegal seek763 TXTBSY = -0x7fff8fc5, // Text file busy
764pub const EROFS = -0x7fff9ff8; // Read-only filesystem764 FBIG = -0x7fff8ffc, // File too large
765pub const EMLINK = -0x7fff8ffb; // Too many links765 NOSPC = -0x7fff9ff9, // No space left on device
766pub const EPIPE = -0x7fff9ff3; // Broken pipe766 SPIPE = -0x7fff8ff4, // Illegal seek
767pub const EBADF = -0x7fffa000; // Bad file descriptor767 ROFS = -0x7fff9ff8, // Read-only filesystem
768768 MLINK = -0x7fff8ffb, // Too many links
769// math software769 PIPE = -0x7fff9ff3, // Broken pipe
770pub const EDOM = 33; // Numerical argument out of domain770 BADF = -0x7fffa000, // Bad file descriptor
771pub const ERANGE = 34; // Result too large771
772772 // math software
773// non-blocking and interrupt i/o773 DOM = 33, // Numerical argument out of domain
774pub const EAGAIN = -0x7ffffff5;774 RANGE = 34, // Result too large
775pub const EWOULDBLOCK = -0x7ffffff5;775
776pub const EINPROGRESS = -0x7fff8fdc;776 // non-blocking and interrupt i/o
777pub const EALREADY = -0x7fff8fdb;777
778778 /// Also used for `WOULDBLOCK`.
779// ipc/network software -- argument errors779 AGAIN = -0x7ffffff5,
780pub const ENOTSOCK = 38; // Socket operation on non-socket780 INPROGRESS = -0x7fff8fdc,
781pub const EDESTADDRREQ = 39; // Destination address required781 ALREADY = -0x7fff8fdb,
782pub const EMSGSIZE = 40; // Message too long782
783pub const EPROTOTYPE = 41; // Protocol wrong type for socket783 // ipc/network software -- argument errors
784pub const ENOPROTOOPT = 42; // Protocol not available784 NOTSOCK = 38, // Socket operation on non-socket
785pub const EPROTONOSUPPORT = 43; // Protocol not supported785 DESTADDRREQ = 39, // Destination address required
786pub const ESOCKTNOSUPPORT = 44; // Socket type not supported786 MSGSIZE = 40, // Message too long
787pub const EOPNOTSUPP = 45; // Operation not supported787 PROTOTYPE = 41, // Protocol wrong type for socket
788pub const ENOTSUP = EOPNOTSUPP; // Operation not supported788 NOPROTOOPT = 42, // Protocol not available
789pub const EPFNOSUPPORT = 46; // Protocol family not supported789 PROTONOSUPPORT = 43, // Protocol not supported
790pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family790 SOCKTNOSUPPORT = 44, // Socket type not supported
791pub const EADDRINUSE = 48; // Address already in use791 /// Also used for `NOTSUP`.
792pub const EADDRNOTAVAIL = 49; // Can't assign requested address792 OPNOTSUPP = 45, // Operation not supported
793793 PFNOSUPPORT = 46, // Protocol family not supported
794// ipc/network software -- operational errors794 AFNOSUPPORT = 47, // Address family not supported by protocol family
795pub const ENETDOWN = 50; // Network is down795 ADDRINUSE = 48, // Address already in use
796pub const ENETUNREACH = 51; // Network is unreachable796 ADDRNOTAVAIL = 49, // Can't assign requested address
797pub const ENETRESET = 52; // Network dropped connection on reset797
798pub const ECONNABORTED = 53; // Software caused connection abort798 // ipc/network software -- operational errors
799pub const ECONNRESET = 54; // Connection reset by peer799 NETDOWN = 50, // Network is down
800pub const ENOBUFS = 55; // No buffer space available800 NETUNREACH = 51, // Network is unreachable
801pub const EISCONN = 56; // Socket is already connected801 NETRESET = 52, // Network dropped connection on reset
802pub const ENOTCONN = 57; // Socket is not connected802 CONNABORTED = 53, // Software caused connection abort
803pub const ESHUTDOWN = 58; // Can't send after socket shutdown803 CONNRESET = 54, // Connection reset by peer
804pub const ETOOMANYREFS = 59; // Too many references: can't splice804 NOBUFS = 55, // No buffer space available
805pub const ETIMEDOUT = 60; // Operation timed out805 ISCONN = 56, // Socket is already connected
806pub const ECONNREFUSED = 61; // Connection refused806 NOTCONN = 57, // Socket is not connected
807807 SHUTDOWN = 58, // Can't send after socket shutdown
808pub const ELOOP = 62; // Too many levels of symbolic links808 TOOMANYREFS = 59, // Too many references: can't splice
809pub const ENAMETOOLONG = 63; // File name too long809 TIMEDOUT = 60, // Operation timed out
810810 CONNREFUSED = 61, // Connection refused
811// should be rearranged811
812pub const EHOSTDOWN = 64; // Host is down812 LOOP = 62, // Too many levels of symbolic links
813pub const EHOSTUNREACH = 65; // No route to host813 NAMETOOLONG = 63, // File name too long
814pub const ENOTEMPTY = 66; // Directory not empty814
815815 // should be rearranged
816// quotas & mush816 HOSTDOWN = 64, // Host is down
817pub const EPROCLIM = 67; // Too many processes817 HOSTUNREACH = 65, // No route to host
818pub const EUSERS = 68; // Too many users818 NOTEMPTY = 66, // Directory not empty
819pub const EDQUOT = 69; // Disc quota exceeded819
820820 // quotas & mush
821// Network File System821 PROCLIM = 67, // Too many processes
822pub const ESTALE = 70; // Stale NFS file handle822 USERS = 68, // Too many users
823pub const EREMOTE = 71; // Too many levels of remote in path823 DQUOT = 69, // Disc quota exceeded
824pub const EBADRPC = 72; // RPC struct is bad824
825pub const ERPCMISMATCH = 73; // RPC version wrong825 // Network File System
826pub const EPROGUNAVAIL = 74; // RPC prog. not avail826 STALE = 70, // Stale NFS file handle
827pub const EPROGMISMATCH = 75; // Program version wrong827 REMOTE = 71, // Too many levels of remote in path
828pub const EPROCUNAVAIL = 76; // Bad procedure for program828 BADRPC = 72, // RPC struct is bad
829829 RPCMISMATCH = 73, // RPC version wrong
830pub const ENOLCK = 77; // No locks available830 PROGUNAVAIL = 74, // RPC prog. not avail
831pub const ENOSYS = 78; // Function not implemented831 PROGMISMATCH = 75, // Program version wrong
832832 PROCUNAVAIL = 76, // Bad procedure for program
833pub const EFTYPE = 79; // Inappropriate file type or format833
834pub const EAUTH = 80; // Authentication error834 NOLCK = 77, // No locks available
835pub const ENEEDAUTH = 81; // Need authenticator835 NOSYS = 78, // Function not implemented
836pub const EIDRM = 82; // Identifier removed836
837pub const ENOMSG = 83; // No message of desired type837 FTYPE = 79, // Inappropriate file type or format
838pub const EOVERFLOW = 84; // Value too large to be stored in data type838 AUTH = 80, // Authentication error
839pub const ECANCELED = 85; // Operation canceled839 NEEDAUTH = 81, // Need authenticator
840pub const EILSEQ = 86; // Illegal byte sequence840 IDRM = 82, // Identifier removed
841pub const ENOATTR = 87; // Attribute not found841 NOMSG = 83, // No message of desired type
842842 OVERFLOW = 84, // Value too large to be stored in data type
843pub const EDOOFUS = 88; // Programming error843 CANCELED = 85, // Operation canceled
844844 ILSEQ = 86, // Illegal byte sequence
845pub const EBADMSG = 89; // Bad message845 NOATTR = 87, // Attribute not found
846pub const EMULTIHOP = 90; // Multihop attempted846
847pub const ENOLINK = 91; // Link has been severed847 DOOFUS = 88, // Programming error
848pub const EPROTO = 92; // Protocol error848
849849 BADMSG = 89, // Bad message
850pub const ENOTCAPABLE = 93; // Capabilities insufficient850 MULTIHOP = 90, // Multihop attempted
851pub const ECAPMODE = 94; // Not permitted in capability mode851 NOLINK = 91, // Link has been severed
852pub const ENOTRECOVERABLE = 95; // State not recoverable852 PROTO = 92, // Protocol error
853pub const EOWNERDEAD = 96; // Previous owner died853
854854 NOTCAPABLE = 93, // Capabilities insufficient
855pub const ELAST = 96; // Must be equal largest errno855 CAPMODE = 94, // Not permitted in capability mode
856 NOTRECOVERABLE = 95, // State not recoverable
857 OWNERDEAD = 96, // Previous owner died
858
859 _,
860};
856861
857pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {862pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
858 .i386, .x86_64 => 2048,863 .i386, .x86_64 => 2048,
lib/std/os/bits/linux.zig+11-4
...@@ -8,10 +8,10 @@ const maxInt = std.math.maxInt;...@@ -8,10 +8,10 @@ const maxInt = std.math.maxInt;
8const arch = @import("builtin").target.cpu.arch;8const arch = @import("builtin").target.cpu.arch;
9pub usingnamespace @import("posix.zig");9pub usingnamespace @import("posix.zig");
1010
11pub usingnamespace switch (arch) {11pub const E = switch (arch) {
12 .mips, .mipsel => @import("linux/errno-mips.zig"),12 .mips, .mipsel => @import("linux/errno/mips.zig").E,
13 .sparc, .sparcel, .sparcv9 => @import("linux/errno-sparc.zig"),13 .sparc, .sparcel, .sparcv9 => @import("linux/errno/sparc.zig").E,
14 else => @import("linux/errno-generic.zig"),14 else => @import("linux/errno/generic.zig").E,
15};15};
1616
17pub usingnamespace switch (arch) {17pub usingnamespace switch (arch) {
...@@ -1665,6 +1665,13 @@ pub const io_uring_cqe = extern struct {...@@ -1665,6 +1665,13 @@ pub const io_uring_cqe = extern struct {
1665 /// result code for this event1665 /// result code for this event
1666 res: i32,1666 res: i32,
1667 flags: u32,1667 flags: u32,
1668
1669 pub fn err(self: io_uring_cqe) E {
1670 if (self.res > -4096 and self.res < 0) {
1671 return @intToEnum(E, -self.res);
1672 }
1673 return .SUCCESS;
1674 }
1668};1675};
16691676
1670// io_uring_cqe.flags1677// io_uring_cqe.flags
lib/std/os/bits/linux/errno-generic.zig deleted-462
...@@ -1,462 +0,0 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6/// Operation not permitted
7pub const EPERM = 1;
8
9/// No such file or directory
10pub const ENOENT = 2;
11
12/// No such process
13pub const ESRCH = 3;
14
15/// Interrupted system call
16pub const EINTR = 4;
17
18/// I/O error
19pub const EIO = 5;
20
21/// No such device or address
22pub const ENXIO = 6;
23
24/// Arg list too long
25pub const E2BIG = 7;
26
27/// Exec format error
28pub const ENOEXEC = 8;
29
30/// Bad file number
31pub const EBADF = 9;
32
33/// No child processes
34pub const ECHILD = 10;
35
36/// Try again
37pub const EAGAIN = 11;
38
39/// Out of memory
40pub const ENOMEM = 12;
41
42/// Permission denied
43pub const EACCES = 13;
44
45/// Bad address
46pub const EFAULT = 14;
47
48/// Block device required
49pub const ENOTBLK = 15;
50
51/// Device or resource busy
52pub const EBUSY = 16;
53
54/// File exists
55pub const EEXIST = 17;
56
57/// Cross-device link
58pub const EXDEV = 18;
59
60/// No such device
61pub const ENODEV = 19;
62
63/// Not a directory
64pub const ENOTDIR = 20;
65
66/// Is a directory
67pub const EISDIR = 21;
68
69/// Invalid argument
70pub const EINVAL = 22;
71
72/// File table overflow
73pub const ENFILE = 23;
74
75/// Too many open files
76pub const EMFILE = 24;
77
78/// Not a typewriter
79pub const ENOTTY = 25;
80
81/// Text file busy
82pub const ETXTBSY = 26;
83
84/// File too large
85pub const EFBIG = 27;
86
87/// No space left on device
88pub const ENOSPC = 28;
89
90/// Illegal seek
91pub const ESPIPE = 29;
92
93/// Read-only file system
94pub const EROFS = 30;
95
96/// Too many links
97pub const EMLINK = 31;
98
99/// Broken pipe
100pub const EPIPE = 32;
101
102/// Math argument out of domain of func
103pub const EDOM = 33;
104
105/// Math result not representable
106pub const ERANGE = 34;
107
108/// Resource deadlock would occur
109pub const EDEADLK = 35;
110
111/// File name too long
112pub const ENAMETOOLONG = 36;
113
114/// No record locks available
115pub const ENOLCK = 37;
116
117/// Function not implemented
118pub const ENOSYS = 38;
119
120/// Directory not empty
121pub const ENOTEMPTY = 39;
122
123/// Too many symbolic links encountered
124pub const ELOOP = 40;
125
126/// Operation would block
127pub const EWOULDBLOCK = EAGAIN;
128
129/// No message of desired type
130pub const ENOMSG = 42;
131
132/// Identifier removed
133pub const EIDRM = 43;
134
135/// Channel number out of range
136pub const ECHRNG = 44;
137
138/// Level 2 not synchronized
139pub const EL2NSYNC = 45;
140
141/// Level 3 halted
142pub const EL3HLT = 46;
143
144/// Level 3 reset
145pub const EL3RST = 47;
146
147/// Link number out of range
148pub const ELNRNG = 48;
149
150/// Protocol driver not attached
151pub const EUNATCH = 49;
152
153/// No CSI structure available
154pub const ENOCSI = 50;
155
156/// Level 2 halted
157pub const EL2HLT = 51;
158
159/// Invalid exchange
160pub const EBADE = 52;
161
162/// Invalid request descriptor
163pub const EBADR = 53;
164
165/// Exchange full
166pub const EXFULL = 54;
167
168/// No anode
169pub const ENOANO = 55;
170
171/// Invalid request code
172pub const EBADRQC = 56;
173
174/// Invalid slot
175pub const EBADSLT = 57;
176
177/// Bad font file format
178pub const EBFONT = 59;
179
180/// Device not a stream
181pub const ENOSTR = 60;
182
183/// No data available
184pub const ENODATA = 61;
185
186/// Timer expired
187pub const ETIME = 62;
188
189/// Out of streams resources
190pub const ENOSR = 63;
191
192/// Machine is not on the network
193pub const ENONET = 64;
194
195/// Package not installed
196pub const ENOPKG = 65;
197
198/// Object is remote
199pub const EREMOTE = 66;
200
201/// Link has been severed
202pub const ENOLINK = 67;
203
204/// Advertise error
205pub const EADV = 68;
206
207/// Srmount error
208pub const ESRMNT = 69;
209
210/// Communication error on send
211pub const ECOMM = 70;
212
213/// Protocol error
214pub const EPROTO = 71;
215
216/// Multihop attempted
217pub const EMULTIHOP = 72;
218
219/// RFS specific error
220pub const EDOTDOT = 73;
221
222/// Not a data message
223pub const EBADMSG = 74;
224
225/// Value too large for defined data type
226pub const EOVERFLOW = 75;
227
228/// Name not unique on network
229pub const ENOTUNIQ = 76;
230
231/// File descriptor in bad state
232pub const EBADFD = 77;
233
234/// Remote address changed
235pub const EREMCHG = 78;
236
237/// Can not access a needed shared library
238pub const ELIBACC = 79;
239
240/// Accessing a corrupted shared library
241pub const ELIBBAD = 80;
242
243/// .lib section in a.out corrupted
244pub const ELIBSCN = 81;
245
246/// Attempting to link in too many shared libraries
247pub const ELIBMAX = 82;
248
249/// Cannot exec a shared library directly
250pub const ELIBEXEC = 83;
251
252/// Illegal byte sequence
253pub const EILSEQ = 84;
254
255/// Interrupted system call should be restarted
256pub const ERESTART = 85;
257
258/// Streams pipe error
259pub const ESTRPIPE = 86;
260
261/// Too many users
262pub const EUSERS = 87;
263
264/// Socket operation on non-socket
265pub const ENOTSOCK = 88;
266
267/// Destination address required
268pub const EDESTADDRREQ = 89;
269
270/// Message too long
271pub const EMSGSIZE = 90;
272
273/// Protocol wrong type for socket
274pub const EPROTOTYPE = 91;
275
276/// Protocol not available
277pub const ENOPROTOOPT = 92;
278
279/// Protocol not supported
280pub const EPROTONOSUPPORT = 93;
281
282/// Socket type not supported
283pub const ESOCKTNOSUPPORT = 94;
284
285/// Operation not supported on transport endpoint
286pub const EOPNOTSUPP = 95;
287pub const ENOTSUP = EOPNOTSUPP;
288
289/// Protocol family not supported
290pub const EPFNOSUPPORT = 96;
291
292/// Address family not supported by protocol
293pub const EAFNOSUPPORT = 97;
294
295/// Address already in use
296pub const EADDRINUSE = 98;
297
298/// Cannot assign requested address
299pub const EADDRNOTAVAIL = 99;
300
301/// Network is down
302pub const ENETDOWN = 100;
303
304/// Network is unreachable
305pub const ENETUNREACH = 101;
306
307/// Network dropped connection because of reset
308pub const ENETRESET = 102;
309
310/// Software caused connection abort
311pub const ECONNABORTED = 103;
312
313/// Connection reset by peer
314pub const ECONNRESET = 104;
315
316/// No buffer space available
317pub const ENOBUFS = 105;
318
319/// Transport endpoint is already connected
320pub const EISCONN = 106;
321
322/// Transport endpoint is not connected
323pub const ENOTCONN = 107;
324
325/// Cannot send after transport endpoint shutdown
326pub const ESHUTDOWN = 108;
327
328/// Too many references: cannot splice
329pub const ETOOMANYREFS = 109;
330
331/// Connection timed out
332pub const ETIMEDOUT = 110;
333
334/// Connection refused
335pub const ECONNREFUSED = 111;
336
337/// Host is down
338pub const EHOSTDOWN = 112;
339
340/// No route to host
341pub const EHOSTUNREACH = 113;
342
343/// Operation already in progress
344pub const EALREADY = 114;
345
346/// Operation now in progress
347pub const EINPROGRESS = 115;
348
349/// Stale NFS file handle
350pub const ESTALE = 116;
351
352/// Structure needs cleaning
353pub const EUCLEAN = 117;
354
355/// Not a XENIX named type file
356pub const ENOTNAM = 118;
357
358/// No XENIX semaphores available
359pub const ENAVAIL = 119;
360
361/// Is a named type file
362pub const EISNAM = 120;
363
364/// Remote I/O error
365pub const EREMOTEIO = 121;
366
367/// Quota exceeded
368pub const EDQUOT = 122;
369
370/// No medium found
371pub const ENOMEDIUM = 123;
372
373/// Wrong medium type
374pub const EMEDIUMTYPE = 124;
375
376/// Operation canceled
377pub const ECANCELED = 125;
378
379/// Required key not available
380pub const ENOKEY = 126;
381
382/// Key has expired
383pub const EKEYEXPIRED = 127;
384
385/// Key has been revoked
386pub const EKEYREVOKED = 128;
387
388/// Key was rejected by service
389pub const EKEYREJECTED = 129;
390
391// for robust mutexes
392
393/// Owner died
394pub const EOWNERDEAD = 130;
395
396/// State not recoverable
397pub const ENOTRECOVERABLE = 131;
398
399/// Operation not possible due to RF-kill
400pub const ERFKILL = 132;
401
402/// Memory page has hardware error
403pub const EHWPOISON = 133;
404
405// nameserver query return codes
406
407/// DNS server returned answer with no data
408pub const ENSROK = 0;
409
410/// DNS server returned answer with no data
411pub const ENSRNODATA = 160;
412
413/// DNS server claims query was misformatted
414pub const ENSRFORMERR = 161;
415
416/// DNS server returned general failure
417pub const ENSRSERVFAIL = 162;
418
419/// Domain name not found
420pub const ENSRNOTFOUND = 163;
421
422/// DNS server does not implement requested operation
423pub const ENSRNOTIMP = 164;
424
425/// DNS server refused query
426pub const ENSRREFUSED = 165;
427
428/// Misformatted DNS query
429pub const ENSRBADQUERY = 166;
430
431/// Misformatted domain name
432pub const ENSRBADNAME = 167;
433
434/// Unsupported address family
435pub const ENSRBADFAMILY = 168;
436
437/// Misformatted DNS reply
438pub const ENSRBADRESP = 169;
439
440/// Could not contact DNS servers
441pub const ENSRCONNREFUSED = 170;
442
443/// Timeout while contacting DNS servers
444pub const ENSRTIMEOUT = 171;
445
446/// End of file
447pub const ENSROF = 172;
448
449/// Error reading file
450pub const ENSRFILE = 173;
451
452/// Out of memory
453pub const ENSRNOMEM = 174;
454
455/// Application terminated lookup
456pub const ENSRDESTRUCTION = 175;
457
458/// Domain name is too long
459pub const ENSRQUERYDOMAINTOOLONG = 176;
460
461/// Domain name is too long
462pub const ENSRCNAMELOOP = 177;
lib/std/os/bits/linux/errno-mips.zig deleted-143
...@@ -1,143 +0,0 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7// These are MIPS ABI compatible.
8
9pub const EPERM = 1;
10pub const ENOENT = 2;
11pub const ESRCH = 3;
12pub const EINTR = 4;
13pub const EIO = 5;
14pub const ENXIO = 6;
15pub const E2BIG = 7;
16pub const ENOEXEC = 8;
17pub const EBADF = 9;
18pub const ECHILD = 10;
19pub const EAGAIN = 11;
20pub const ENOMEM = 12;
21pub const EACCES = 13;
22pub const EFAULT = 14;
23pub const ENOTBLK = 15;
24pub const EBUSY = 16;
25pub const EEXIST = 17;
26pub const EXDEV = 18;
27pub const ENODEV = 19;
28pub const ENOTDIR = 20;
29pub const EISDIR = 21;
30pub const EINVAL = 22;
31pub const ENFILE = 23;
32pub const EMFILE = 24;
33pub const ENOTTY = 25;
34pub const ETXTBSY = 26;
35pub const EFBIG = 27;
36pub const ENOSPC = 28;
37pub const ESPIPE = 29;
38pub const EROFS = 30;
39pub const EMLINK = 31;
40pub const EPIPE = 32;
41pub const EDOM = 33;
42pub const ERANGE = 34;
43
44pub const ENOMSG = 35;
45pub const EIDRM = 36;
46pub const ECHRNG = 37;
47pub const EL2NSYNC = 38;
48pub const EL3HLT = 39;
49pub const EL3RST = 40;
50pub const ELNRNG = 41;
51pub const EUNATCH = 42;
52pub const ENOCSI = 43;
53pub const EL2HLT = 44;
54pub const EDEADLK = 45;
55pub const ENOLCK = 46;
56pub const EBADE = 50;
57pub const EBADR = 51;
58pub const EXFULL = 52;
59pub const ENOANO = 53;
60pub const EBADRQC = 54;
61pub const EBADSLT = 55;
62pub const EDEADLOCK = 56;
63pub const EBFONT = 59;
64pub const ENOSTR = 60;
65pub const ENODATA = 61;
66pub const ETIME = 62;
67pub const ENOSR = 63;
68pub const ENONET = 64;
69pub const ENOPKG = 65;
70pub const EREMOTE = 66;
71pub const ENOLINK = 67;
72pub const EADV = 68;
73pub const ESRMNT = 69;
74pub const ECOMM = 70;
75pub const EPROTO = 71;
76pub const EDOTDOT = 73;
77pub const EMULTIHOP = 74;
78pub const EBADMSG = 77;
79pub const ENAMETOOLONG = 78;
80pub const EOVERFLOW = 79;
81pub const ENOTUNIQ = 80;
82pub const EBADFD = 81;
83pub const EREMCHG = 82;
84pub const ELIBACC = 83;
85pub const ELIBBAD = 84;
86pub const ELIBSCN = 85;
87pub const ELIBMAX = 86;
88pub const ELIBEXEC = 87;
89pub const EILSEQ = 88;
90pub const ENOSYS = 89;
91pub const ELOOP = 90;
92pub const ERESTART = 91;
93pub const ESTRPIPE = 92;
94pub const ENOTEMPTY = 93;
95pub const EUSERS = 94;
96pub const ENOTSOCK = 95;
97pub const EDESTADDRREQ = 96;
98pub const EMSGSIZE = 97;
99pub const EPROTOTYPE = 98;
100pub const ENOPROTOOPT = 99;
101pub const EPROTONOSUPPORT = 120;
102pub const ESOCKTNOSUPPORT = 121;
103pub const EOPNOTSUPP = 122;
104pub const ENOTSUP = EOPNOTSUPP;
105pub const EPFNOSUPPORT = 123;
106pub const EAFNOSUPPORT = 124;
107pub const EADDRINUSE = 125;
108pub const EADDRNOTAVAIL = 126;
109pub const ENETDOWN = 127;
110pub const ENETUNREACH = 128;
111pub const ENETRESET = 129;
112pub const ECONNABORTED = 130;
113pub const ECONNRESET = 131;
114pub const ENOBUFS = 132;
115pub const EISCONN = 133;
116pub const ENOTCONN = 134;
117pub const EUCLEAN = 135;
118pub const ENOTNAM = 137;
119pub const ENAVAIL = 138;
120pub const EISNAM = 139;
121pub const EREMOTEIO = 140;
122pub const ESHUTDOWN = 143;
123pub const ETOOMANYREFS = 144;
124pub const ETIMEDOUT = 145;
125pub const ECONNREFUSED = 146;
126pub const EHOSTDOWN = 147;
127pub const EHOSTUNREACH = 148;
128pub const EWOULDBLOCK = EAGAIN;
129pub const EALREADY = 149;
130pub const EINPROGRESS = 150;
131pub const ESTALE = 151;
132pub const ECANCELED = 158;
133pub const ENOMEDIUM = 159;
134pub const EMEDIUMTYPE = 160;
135pub const ENOKEY = 161;
136pub const EKEYEXPIRED = 162;
137pub const EKEYREVOKED = 163;
138pub const EKEYREJECTED = 164;
139pub const EOWNERDEAD = 165;
140pub const ENOTRECOVERABLE = 166;
141pub const ERFKILL = 167;
142pub const EHWPOISON = 168;
143pub const EDQUOT = 1133;
lib/std/os/bits/linux/errno-sparc.zig deleted-145
...@@ -1,145 +0,0 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7// These match the SunOS error numbering scheme.
8
9pub const EPERM = 1;
10pub const ENOENT = 2;
11pub const ESRCH = 3;
12pub const EINTR = 4;
13pub const EIO = 5;
14pub const ENXIO = 6;
15pub const E2BIG = 7;
16pub const ENOEXEC = 8;
17pub const EBADF = 9;
18pub const ECHILD = 10;
19pub const EAGAIN = 11;
20pub const ENOMEM = 12;
21pub const EACCES = 13;
22pub const EFAULT = 14;
23pub const ENOTBLK = 15;
24pub const EBUSY = 16;
25pub const EEXIST = 17;
26pub const EXDEV = 18;
27pub const ENODEV = 19;
28pub const ENOTDIR = 20;
29pub const EISDIR = 21;
30pub const EINVAL = 22;
31pub const ENFILE = 23;
32pub const EMFILE = 24;
33pub const ENOTTY = 25;
34pub const ETXTBSY = 26;
35pub const EFBIG = 27;
36pub const ENOSPC = 28;
37pub const ESPIPE = 29;
38pub const EROFS = 30;
39pub const EMLINK = 31;
40pub const EPIPE = 32;
41pub const EDOM = 33;
42pub const ERANGE = 34;
43
44pub const EWOULDBLOCK = EAGAIN;
45pub const EINPROGRESS = 36;
46pub const EALREADY = 37;
47pub const ENOTSOCK = 38;
48pub const EDESTADDRREQ = 39;
49pub const EMSGSIZE = 40;
50pub const EPROTOTYPE = 41;
51pub const ENOPROTOOPT = 42;
52pub const EPROTONOSUPPORT = 43;
53pub const ESOCKTNOSUPPORT = 44;
54pub const EOPNOTSUPP = 45;
55pub const ENOTSUP = EOPNOTSUPP;
56pub const EPFNOSUPPORT = 46;
57pub const EAFNOSUPPORT = 47;
58pub const EADDRINUSE = 48;
59pub const EADDRNOTAVAIL = 49;
60pub const ENETDOWN = 50;
61pub const ENETUNREACH = 51;
62pub const ENETRESET = 52;
63pub const ECONNABORTED = 53;
64pub const ECONNRESET = 54;
65pub const ENOBUFS = 55;
66pub const EISCONN = 56;
67pub const ENOTCONN = 57;
68pub const ESHUTDOWN = 58;
69pub const ETOOMANYREFS = 59;
70pub const ETIMEDOUT = 60;
71pub const ECONNREFUSED = 61;
72pub const ELOOP = 62;
73pub const ENAMETOOLONG = 63;
74pub const EHOSTDOWN = 64;
75pub const EHOSTUNREACH = 65;
76pub const ENOTEMPTY = 66;
77pub const EPROCLIM = 67;
78pub const EUSERS = 68;
79pub const EDQUOT = 69;
80pub const ESTALE = 70;
81pub const EREMOTE = 71;
82pub const ENOSTR = 72;
83pub const ETIME = 73;
84pub const ENOSR = 74;
85pub const ENOMSG = 75;
86pub const EBADMSG = 76;
87pub const EIDRM = 77;
88pub const EDEADLK = 78;
89pub const ENOLCK = 79;
90pub const ENONET = 80;
91pub const ERREMOTE = 81;
92pub const ENOLINK = 82;
93pub const EADV = 83;
94pub const ESRMNT = 84;
95pub const ECOMM = 85;
96pub const EPROTO = 86;
97pub const EMULTIHOP = 87;
98pub const EDOTDOT = 88;
99pub const EREMCHG = 89;
100pub const ENOSYS = 90;
101pub const ESTRPIPE = 91;
102pub const EOVERFLOW = 92;
103pub const EBADFD = 93;
104pub const ECHRNG = 94;
105pub const EL2NSYNC = 95;
106pub const EL3HLT = 96;
107pub const EL3RST = 97;
108pub const ELNRNG = 98;
109pub const EUNATCH = 99;
110pub const ENOCSI = 100;
111pub const EL2HLT = 101;
112pub const EBADE = 102;
113pub const EBADR = 103;
114pub const EXFULL = 104;
115pub const ENOANO = 105;
116pub const EBADRQC = 106;
117pub const EBADSLT = 107;
118pub const EDEADLOCK = 108;
119pub const EBFONT = 109;
120pub const ELIBEXEC = 110;
121pub const ENODATA = 111;
122pub const ELIBBAD = 112;
123pub const ENOPKG = 113;
124pub const ELIBACC = 114;
125pub const ENOTUNIQ = 115;
126pub const ERESTART = 116;
127pub const EUCLEAN = 117;
128pub const ENOTNAM = 118;
129pub const ENAVAIL = 119;
130pub const EISNAM = 120;
131pub const EREMOTEIO = 121;
132pub const EILSEQ = 122;
133pub const ELIBMAX = 123;
134pub const ELIBSCN = 124;
135pub const ENOMEDIUM = 125;
136pub const EMEDIUMTYPE = 126;
137pub const ECANCELED = 127;
138pub const ENOKEY = 128;
139pub const EKEYEXPIRED = 129;
140pub const EKEYREVOKED = 130;
141pub const EKEYREJECTED = 131;
142pub const EOWNERDEAD = 132;
143pub const ENOTRECOVERABLE = 133;
144pub const ERFKILL = 134;
145pub const EHWPOISON = 135;
lib/std/os/bits/linux/errno/generic.zig created+466
...@@ -0,0 +1,466 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7pub const E = enum(u16) {
8 /// No error occurred.
9 /// Same code used for `NSROK`.
10 SUCCESS = 0,
11
12 /// Operation not permitted
13 PERM = 1,
14
15 /// No such file or directory
16 NOENT = 2,
17
18 /// No such process
19 SRCH = 3,
20
21 /// Interrupted system call
22 INTR = 4,
23
24 /// I/O error
25 IO = 5,
26
27 /// No such device or address
28 NXIO = 6,
29
30 /// Arg list too long
31 @"2BIG" = 7,
32
33 /// Exec format error
34 NOEXEC = 8,
35
36 /// Bad file number
37 BADF = 9,
38
39 /// No child processes
40 CHILD = 10,
41
42 /// Try again
43 /// Also means: WOULDBLOCK: operation would block
44 AGAIN = 11,
45
46 /// Out of memory
47 NOMEM = 12,
48
49 /// Permission denied
50 ACCES = 13,
51
52 /// Bad address
53 FAULT = 14,
54
55 /// Block device required
56 NOTBLK = 15,
57
58 /// Device or resource busy
59 BUSY = 16,
60
61 /// File exists
62 EXIST = 17,
63
64 /// Cross-device link
65 XDEV = 18,
66
67 /// No such device
68 NODEV = 19,
69
70 /// Not a directory
71 NOTDIR = 20,
72
73 /// Is a directory
74 ISDIR = 21,
75
76 /// Invalid argument
77 INVAL = 22,
78
79 /// File table overflow
80 NFILE = 23,
81
82 /// Too many open files
83 MFILE = 24,
84
85 /// Not a typewriter
86 NOTTY = 25,
87
88 /// Text file busy
89 TXTBSY = 26,
90
91 /// File too large
92 FBIG = 27,
93
94 /// No space left on device
95 NOSPC = 28,
96
97 /// Illegal seek
98 SPIPE = 29,
99
100 /// Read-only file system
101 ROFS = 30,
102
103 /// Too many links
104 MLINK = 31,
105
106 /// Broken pipe
107 PIPE = 32,
108
109 /// Math argument out of domain of func
110 DOM = 33,
111
112 /// Math result not representable
113 RANGE = 34,
114
115 /// Resource deadlock would occur
116 DEADLK = 35,
117
118 /// File name too long
119 NAMETOOLONG = 36,
120
121 /// No record locks available
122 NOLCK = 37,
123
124 /// Function not implemented
125 NOSYS = 38,
126
127 /// Directory not empty
128 NOTEMPTY = 39,
129
130 /// Too many symbolic links encountered
131 LOOP = 40,
132
133 /// No message of desired type
134 NOMSG = 42,
135
136 /// Identifier removed
137 IDRM = 43,
138
139 /// Channel number out of range
140 CHRNG = 44,
141
142 /// Level 2 not synchronized
143 L2NSYNC = 45,
144
145 /// Level 3 halted
146 L3HLT = 46,
147
148 /// Level 3 reset
149 L3RST = 47,
150
151 /// Link number out of range
152 LNRNG = 48,
153
154 /// Protocol driver not attached
155 UNATCH = 49,
156
157 /// No CSI structure available
158 NOCSI = 50,
159
160 /// Level 2 halted
161 L2HLT = 51,
162
163 /// Invalid exchange
164 BADE = 52,
165
166 /// Invalid request descriptor
167 BADR = 53,
168
169 /// Exchange full
170 XFULL = 54,
171
172 /// No anode
173 NOANO = 55,
174
175 /// Invalid request code
176 BADRQC = 56,
177
178 /// Invalid slot
179 BADSLT = 57,
180
181 /// Bad font file format
182 BFONT = 59,
183
184 /// Device not a stream
185 NOSTR = 60,
186
187 /// No data available
188 NODATA = 61,
189
190 /// Timer expired
191 TIME = 62,
192
193 /// Out of streams resources
194 NOSR = 63,
195
196 /// Machine is not on the network
197 NONET = 64,
198
199 /// Package not installed
200 NOPKG = 65,
201
202 /// Object is remote
203 REMOTE = 66,
204
205 /// Link has been severed
206 NOLINK = 67,
207
208 /// Advertise error
209 ADV = 68,
210
211 /// Srmount error
212 SRMNT = 69,
213
214 /// Communication error on send
215 COMM = 70,
216
217 /// Protocol error
218 PROTO = 71,
219
220 /// Multihop attempted
221 MULTIHOP = 72,
222
223 /// RFS specific error
224 DOTDOT = 73,
225
226 /// Not a data message
227 BADMSG = 74,
228
229 /// Value too large for defined data type
230 OVERFLOW = 75,
231
232 /// Name not unique on network
233 NOTUNIQ = 76,
234
235 /// File descriptor in bad state
236 BADFD = 77,
237
238 /// Remote address changed
239 REMCHG = 78,
240
241 /// Can not access a needed shared library
242 LIBACC = 79,
243
244 /// Accessing a corrupted shared library
245 LIBBAD = 80,
246
247 /// .lib section in a.out corrupted
248 LIBSCN = 81,
249
250 /// Attempting to link in too many shared libraries
251 LIBMAX = 82,
252
253 /// Cannot exec a shared library directly
254 LIBEXEC = 83,
255
256 /// Illegal byte sequence
257 ILSEQ = 84,
258
259 /// Interrupted system call should be restarted
260 RESTART = 85,
261
262 /// Streams pipe error
263 STRPIPE = 86,
264
265 /// Too many users
266 USERS = 87,
267
268 /// Socket operation on non-socket
269 NOTSOCK = 88,
270
271 /// Destination address required
272 DESTADDRREQ = 89,
273
274 /// Message too long
275 MSGSIZE = 90,
276
277 /// Protocol wrong type for socket
278 PROTOTYPE = 91,
279
280 /// Protocol not available
281 NOPROTOOPT = 92,
282
283 /// Protocol not supported
284 PROTONOSUPPORT = 93,
285
286 /// Socket type not supported
287 SOCKTNOSUPPORT = 94,
288
289 /// Operation not supported on transport endpoint
290 /// This code also means `NOTSUP`.
291 OPNOTSUPP = 95,
292
293 /// Protocol family not supported
294 PFNOSUPPORT = 96,
295
296 /// Address family not supported by protocol
297 AFNOSUPPORT = 97,
298
299 /// Address already in use
300 ADDRINUSE = 98,
301
302 /// Cannot assign requested address
303 ADDRNOTAVAIL = 99,
304
305 /// Network is down
306 NETDOWN = 100,
307
308 /// Network is unreachable
309 NETUNREACH = 101,
310
311 /// Network dropped connection because of reset
312 NETRESET = 102,
313
314 /// Software caused connection abort
315 CONNABORTED = 103,
316
317 /// Connection reset by peer
318 CONNRESET = 104,
319
320 /// No buffer space available
321 NOBUFS = 105,
322
323 /// Transport endpoint is already connected
324 ISCONN = 106,
325
326 /// Transport endpoint is not connected
327 NOTCONN = 107,
328
329 /// Cannot send after transport endpoint shutdown
330 SHUTDOWN = 108,
331
332 /// Too many references: cannot splice
333 TOOMANYREFS = 109,
334
335 /// Connection timed out
336 TIMEDOUT = 110,
337
338 /// Connection refused
339 CONNREFUSED = 111,
340
341 /// Host is down
342 HOSTDOWN = 112,
343
344 /// No route to host
345 HOSTUNREACH = 113,
346
347 /// Operation already in progress
348 ALREADY = 114,
349
350 /// Operation now in progress
351 INPROGRESS = 115,
352
353 /// Stale NFS file handle
354 STALE = 116,
355
356 /// Structure needs cleaning
357 UCLEAN = 117,
358
359 /// Not a XENIX named type file
360 NOTNAM = 118,
361
362 /// No XENIX semaphores available
363 NAVAIL = 119,
364
365 /// Is a named type file
366 ISNAM = 120,
367
368 /// Remote I/O error
369 REMOTEIO = 121,
370
371 /// Quota exceeded
372 DQUOT = 122,
373
374 /// No medium found
375 NOMEDIUM = 123,
376
377 /// Wrong medium type
378 MEDIUMTYPE = 124,
379
380 /// Operation canceled
381 CANCELED = 125,
382
383 /// Required key not available
384 NOKEY = 126,
385
386 /// Key has expired
387 KEYEXPIRED = 127,
388
389 /// Key has been revoked
390 KEYREVOKED = 128,
391
392 /// Key was rejected by service
393 KEYREJECTED = 129,
394
395 // for robust mutexes
396
397 /// Owner died
398 OWNERDEAD = 130,
399
400 /// State not recoverable
401 NOTRECOVERABLE = 131,
402
403 /// Operation not possible due to RF-kill
404 RFKILL = 132,
405
406 /// Memory page has hardware error
407 HWPOISON = 133,
408
409 // nameserver query return codes
410
411 /// DNS server returned answer with no data
412 NSRNODATA = 160,
413
414 /// DNS server claims query was misformatted
415 NSRFORMERR = 161,
416
417 /// DNS server returned general failure
418 NSRSERVFAIL = 162,
419
420 /// Domain name not found
421 NSRNOTFOUND = 163,
422
423 /// DNS server does not implement requested operation
424 NSRNOTIMP = 164,
425
426 /// DNS server refused query
427 NSRREFUSED = 165,
428
429 /// Misformatted DNS query
430 NSRBADQUERY = 166,
431
432 /// Misformatted domain name
433 NSRBADNAME = 167,
434
435 /// Unsupported address family
436 NSRBADFAMILY = 168,
437
438 /// Misformatted DNS reply
439 NSRBADRESP = 169,
440
441 /// Could not contact DNS servers
442 NSRCONNREFUSED = 170,
443
444 /// Timeout while contacting DNS servers
445 NSRTIMEOUT = 171,
446
447 /// End of file
448 NSROF = 172,
449
450 /// Error reading file
451 NSRFILE = 173,
452
453 /// Out of memory
454 NSRNOMEM = 174,
455
456 /// Application terminated lookup
457 NSRDESTRUCTION = 175,
458
459 /// Domain name is too long
460 NSRQUERYDOMAINTOOLONG = 176,
461
462 /// Domain name is too long
463 NSRCNAMELOOP = 177,
464
465 _,
466};
lib/std/os/bits/linux/errno/mips.zig created+147
...@@ -0,0 +1,147 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7//! These are MIPS ABI compatible.
8pub const E = enum(i32) {
9 /// No error occurred.
10 SUCCESS = 0,
11
12 PERM = 1,
13 NOENT = 2,
14 SRCH = 3,
15 INTR = 4,
16 IO = 5,
17 NXIO = 6,
18 @"2BIG" = 7,
19 NOEXEC = 8,
20 BADF = 9,
21 CHILD = 10,
22 /// Also used for WOULDBLOCK.
23 AGAIN = 11,
24 NOMEM = 12,
25 ACCES = 13,
26 FAULT = 14,
27 NOTBLK = 15,
28 BUSY = 16,
29 EXIST = 17,
30 XDEV = 18,
31 NODEV = 19,
32 NOTDIR = 20,
33 ISDIR = 21,
34 INVAL = 22,
35 NFILE = 23,
36 MFILE = 24,
37 NOTTY = 25,
38 TXTBSY = 26,
39 FBIG = 27,
40 NOSPC = 28,
41 SPIPE = 29,
42 ROFS = 30,
43 MLINK = 31,
44 PIPE = 32,
45 DOM = 33,
46 RANGE = 34,
47
48 NOMSG = 35,
49 IDRM = 36,
50 CHRNG = 37,
51 L2NSYNC = 38,
52 L3HLT = 39,
53 L3RST = 40,
54 LNRNG = 41,
55 UNATCH = 42,
56 NOCSI = 43,
57 L2HLT = 44,
58 DEADLK = 45,
59 NOLCK = 46,
60 BADE = 50,
61 BADR = 51,
62 XFULL = 52,
63 NOANO = 53,
64 BADRQC = 54,
65 BADSLT = 55,
66 DEADLOCK = 56,
67 BFONT = 59,
68 NOSTR = 60,
69 NODATA = 61,
70 TIME = 62,
71 NOSR = 63,
72 NONET = 64,
73 NOPKG = 65,
74 REMOTE = 66,
75 NOLINK = 67,
76 ADV = 68,
77 SRMNT = 69,
78 COMM = 70,
79 PROTO = 71,
80 DOTDOT = 73,
81 MULTIHOP = 74,
82 BADMSG = 77,
83 NAMETOOLONG = 78,
84 OVERFLOW = 79,
85 NOTUNIQ = 80,
86 BADFD = 81,
87 REMCHG = 82,
88 LIBACC = 83,
89 LIBBAD = 84,
90 LIBSCN = 85,
91 LIBMAX = 86,
92 LIBEXEC = 87,
93 ILSEQ = 88,
94 NOSYS = 89,
95 LOOP = 90,
96 RESTART = 91,
97 STRPIPE = 92,
98 NOTEMPTY = 93,
99 USERS = 94,
100 NOTSOCK = 95,
101 DESTADDRREQ = 96,
102 MSGSIZE = 97,
103 PROTOTYPE = 98,
104 NOPROTOOPT = 99,
105 PROTONOSUPPORT = 120,
106 SOCKTNOSUPPORT = 121,
107 OPNOTSUPP = 122,
108 PFNOSUPPORT = 123,
109 AFNOSUPPORT = 124,
110 ADDRINUSE = 125,
111 ADDRNOTAVAIL = 126,
112 NETDOWN = 127,
113 NETUNREACH = 128,
114 NETRESET = 129,
115 CONNABORTED = 130,
116 CONNRESET = 131,
117 NOBUFS = 132,
118 ISCONN = 133,
119 NOTCONN = 134,
120 UCLEAN = 135,
121 NOTNAM = 137,
122 NAVAIL = 138,
123 ISNAM = 139,
124 REMOTEIO = 140,
125 SHUTDOWN = 143,
126 TOOMANYREFS = 144,
127 TIMEDOUT = 145,
128 CONNREFUSED = 146,
129 HOSTDOWN = 147,
130 HOSTUNREACH = 148,
131 ALREADY = 149,
132 INPROGRESS = 150,
133 STALE = 151,
134 CANCELED = 158,
135 NOMEDIUM = 159,
136 MEDIUMTYPE = 160,
137 NOKEY = 161,
138 KEYEXPIRED = 162,
139 KEYREVOKED = 163,
140 KEYREJECTED = 164,
141 OWNERDEAD = 165,
142 NOTRECOVERABLE = 166,
143 RFKILL = 167,
144 HWPOISON = 168,
145 DQUOT = 1133,
146 _,
147};
lib/std/os/bits/linux/errno/sparc.zig created+150
...@@ -0,0 +1,150 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7//! These match the SunOS error numbering scheme.
8pub const E = enum(i32) {
9 /// No error occurred.
10 SUCCESS = 0,
11
12 PERM = 1,
13 NOENT = 2,
14 SRCH = 3,
15 INTR = 4,
16 IO = 5,
17 NXIO = 6,
18 @"2BIG" = 7,
19 NOEXEC = 8,
20 BADF = 9,
21 CHILD = 10,
22 /// Also used for WOULDBLOCK
23 AGAIN = 11,
24 NOMEM = 12,
25 ACCES = 13,
26 FAULT = 14,
27 NOTBLK = 15,
28 BUSY = 16,
29 EXIST = 17,
30 XDEV = 18,
31 NODEV = 19,
32 NOTDIR = 20,
33 ISDIR = 21,
34 INVAL = 22,
35 NFILE = 23,
36 MFILE = 24,
37 NOTTY = 25,
38 TXTBSY = 26,
39 FBIG = 27,
40 NOSPC = 28,
41 SPIPE = 29,
42 ROFS = 30,
43 MLINK = 31,
44 PIPE = 32,
45 DOM = 33,
46 RANGE = 34,
47
48 INPROGRESS = 36,
49 ALREADY = 37,
50 NOTSOCK = 38,
51 DESTADDRREQ = 39,
52 MSGSIZE = 40,
53 PROTOTYPE = 41,
54 NOPROTOOPT = 42,
55 PROTONOSUPPORT = 43,
56 SOCKTNOSUPPORT = 44,
57 /// Also used for NOTSUP
58 OPNOTSUPP = 45,
59 PFNOSUPPORT = 46,
60 AFNOSUPPORT = 47,
61 ADDRINUSE = 48,
62 ADDRNOTAVAIL = 49,
63 NETDOWN = 50,
64 NETUNREACH = 51,
65 NETRESET = 52,
66 CONNABORTED = 53,
67 CONNRESET = 54,
68 NOBUFS = 55,
69 ISCONN = 56,
70 NOTCONN = 57,
71 SHUTDOWN = 58,
72 TOOMANYREFS = 59,
73 TIMEDOUT = 60,
74 CONNREFUSED = 61,
75 LOOP = 62,
76 NAMETOOLONG = 63,
77 HOSTDOWN = 64,
78 HOSTUNREACH = 65,
79 NOTEMPTY = 66,
80 PROCLIM = 67,
81 USERS = 68,
82 DQUOT = 69,
83 STALE = 70,
84 REMOTE = 71,
85 NOSTR = 72,
86 TIME = 73,
87 NOSR = 74,
88 NOMSG = 75,
89 BADMSG = 76,
90 IDRM = 77,
91 DEADLK = 78,
92 NOLCK = 79,
93 NONET = 80,
94 RREMOTE = 81,
95 NOLINK = 82,
96 ADV = 83,
97 SRMNT = 84,
98 COMM = 85,
99 PROTO = 86,
100 MULTIHOP = 87,
101 DOTDOT = 88,
102 REMCHG = 89,
103 NOSYS = 90,
104 STRPIPE = 91,
105 OVERFLOW = 92,
106 BADFD = 93,
107 CHRNG = 94,
108 L2NSYNC = 95,
109 L3HLT = 96,
110 L3RST = 97,
111 LNRNG = 98,
112 UNATCH = 99,
113 NOCSI = 100,
114 L2HLT = 101,
115 BADE = 102,
116 BADR = 103,
117 XFULL = 104,
118 NOANO = 105,
119 BADRQC = 106,
120 BADSLT = 107,
121 DEADLOCK = 108,
122 BFONT = 109,
123 LIBEXEC = 110,
124 NODATA = 111,
125 LIBBAD = 112,
126 NOPKG = 113,
127 LIBACC = 114,
128 NOTUNIQ = 115,
129 RESTART = 116,
130 UCLEAN = 117,
131 NOTNAM = 118,
132 NAVAIL = 119,
133 ISNAM = 120,
134 REMOTEIO = 121,
135 ILSEQ = 122,
136 LIBMAX = 123,
137 LIBSCN = 124,
138 NOMEDIUM = 125,
139 MEDIUMTYPE = 126,
140 CANCELED = 127,
141 NOKEY = 128,
142 KEYEXPIRED = 129,
143 KEYREVOKED = 130,
144 KEYREJECTED = 131,
145 OWNERDEAD = 132,
146 NOTRECOVERABLE = 133,
147 RFKILL = 134,
148 HWPOISON = 135,
149 _,
150};
lib/std/os/bits/netbsd.zig+138-134
...@@ -933,140 +933,144 @@ pub const ucontext_t = extern struct {...@@ -933,140 +933,144 @@ pub const ucontext_t = extern struct {
933 ]u32,933 ]u32,
934};934};
935935
936pub const EPERM = 1; // Operation not permitted936pub const E = enum(u16) {
937pub const ENOENT = 2; // No such file or directory937 /// No error occurred.
938pub const ESRCH = 3; // No such process938 SUCCESS = 0,
939pub const EINTR = 4; // Interrupted system call939 PERM = 1, // Operation not permitted
940pub const EIO = 5; // Input/output error940 NOENT = 2, // No such file or directory
941pub const ENXIO = 6; // Device not configured941 SRCH = 3, // No such process
942pub const E2BIG = 7; // Argument list too long942 INTR = 4, // Interrupted system call
943pub const ENOEXEC = 8; // Exec format error943 IO = 5, // Input/output error
944pub const EBADF = 9; // Bad file descriptor944 NXIO = 6, // Device not configured
945pub const ECHILD = 10; // No child processes945 @"2BIG" = 7, // Argument list too long
946pub const EDEADLK = 11; // Resource deadlock avoided946 NOEXEC = 8, // Exec format error
947// 11 was EAGAIN947 BADF = 9, // Bad file descriptor
948pub const ENOMEM = 12; // Cannot allocate memory948 CHILD = 10, // No child processes
949pub const EACCES = 13; // Permission denied949 DEADLK = 11, // Resource deadlock avoided
950pub const EFAULT = 14; // Bad address950 // 11 was AGAIN
951pub const ENOTBLK = 15; // Block device required951 NOMEM = 12, // Cannot allocate memory
952pub const EBUSY = 16; // Device busy952 ACCES = 13, // Permission denied
953pub const EEXIST = 17; // File exists953 FAULT = 14, // Bad address
954pub const EXDEV = 18; // Cross-device link954 NOTBLK = 15, // Block device required
955pub const ENODEV = 19; // Operation not supported by device955 BUSY = 16, // Device busy
956pub const ENOTDIR = 20; // Not a directory956 EXIST = 17, // File exists
957pub const EISDIR = 21; // Is a directory957 XDEV = 18, // Cross-device link
958pub const EINVAL = 22; // Invalid argument958 NODEV = 19, // Operation not supported by device
959pub const ENFILE = 23; // Too many open files in system959 NOTDIR = 20, // Not a directory
960pub const EMFILE = 24; // Too many open files960 ISDIR = 21, // Is a directory
961pub const ENOTTY = 25; // Inappropriate ioctl for device961 INVAL = 22, // Invalid argument
962pub const ETXTBSY = 26; // Text file busy962 NFILE = 23, // Too many open files in system
963pub const EFBIG = 27; // File too large963 MFILE = 24, // Too many open files
964pub const ENOSPC = 28; // No space left on device964 NOTTY = 25, // Inappropriate ioctl for device
965pub const ESPIPE = 29; // Illegal seek965 TXTBSY = 26, // Text file busy
966pub const EROFS = 30; // Read-only file system966 FBIG = 27, // File too large
967pub const EMLINK = 31; // Too many links967 NOSPC = 28, // No space left on device
968pub const EPIPE = 32; // Broken pipe968 SPIPE = 29, // Illegal seek
969969 ROFS = 30, // Read-only file system
970// math software970 MLINK = 31, // Too many links
971pub const EDOM = 33; // Numerical argument out of domain971 PIPE = 32, // Broken pipe
972pub const ERANGE = 34; // Result too large or too small972
973973 // math software
974// non-blocking and interrupt i/o974 DOM = 33, // Numerical argument out of domain
975pub const EAGAIN = 35; // Resource temporarily unavailable975 RANGE = 34, // Result too large or too small
976pub const EWOULDBLOCK = EAGAIN; // Operation would block976
977pub const EINPROGRESS = 36; // Operation now in progress977 // non-blocking and interrupt i/o
978pub const EALREADY = 37; // Operation already in progress978 // also: WOULDBLOCK: operation would block
979979 AGAIN = 35, // Resource temporarily unavailable
980// ipc/network software -- argument errors980 INPROGRESS = 36, // Operation now in progress
981pub const ENOTSOCK = 38; // Socket operation on non-socket981 ALREADY = 37, // Operation already in progress
982pub const EDESTADDRREQ = 39; // Destination address required982
983pub const EMSGSIZE = 40; // Message too long983 // ipc/network software -- argument errors
984pub const EPROTOTYPE = 41; // Protocol wrong type for socket984 NOTSOCK = 38, // Socket operation on non-socket
985pub const ENOPROTOOPT = 42; // Protocol option not available985 DESTADDRREQ = 39, // Destination address required
986pub const EPROTONOSUPPORT = 43; // Protocol not supported986 MSGSIZE = 40, // Message too long
987pub const ESOCKTNOSUPPORT = 44; // Socket type not supported987 PROTOTYPE = 41, // Protocol wrong type for socket
988pub const EOPNOTSUPP = 45; // Operation not supported988 NOPROTOOPT = 42, // Protocol option not available
989pub const EPFNOSUPPORT = 46; // Protocol family not supported989 PROTONOSUPPORT = 43, // Protocol not supported
990pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family990 SOCKTNOSUPPORT = 44, // Socket type not supported
991pub const EADDRINUSE = 48; // Address already in use991 OPNOTSUPP = 45, // Operation not supported
992pub const EADDRNOTAVAIL = 49; // Can't assign requested address992 PFNOSUPPORT = 46, // Protocol family not supported
993993 AFNOSUPPORT = 47, // Address family not supported by protocol family
994// ipc/network software -- operational errors994 ADDRINUSE = 48, // Address already in use
995pub const ENETDOWN = 50; // Network is down995 ADDRNOTAVAIL = 49, // Can't assign requested address
996pub const ENETUNREACH = 51; // Network is unreachable996
997pub const ENETRESET = 52; // Network dropped connection on reset997 // ipc/network software -- operational errors
998pub const ECONNABORTED = 53; // Software caused connection abort998 NETDOWN = 50, // Network is down
999pub const ECONNRESET = 54; // Connection reset by peer999 NETUNREACH = 51, // Network is unreachable
1000pub const ENOBUFS = 55; // No buffer space available1000 NETRESET = 52, // Network dropped connection on reset
1001pub const EISCONN = 56; // Socket is already connected1001 CONNABORTED = 53, // Software caused connection abort
1002pub const ENOTCONN = 57; // Socket is not connected1002 CONNRESET = 54, // Connection reset by peer
1003pub const ESHUTDOWN = 58; // Can't send after socket shutdown1003 NOBUFS = 55, // No buffer space available
1004pub const ETOOMANYREFS = 59; // Too many references: can't splice1004 ISCONN = 56, // Socket is already connected
1005pub const ETIMEDOUT = 60; // Operation timed out1005 NOTCONN = 57, // Socket is not connected
1006pub const ECONNREFUSED = 61; // Connection refused1006 SHUTDOWN = 58, // Can't send after socket shutdown
10071007 TOOMANYREFS = 59, // Too many references: can't splice
1008pub const ELOOP = 62; // Too many levels of symbolic links1008 TIMEDOUT = 60, // Operation timed out
1009pub const ENAMETOOLONG = 63; // File name too long1009 CONNREFUSED = 61, // Connection refused
10101010
1011// should be rearranged1011 LOOP = 62, // Too many levels of symbolic links
1012pub const EHOSTDOWN = 64; // Host is down1012 NAMETOOLONG = 63, // File name too long
1013pub const EHOSTUNREACH = 65; // No route to host1013
1014pub const ENOTEMPTY = 66; // Directory not empty1014 // should be rearranged
10151015 HOSTDOWN = 64, // Host is down
1016// quotas & mush1016 HOSTUNREACH = 65, // No route to host
1017pub const EPROCLIM = 67; // Too many processes1017 NOTEMPTY = 66, // Directory not empty
1018pub const EUSERS = 68; // Too many users1018
1019pub const EDQUOT = 69; // Disc quota exceeded1019 // quotas & mush
10201020 PROCLIM = 67, // Too many processes
1021// Network File System1021 USERS = 68, // Too many users
1022pub const ESTALE = 70; // Stale NFS file handle1022 DQUOT = 69, // Disc quota exceeded
1023pub const EREMOTE = 71; // Too many levels of remote in path1023
1024pub const EBADRPC = 72; // RPC struct is bad1024 // Network File System
1025pub const ERPCMISMATCH = 73; // RPC version wrong1025 STALE = 70, // Stale NFS file handle
1026pub const EPROGUNAVAIL = 74; // RPC prog. not avail1026 REMOTE = 71, // Too many levels of remote in path
1027pub const EPROGMISMATCH = 75; // Program version wrong1027 BADRPC = 72, // RPC struct is bad
1028pub const EPROCUNAVAIL = 76; // Bad procedure for program1028 RPCMISMATCH = 73, // RPC version wrong
10291029 PROGUNAVAIL = 74, // RPC prog. not avail
1030pub const ENOLCK = 77; // No locks available1030 PROGMISMATCH = 75, // Program version wrong
1031pub const ENOSYS = 78; // Function not implemented1031 PROCUNAVAIL = 76, // Bad procedure for program
10321032
1033pub const EFTYPE = 79; // Inappropriate file type or format1033 NOLCK = 77, // No locks available
1034pub const EAUTH = 80; // Authentication error1034 NOSYS = 78, // Function not implemented
1035pub const ENEEDAUTH = 81; // Need authenticator1035
10361036 FTYPE = 79, // Inappropriate file type or format
1037// SystemV IPC1037 AUTH = 80, // Authentication error
1038pub const EIDRM = 82; // Identifier removed1038 NEEDAUTH = 81, // Need authenticator
1039pub const ENOMSG = 83; // No message of desired type1039
1040pub const EOVERFLOW = 84; // Value too large to be stored in data type1040 // SystemV IPC
10411041 IDRM = 82, // Identifier removed
1042// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:19951042 NOMSG = 83, // No message of desired type
1043pub const EILSEQ = 85; // Illegal byte sequence1043 OVERFLOW = 84, // Value too large to be stored in data type
10441044
1045// From IEEE Std 1003.1-20011045 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
1046// Base, Realtime, Threads or Thread Priority Scheduling option errors1046 ILSEQ = 85, // Illegal byte sequence
1047pub const ENOTSUP = 86; // Not supported1047
10481048 // From IEEE Std 1003.1-2001
1049// Realtime option errors1049 // Base, Realtime, Threads or Thread Priority Scheduling option errors
1050pub const ECANCELED = 87; // Operation canceled1050 NOTSUP = 86, // Not supported
10511051
1052// Realtime, XSI STREAMS option errors1052 // Realtime option errors
1053pub const EBADMSG = 88; // Bad or Corrupt message1053 CANCELED = 87, // Operation canceled
10541054
1055// XSI STREAMS option errors1055 // Realtime, XSI STREAMS option errors
1056pub const ENODATA = 89; // No message available1056 BADMSG = 88, // Bad or Corrupt message
1057pub const ENOSR = 90; // No STREAM resources1057
1058pub const ENOSTR = 91; // Not a STREAM1058 // XSI STREAMS option errors
1059pub const ETIME = 92; // STREAM ioctl timeout1059 NODATA = 89, // No message available
10601060 NOSR = 90, // No STREAM resources
1061// File system extended attribute errors1061 NOSTR = 91, // Not a STREAM
1062pub const ENOATTR = 93; // Attribute not found1062 TIME = 92, // STREAM ioctl timeout
10631063
1064// Realtime, XSI STREAMS option errors1064 // File system extended attribute errors
1065pub const EMULTIHOP = 94; // Multihop attempted1065 NOATTR = 93, // Attribute not found
1066pub const ENOLINK = 95; // Link has been severed1066
1067pub const EPROTO = 96; // Protocol error1067 // Realtime, XSI STREAMS option errors
10681068 MULTIHOP = 94, // Multihop attempted
1069pub const ELAST = 96; // Must equal largest errno1069 NOLINK = 95, // Link has been severed
1070 PROTO = 96, // Protocol error
1071
1072 _,
1073};
10701074
1071pub const MINSIGSTKSZ = 8192;1075pub const MINSIGSTKSZ = 8192;
1072pub const SIGSTKSZ = MINSIGSTKSZ + 32768;1076pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
lib/std/os/bits/openbsd.zig+124-119
...@@ -295,6 +295,7 @@ pub const AI_NUMERICSERV = 16;...@@ -295,6 +295,7 @@ pub const AI_NUMERICSERV = 16;
295pub const AI_ADDRCONFIG = 64;295pub const AI_ADDRCONFIG = 64;
296296
297pub const PATH_MAX = 1024;297pub const PATH_MAX = 1024;
298pub const IOV_MAX = 1024;
298299
299pub const STDIN_FILENO = 0;300pub const STDIN_FILENO = 0;
300pub const STDOUT_FILENO = 1;301pub const STDOUT_FILENO = 1;
...@@ -824,125 +825,129 @@ pub usingnamespace switch (builtin.target.cpu.arch) {...@@ -824,125 +825,129 @@ pub usingnamespace switch (builtin.target.cpu.arch) {
824pub const sigset_t = c_uint;825pub const sigset_t = c_uint;
825pub const empty_sigset: sigset_t = 0;826pub const empty_sigset: sigset_t = 0;
826827
827pub const EPERM = 1; // Operation not permitted828pub const E = enum(u16) {
828pub const ENOENT = 2; // No such file or directory829 /// No error occurred.
829pub const ESRCH = 3; // No such process830 SUCCESS = 0,
830pub const EINTR = 4; // Interrupted system call831 PERM = 1, // Operation not permitted
831pub const EIO = 5; // Input/output error832 NOENT = 2, // No such file or directory
832pub const ENXIO = 6; // Device not configured833 SRCH = 3, // No such process
833pub const E2BIG = 7; // Argument list too long834 INTR = 4, // Interrupted system call
834pub const ENOEXEC = 8; // Exec format error835 IO = 5, // Input/output error
835pub const EBADF = 9; // Bad file descriptor836 NXIO = 6, // Device not configured
836pub const ECHILD = 10; // No child processes837 @"2BIG" = 7, // Argument list too long
837pub const EDEADLK = 11; // Resource deadlock avoided838 NOEXEC = 8, // Exec format error
838// 11 was EAGAIN839 BADF = 9, // Bad file descriptor
839pub const ENOMEM = 12; // Cannot allocate memory840 CHILD = 10, // No child processes
840pub const EACCES = 13; // Permission denied841 DEADLK = 11, // Resource deadlock avoided
841pub const EFAULT = 14; // Bad address842 // 11 was AGAIN
842pub const ENOTBLK = 15; // Block device required843 NOMEM = 12, // Cannot allocate memory
843pub const EBUSY = 16; // Device busy844 ACCES = 13, // Permission denied
844pub const EEXIST = 17; // File exists845 FAULT = 14, // Bad address
845pub const EXDEV = 18; // Cross-device link846 NOTBLK = 15, // Block device required
846pub const ENODEV = 19; // Operation not supported by device847 BUSY = 16, // Device busy
847pub const ENOTDIR = 20; // Not a directory848 EXIST = 17, // File exists
848pub const EISDIR = 21; // Is a directory849 XDEV = 18, // Cross-device link
849pub const EINVAL = 22; // Invalid argument850 NODEV = 19, // Operation not supported by device
850pub const ENFILE = 23; // Too many open files in system851 NOTDIR = 20, // Not a directory
851pub const EMFILE = 24; // Too many open files852 ISDIR = 21, // Is a directory
852pub const ENOTTY = 25; // Inappropriate ioctl for device853 INVAL = 22, // Invalid argument
853pub const ETXTBSY = 26; // Text file busy854 NFILE = 23, // Too many open files in system
854pub const EFBIG = 27; // File too large855 MFILE = 24, // Too many open files
855pub const ENOSPC = 28; // No space left on device856 NOTTY = 25, // Inappropriate ioctl for device
856pub const ESPIPE = 29; // Illegal seek857 TXTBSY = 26, // Text file busy
857pub const EROFS = 30; // Read-only file system858 FBIG = 27, // File too large
858pub const EMLINK = 31; // Too many links859 NOSPC = 28, // No space left on device
859pub const EPIPE = 32; // Broken pipe860 SPIPE = 29, // Illegal seek
860861 ROFS = 30, // Read-only file system
861// math software862 MLINK = 31, // Too many links
862pub const EDOM = 33; // Numerical argument out of domain863 PIPE = 32, // Broken pipe
863pub const ERANGE = 34; // Result too large or too small864
864865 // math software
865// non-blocking and interrupt i/o866 DOM = 33, // Numerical argument out of domain
866pub const EAGAIN = 35; // Resource temporarily unavailable867 RANGE = 34, // Result too large or too small
867pub const EWOULDBLOCK = EAGAIN; // Operation would block868
868pub const EINPROGRESS = 36; // Operation now in progress869 // non-blocking and interrupt i/o
869pub const EALREADY = 37; // Operation already in progress870 // also: WOULDBLOCK: operation would block
870871 AGAIN = 35, // Resource temporarily unavailable
871// ipc/network software -- argument errors872 INPROGRESS = 36, // Operation now in progress
872pub const ENOTSOCK = 38; // Socket operation on non-socket873 ALREADY = 37, // Operation already in progress
873pub const EDESTADDRREQ = 39; // Destination address required874
874pub const EMSGSIZE = 40; // Message too long875 // ipc/network software -- argument errors
875pub const EPROTOTYPE = 41; // Protocol wrong type for socket876 NOTSOCK = 38, // Socket operation on non-socket
876pub const ENOPROTOOPT = 42; // Protocol option not available877 DESTADDRREQ = 39, // Destination address required
877pub const EPROTONOSUPPORT = 43; // Protocol not supported878 MSGSIZE = 40, // Message too long
878pub const ESOCKTNOSUPPORT = 44; // Socket type not supported879 PROTOTYPE = 41, // Protocol wrong type for socket
879pub const EOPNOTSUPP = 45; // Operation not supported880 NOPROTOOPT = 42, // Protocol option not available
880pub const EPFNOSUPPORT = 46; // Protocol family not supported881 PROTONOSUPPORT = 43, // Protocol not supported
881pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family882 SOCKTNOSUPPORT = 44, // Socket type not supported
882pub const EADDRINUSE = 48; // Address already in use883 OPNOTSUPP = 45, // Operation not supported
883pub const EADDRNOTAVAIL = 49; // Can't assign requested address884 PFNOSUPPORT = 46, // Protocol family not supported
884885 AFNOSUPPORT = 47, // Address family not supported by protocol family
885// ipc/network software -- operational errors886 ADDRINUSE = 48, // Address already in use
886pub const ENETDOWN = 50; // Network is down887 ADDRNOTAVAIL = 49, // Can't assign requested address
887pub const ENETUNREACH = 51; // Network is unreachable888
888pub const ENETRESET = 52; // Network dropped connection on reset889 // ipc/network software -- operational errors
889pub const ECONNABORTED = 53; // Software caused connection abort890 NETDOWN = 50, // Network is down
890pub const ECONNRESET = 54; // Connection reset by peer891 NETUNREACH = 51, // Network is unreachable
891pub const ENOBUFS = 55; // No buffer space available892 NETRESET = 52, // Network dropped connection on reset
892pub const EISCONN = 56; // Socket is already connected893 CONNABORTED = 53, // Software caused connection abort
893pub const ENOTCONN = 57; // Socket is not connected894 CONNRESET = 54, // Connection reset by peer
894pub const ESHUTDOWN = 58; // Can't send after socket shutdown895 NOBUFS = 55, // No buffer space available
895pub const ETOOMANYREFS = 59; // Too many references: can't splice896 ISCONN = 56, // Socket is already connected
896pub const ETIMEDOUT = 60; // Operation timed out897 NOTCONN = 57, // Socket is not connected
897pub const ECONNREFUSED = 61; // Connection refused898 SHUTDOWN = 58, // Can't send after socket shutdown
898899 TOOMANYREFS = 59, // Too many references: can't splice
899pub const ELOOP = 62; // Too many levels of symbolic links900 TIMEDOUT = 60, // Operation timed out
900pub const ENAMETOOLONG = 63; // File name too long901 CONNREFUSED = 61, // Connection refused
901902
902// should be rearranged903 LOOP = 62, // Too many levels of symbolic links
903pub const EHOSTDOWN = 64; // Host is down904 NAMETOOLONG = 63, // File name too long
904pub const EHOSTUNREACH = 65; // No route to host905
905pub const ENOTEMPTY = 66; // Directory not empty906 // should be rearranged
906907 HOSTDOWN = 64, // Host is down
907// quotas & mush908 HOSTUNREACH = 65, // No route to host
908pub const EPROCLIM = 67; // Too many processes909 NOTEMPTY = 66, // Directory not empty
909pub const EUSERS = 68; // Too many users910
910pub const EDQUOT = 69; // Disc quota exceeded911 // quotas & mush
911912 PROCLIM = 67, // Too many processes
912// Network File System913 USERS = 68, // Too many users
913pub const ESTALE = 70; // Stale NFS file handle914 DQUOT = 69, // Disc quota exceeded
914pub const EREMOTE = 71; // Too many levels of remote in path915
915pub const EBADRPC = 72; // RPC struct is bad916 // Network File System
916pub const ERPCMISMATCH = 73; // RPC version wrong917 STALE = 70, // Stale NFS file handle
917pub const EPROGUNAVAIL = 74; // RPC prog. not avail918 REMOTE = 71, // Too many levels of remote in path
918pub const EPROGMISMATCH = 75; // Program version wrong919 BADRPC = 72, // RPC struct is bad
919pub const EPROCUNAVAIL = 76; // Bad procedure for program920 RPCMISMATCH = 73, // RPC version wrong
920921 PROGUNAVAIL = 74, // RPC prog. not avail
921pub const ENOLCK = 77; // No locks available922 PROGMISMATCH = 75, // Program version wrong
922pub const ENOSYS = 78; // Function not implemented923 PROCUNAVAIL = 76, // Bad procedure for program
923924
924pub const EFTYPE = 79; // Inappropriate file type or format925 NOLCK = 77, // No locks available
925pub const EAUTH = 80; // Authentication error926 NOSYS = 78, // Function not implemented
926pub const ENEEDAUTH = 81; // Need authenticator927
927pub const EIPSEC = 82; // IPsec processing failure928 FTYPE = 79, // Inappropriate file type or format
928pub const ENOATTR = 83; // Attribute not found929 AUTH = 80, // Authentication error
929930 NEEDAUTH = 81, // Need authenticator
930// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995931 IPSEC = 82, // IPsec processing failure
931pub const EILSEQ = 84; // Illegal byte sequence932 NOATTR = 83, // Attribute not found
932933
933pub const ENOMEDIUM = 85; // No medium found934 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
934pub const EMEDIUMTYPE = 86; // Wrong medium type935 ILSEQ = 84, // Illegal byte sequence
935pub const EOVERFLOW = 87; // Value too large to be stored in data type936
936pub const ECANCELED = 88; // Operation canceled937 NOMEDIUM = 85, // No medium found
937pub const EIDRM = 89; // Identifier removed938 MEDIUMTYPE = 86, // Wrong medium type
938pub const ENOMSG = 90; // No message of desired type939 OVERFLOW = 87, // Value too large to be stored in data type
939pub const ENOTSUP = 91; // Not supported940 CANCELED = 88, // Operation canceled
940pub const EBADMSG = 92; // Bad or Corrupt message941 IDRM = 89, // Identifier removed
941pub const ENOTRECOVERABLE = 93; // State not recoverable942 NOMSG = 90, // No message of desired type
942pub const EOWNERDEAD = 94; // Previous owner died943 NOTSUP = 91, // Not supported
943pub const EPROTO = 95; // Protocol error944 BADMSG = 92, // Bad or Corrupt message
944945 NOTRECOVERABLE = 93, // State not recoverable
945pub const ELAST = 95; // Must equal largest errno946 OWNERDEAD = 94, // Previous owner died
947 PROTO = 95, // Protocol error
948
949 _,
950};
946951
947const _MAX_PAGE_SHIFT = switch (builtin.target.cpu.arch) {952const _MAX_PAGE_SHIFT = switch (builtin.target.cpu.arch) {
948 .i386 => 12,953 .i386 => 12,
lib/std/os/bits/wasi.zig+83-80
...@@ -111,86 +111,89 @@ pub const dirent_t = extern struct {...@@ -111,86 +111,89 @@ pub const dirent_t = extern struct {
111 d_type: filetype_t,111 d_type: filetype_t,
112};112};
113113
114pub const errno_t = u16;114pub const errno_t = enum(u16) {
115pub const ESUCCESS: errno_t = 0;115 SUCCESS = 0,
116pub const E2BIG: errno_t = 1;116 @"2BIG" = 1,
117pub const EACCES: errno_t = 2;117 ACCES = 2,
118pub const EADDRINUSE: errno_t = 3;118 ADDRINUSE = 3,
119pub const EADDRNOTAVAIL: errno_t = 4;119 ADDRNOTAVAIL = 4,
120pub const EAFNOSUPPORT: errno_t = 5;120 AFNOSUPPORT = 5,
121pub const EAGAIN: errno_t = 6;121 /// This is also the error code used for `WOULDBLOCK`.
122pub const EWOULDBLOCK = EAGAIN;122 AGAIN = 6,
123pub const EALREADY: errno_t = 7;123 ALREADY = 7,
124pub const EBADF: errno_t = 8;124 BADF = 8,
125pub const EBADMSG: errno_t = 9;125 BADMSG = 9,
126pub const EBUSY: errno_t = 10;126 BUSY = 10,
127pub const ECANCELED: errno_t = 11;127 CANCELED = 11,
128pub const ECHILD: errno_t = 12;128 CHILD = 12,
129pub const ECONNABORTED: errno_t = 13;129 CONNABORTED = 13,
130pub const ECONNREFUSED: errno_t = 14;130 CONNREFUSED = 14,
131pub const ECONNRESET: errno_t = 15;131 CONNRESET = 15,
132pub const EDEADLK: errno_t = 16;132 DEADLK = 16,
133pub const EDESTADDRREQ: errno_t = 17;133 DESTADDRREQ = 17,
134pub const EDOM: errno_t = 18;134 DOM = 18,
135pub const EDQUOT: errno_t = 19;135 DQUOT = 19,
136pub const EEXIST: errno_t = 20;136 EXIST = 20,
137pub const EFAULT: errno_t = 21;137 FAULT = 21,
138pub const EFBIG: errno_t = 22;138 FBIG = 22,
139pub const EHOSTUNREACH: errno_t = 23;139 HOSTUNREACH = 23,
140pub const EIDRM: errno_t = 24;140 IDRM = 24,
141pub const EILSEQ: errno_t = 25;141 ILSEQ = 25,
142pub const EINPROGRESS: errno_t = 26;142 INPROGRESS = 26,
143pub const EINTR: errno_t = 27;143 INTR = 27,
144pub const EINVAL: errno_t = 28;144 INVAL = 28,
145pub const EIO: errno_t = 29;145 IO = 29,
146pub const EISCONN: errno_t = 30;146 ISCONN = 30,
147pub const EISDIR: errno_t = 31;147 ISDIR = 31,
148pub const ELOOP: errno_t = 32;148 LOOP = 32,
149pub const EMFILE: errno_t = 33;149 MFILE = 33,
150pub const EMLINK: errno_t = 34;150 MLINK = 34,
151pub const EMSGSIZE: errno_t = 35;151 MSGSIZE = 35,
152pub const EMULTIHOP: errno_t = 36;152 MULTIHOP = 36,
153pub const ENAMETOOLONG: errno_t = 37;153 NAMETOOLONG = 37,
154pub const ENETDOWN: errno_t = 38;154 NETDOWN = 38,
155pub const ENETRESET: errno_t = 39;155 NETRESET = 39,
156pub const ENETUNREACH: errno_t = 40;156 NETUNREACH = 40,
157pub const ENFILE: errno_t = 41;157 NFILE = 41,
158pub const ENOBUFS: errno_t = 42;158 NOBUFS = 42,
159pub const ENODEV: errno_t = 43;159 NODEV = 43,
160pub const ENOENT: errno_t = 44;160 NOENT = 44,
161pub const ENOEXEC: errno_t = 45;161 NOEXEC = 45,
162pub const ENOLCK: errno_t = 46;162 NOLCK = 46,
163pub const ENOLINK: errno_t = 47;163 NOLINK = 47,
164pub const ENOMEM: errno_t = 48;164 NOMEM = 48,
165pub const ENOMSG: errno_t = 49;165 NOMSG = 49,
166pub const ENOPROTOOPT: errno_t = 50;166 NOPROTOOPT = 50,
167pub const ENOSPC: errno_t = 51;167 NOSPC = 51,
168pub const ENOSYS: errno_t = 52;168 NOSYS = 52,
169pub const ENOTCONN: errno_t = 53;169 NOTCONN = 53,
170pub const ENOTDIR: errno_t = 54;170 NOTDIR = 54,
171pub const ENOTEMPTY: errno_t = 55;171 NOTEMPTY = 55,
172pub const ENOTRECOVERABLE: errno_t = 56;172 NOTRECOVERABLE = 56,
173pub const ENOTSOCK: errno_t = 57;173 NOTSOCK = 57,
174pub const ENOTSUP: errno_t = 58;174 /// This is also the code used for `NOTSUP`.
175pub const EOPNOTSUPP = ENOTSUP;175 OPNOTSUPP = 58,
176pub const ENOTTY: errno_t = 59;176 NOTTY = 59,
177pub const ENXIO: errno_t = 60;177 NXIO = 60,
178pub const EOVERFLOW: errno_t = 61;178 OVERFLOW = 61,
179pub const EOWNERDEAD: errno_t = 62;179 OWNERDEAD = 62,
180pub const EPERM: errno_t = 63;180 PERM = 63,
181pub const EPIPE: errno_t = 64;181 PIPE = 64,
182pub const EPROTO: errno_t = 65;182 PROTO = 65,
183pub const EPROTONOSUPPORT: errno_t = 66;183 PROTONOSUPPORT = 66,
184pub const EPROTOTYPE: errno_t = 67;184 PROTOTYPE = 67,
185pub const ERANGE: errno_t = 68;185 RANGE = 68,
186pub const EROFS: errno_t = 69;186 ROFS = 69,
187pub const ESPIPE: errno_t = 70;187 SPIPE = 70,
188pub const ESRCH: errno_t = 71;188 SRCH = 71,
189pub const ESTALE: errno_t = 72;189 STALE = 72,
190pub const ETIMEDOUT: errno_t = 73;190 TIMEDOUT = 73,
191pub const ETXTBSY: errno_t = 74;191 TXTBSY = 74,
192pub const EXDEV: errno_t = 75;192 XDEV = 75,
193pub const ENOTCAPABLE: errno_t = 76;193 NOTCAPABLE = 76,
194 _,
195};
196pub const E = errno_t;
194197
195pub const event_t = extern struct {198pub const event_t = extern struct {
196 userdata: userdata_t,199 userdata: userdata_t,
lib/std/os/bits/windows.zig+90-86
...@@ -87,93 +87,97 @@ pub const SEEK_SET = 0;...@@ -87,93 +87,97 @@ pub const SEEK_SET = 0;
87pub const SEEK_CUR = 1;87pub const SEEK_CUR = 1;
88pub const SEEK_END = 2;88pub const SEEK_END = 2;
8989
90pub const EPERM = 1;90pub const E = enum(u16) {
91pub const ENOENT = 2;91 /// No error occurred.
92pub const ESRCH = 3;92 SUCCESS = 0,
93pub const EINTR = 4;93 PERM = 1,
94pub const EIO = 5;94 NOENT = 2,
95pub const ENXIO = 6;95 SRCH = 3,
96pub const E2BIG = 7;96 INTR = 4,
97pub const ENOEXEC = 8;97 IO = 5,
98pub const EBADF = 9;98 NXIO = 6,
99pub const ECHILD = 10;99 @"2BIG" = 7,
100pub const EAGAIN = 11;100 NOEXEC = 8,
101pub const ENOMEM = 12;101 BADF = 9,
102pub const EACCES = 13;102 CHILD = 10,
103pub const EFAULT = 14;103 AGAIN = 11,
104pub const EBUSY = 16;104 NOMEM = 12,
105pub const EEXIST = 17;105 ACCES = 13,
106pub const EXDEV = 18;106 FAULT = 14,
107pub const ENODEV = 19;107 BUSY = 16,
108pub const ENOTDIR = 20;108 EXIST = 17,
109pub const EISDIR = 21;109 XDEV = 18,
110pub const ENFILE = 23;110 NODEV = 19,
111pub const EMFILE = 24;111 NOTDIR = 20,
112pub const ENOTTY = 25;112 ISDIR = 21,
113pub const EFBIG = 27;113 NFILE = 23,
114pub const ENOSPC = 28;114 MFILE = 24,
115pub const ESPIPE = 29;115 NOTTY = 25,
116pub const EROFS = 30;116 FBIG = 27,
117pub const EMLINK = 31;117 NOSPC = 28,
118pub const EPIPE = 32;118 SPIPE = 29,
119pub const EDOM = 33;119 ROFS = 30,
120pub const EDEADLK = 36;120 MLINK = 31,
121pub const ENAMETOOLONG = 38;121 PIPE = 32,
122pub const ENOLCK = 39;122 DOM = 33,
123pub const ENOSYS = 40;123 /// Also means `DEADLOCK`.
124pub const ENOTEMPTY = 41;124 DEADLK = 36,
125125 NAMETOOLONG = 38,
126pub const EINVAL = 22;126 NOLCK = 39,
127pub const ERANGE = 34;127 NOSYS = 40,
128pub const EILSEQ = 42;128 NOTEMPTY = 41,
129pub const STRUNCATE = 80;129
130 INVAL = 22,
131 RANGE = 34,
132 ILSEQ = 42,
133
134 // POSIX Supplement
135 ADDRINUSE = 100,
136 ADDRNOTAVAIL = 101,
137 AFNOSUPPORT = 102,
138 ALREADY = 103,
139 BADMSG = 104,
140 CANCELED = 105,
141 CONNABORTED = 106,
142 CONNREFUSED = 107,
143 CONNRESET = 108,
144 DESTADDRREQ = 109,
145 HOSTUNREACH = 110,
146 IDRM = 111,
147 INPROGRESS = 112,
148 ISCONN = 113,
149 LOOP = 114,
150 MSGSIZE = 115,
151 NETDOWN = 116,
152 NETRESET = 117,
153 NETUNREACH = 118,
154 NOBUFS = 119,
155 NODATA = 120,
156 NOLINK = 121,
157 NOMSG = 122,
158 NOPROTOOPT = 123,
159 NOSR = 124,
160 NOSTR = 125,
161 NOTCONN = 126,
162 NOTRECOVERABLE = 127,
163 NOTSOCK = 128,
164 NOTSUP = 129,
165 OPNOTSUPP = 130,
166 OTHER = 131,
167 OVERFLOW = 132,
168 OWNERDEAD = 133,
169 PROTO = 134,
170 PROTONOSUPPORT = 135,
171 PROTOTYPE = 136,
172 TIME = 137,
173 TIMEDOUT = 138,
174 TXTBSY = 139,
175 WOULDBLOCK = 140,
176 DQUOT = 10069,
177 _,
178};
130179
131// Support EDEADLOCK for compatibility with older Microsoft C versions180pub const STRUNCATE = 80;
132pub const EDEADLOCK = EDEADLK;
133
134// POSIX Supplement
135pub const EADDRINUSE = 100;
136pub const EADDRNOTAVAIL = 101;
137pub const EAFNOSUPPORT = 102;
138pub const EALREADY = 103;
139pub const EBADMSG = 104;
140pub const ECANCELED = 105;
141pub const ECONNABORTED = 106;
142pub const ECONNREFUSED = 107;
143pub const ECONNRESET = 108;
144pub const EDESTADDRREQ = 109;
145pub const EHOSTUNREACH = 110;
146pub const EIDRM = 111;
147pub const EINPROGRESS = 112;
148pub const EISCONN = 113;
149pub const ELOOP = 114;
150pub const EMSGSIZE = 115;
151pub const ENETDOWN = 116;
152pub const ENETRESET = 117;
153pub const ENETUNREACH = 118;
154pub const ENOBUFS = 119;
155pub const ENODATA = 120;
156pub const ENOLINK = 121;
157pub const ENOMSG = 122;
158pub const ENOPROTOOPT = 123;
159pub const ENOSR = 124;
160pub const ENOSTR = 125;
161pub const ENOTCONN = 126;
162pub const ENOTRECOVERABLE = 127;
163pub const ENOTSOCK = 128;
164pub const ENOTSUP = 129;
165pub const EOPNOTSUPP = 130;
166pub const EOTHER = 131;
167pub const EOVERFLOW = 132;
168pub const EOWNERDEAD = 133;
169pub const EPROTO = 134;
170pub const EPROTONOSUPPORT = 135;
171pub const EPROTOTYPE = 136;
172pub const ETIME = 137;
173pub const ETIMEDOUT = 138;
174pub const ETXTBSY = 139;
175pub const EWOULDBLOCK = 140;
176pub const EDQUOT = 10069;
177181
178pub const F_OK = 0;182pub const F_OK = 0;
179183
lib/std/os/linux.zig+8-7
...@@ -91,9 +91,10 @@ fn splitValue64(val: i64) [2]u32 {...@@ -91,9 +91,10 @@ fn splitValue64(val: i64) [2]u32 {
91}91}
9292
93/// Get the errno from a syscall return value, or 0 for no error.93/// Get the errno from a syscall return value, or 0 for no error.
94pub fn getErrno(r: usize) u12 {94pub fn getErrno(r: usize) E {
95 const signed_r = @bitCast(isize, r);95 const signed_r = @bitCast(isize, r);
96 return if (signed_r > -4096 and signed_r < 0) @intCast(u12, -signed_r) else 0;96 const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0;
97 return @intToEnum(E, int);
97}98}
9899
99pub fn dup(old: i32) usize {100pub fn dup(old: i32) usize {
...@@ -281,7 +282,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of...@@ -281,7 +282,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
281 if (@hasField(SYS, "mmap2")) {282 if (@hasField(SYS, "mmap2")) {
282 // Make sure the offset is also specified in multiples of page size283 // Make sure the offset is also specified in multiples of page size
283 if ((offset & (MMAP2_UNIT - 1)) != 0)284 if ((offset & (MMAP2_UNIT - 1)) != 0)
284 return @bitCast(usize, @as(isize, -EINVAL));285 return @bitCast(usize, -@as(isize, @enumToInt(E.INVAL)));
285286
286 return syscall6(287 return syscall6(
287 .mmap2,288 .mmap2,
...@@ -746,7 +747,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {...@@ -746,7 +747,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
746 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);747 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
747 const rc = f(clk_id, tp);748 const rc = f(clk_id, tp);
748 switch (rc) {749 switch (rc) {
749 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc,750 0, @bitCast(usize, -@as(isize, @enumToInt(E.INVAL))) => return rc,
750 else => {},751 else => {},
751 }752 }
752 }753 }
...@@ -764,7 +765,7 @@ fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {...@@ -764,7 +765,7 @@ fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
764 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);765 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
765 return f(clk, ts);766 return f(clk, ts);
766 }767 }
767 return @bitCast(usize, @as(isize, -ENOSYS));768 return @bitCast(usize, -@as(isize, @enumToInt(E.NOSYS)));
768}769}
769770
770pub fn clock_getres(clk_id: i32, tp: *timespec) usize {771pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
...@@ -961,7 +962,7 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact...@@ -961,7 +962,7 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
961 .sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),962 .sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),
962 else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),963 else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),
963 };964 };
964 if (getErrno(result) != 0) return result;965 if (getErrno(result) != .SUCCESS) return result;
965966
966 if (oact) |old| {967 if (oact) |old| {
967 old.handler.handler = oldksa.handler;968 old.handler.handler = oldksa.handler;
...@@ -1202,7 +1203,7 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S...@@ -1202,7 +1203,7 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
1202 @ptrToInt(statx_buf),1203 @ptrToInt(statx_buf),
1203 );1204 );
1204 }1205 }
1205 return @bitCast(usize, @as(isize, -ENOSYS));1206 return @bitCast(usize, -@as(isize, @enumToInt(E.NOSYS)));
1206}1207}
12071208
1208pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {1209pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
lib/std/os/linux/bpf.zig+31-31
...@@ -1508,13 +1508,13 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries...@@ -1508,13 +1508,13 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries
1508 attr.map_create.max_entries = max_entries;1508 attr.map_create.max_entries = max_entries;
15091509
1510 const rc = bpf(.map_create, &attr, @sizeOf(MapCreateAttr));1510 const rc = bpf(.map_create, &attr, @sizeOf(MapCreateAttr));
1511 return switch (errno(rc)) {1511 switch (errno(rc)) {
1512 0 => @intCast(fd_t, rc),1512 .SUCCESS => return @intCast(fd_t, rc),
1513 EINVAL => error.MapTypeOrAttrInvalid,1513 .INVAL => return error.MapTypeOrAttrInvalid,
1514 ENOMEM => error.SystemResources,1514 .NOMEM => return error.SystemResources,
1515 EPERM => error.AccessDenied,1515 .PERM => return error.AccessDenied,
1516 else => |err| unexpectedErrno(err),1516 else => |err| return unexpectedErrno(err),
1517 };1517 }
1518}1518}
15191519
1520test "map_create" {1520test "map_create" {
...@@ -1533,12 +1533,12 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void {...@@ -1533,12 +1533,12 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void {
15331533
1534 const rc = bpf(.map_lookup_elem, &attr, @sizeOf(MapElemAttr));1534 const rc = bpf(.map_lookup_elem, &attr, @sizeOf(MapElemAttr));
1535 switch (errno(rc)) {1535 switch (errno(rc)) {
1536 0 => return,1536 .SUCCESS => return,
1537 EBADF => return error.BadFd,1537 .BADF => return error.BadFd,
1538 EFAULT => unreachable,1538 .FAULT => unreachable,
1539 EINVAL => return error.FieldInAttrNeedsZeroing,1539 .INVAL => return error.FieldInAttrNeedsZeroing,
1540 ENOENT => return error.NotFound,1540 .NOENT => return error.NotFound,
1541 EPERM => return error.AccessDenied,1541 .PERM => return error.AccessDenied,
1542 else => |err| return unexpectedErrno(err),1542 else => |err| return unexpectedErrno(err),
1543 }1543 }
1544}1544}
...@@ -1555,13 +1555,13 @@ pub fn map_update_elem(fd: fd_t, key: []const u8, value: []const u8, flags: u64)...@@ -1555,13 +1555,13 @@ pub fn map_update_elem(fd: fd_t, key: []const u8, value: []const u8, flags: u64)
15551555
1556 const rc = bpf(.map_update_elem, &attr, @sizeOf(MapElemAttr));1556 const rc = bpf(.map_update_elem, &attr, @sizeOf(MapElemAttr));
1557 switch (errno(rc)) {1557 switch (errno(rc)) {
1558 0 => return,1558 .SUCCESS => return,
1559 E2BIG => return error.ReachedMaxEntries,1559 .@"2BIG" => return error.ReachedMaxEntries,
1560 EBADF => return error.BadFd,1560 .BADF => return error.BadFd,
1561 EFAULT => unreachable,1561 .FAULT => unreachable,
1562 EINVAL => return error.FieldInAttrNeedsZeroing,1562 .INVAL => return error.FieldInAttrNeedsZeroing,
1563 ENOMEM => return error.SystemResources,1563 .NOMEM => return error.SystemResources,
1564 EPERM => return error.AccessDenied,1564 .PERM => return error.AccessDenied,
1565 else => |err| return unexpectedErrno(err),1565 else => |err| return unexpectedErrno(err),
1566 }1566 }
1567}1567}
...@@ -1576,12 +1576,12 @@ pub fn map_delete_elem(fd: fd_t, key: []const u8) !void {...@@ -1576,12 +1576,12 @@ pub fn map_delete_elem(fd: fd_t, key: []const u8) !void {
15761576
1577 const rc = bpf(.map_delete_elem, &attr, @sizeOf(MapElemAttr));1577 const rc = bpf(.map_delete_elem, &attr, @sizeOf(MapElemAttr));
1578 switch (errno(rc)) {1578 switch (errno(rc)) {
1579 0 => return,1579 .SUCCESS => return,
1580 EBADF => return error.BadFd,1580 .BADF => return error.BadFd,
1581 EFAULT => unreachable,1581 .FAULT => unreachable,
1582 EINVAL => return error.FieldInAttrNeedsZeroing,1582 .INVAL => return error.FieldInAttrNeedsZeroing,
1583 ENOENT => return error.NotFound,1583 .NOENT => return error.NotFound,
1584 EPERM => return error.AccessDenied,1584 .PERM => return error.AccessDenied,
1585 else => |err| return unexpectedErrno(err),1585 else => |err| return unexpectedErrno(err),
1586 }1586 }
1587}1587}
...@@ -1639,11 +1639,11 @@ pub fn prog_load(...@@ -1639,11 +1639,11 @@ pub fn prog_load(
16391639
1640 const rc = bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));1640 const rc = bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));
1641 return switch (errno(rc)) {1641 return switch (errno(rc)) {
1642 0 => @intCast(fd_t, rc),1642 .SUCCESS => @intCast(fd_t, rc),
1643 EACCES => error.UnsafeProgram,1643 .ACCES => error.UnsafeProgram,
1644 EFAULT => unreachable,1644 .FAULT => unreachable,
1645 EINVAL => error.InvalidProgram,1645 .INVAL => error.InvalidProgram,
1646 EPERM => error.AccessDenied,1646 .PERM => error.AccessDenied,
1647 else => |err| unexpectedErrno(err),1647 else => |err| unexpectedErrno(err),
1648 };1648 };
1649}1649}
lib/std/os/linux/io_uring.zig+44-44
...@@ -54,19 +54,19 @@ pub const IO_Uring = struct {...@@ -54,19 +54,19 @@ pub const IO_Uring = struct {
5454
55 const res = linux.io_uring_setup(entries, p);55 const res = linux.io_uring_setup(entries, p);
56 switch (linux.getErrno(res)) {56 switch (linux.getErrno(res)) {
57 0 => {},57 .SUCCESS => {},
58 linux.EFAULT => return error.ParamsOutsideAccessibleAddressSpace,58 .FAULT => return error.ParamsOutsideAccessibleAddressSpace,
59 // The resv array contains non-zero data, p.flags contains an unsupported flag,59 // The resv array contains non-zero data, p.flags contains an unsupported flag,
60 // entries out of bounds, IORING_SETUP_SQ_AFF was specified without IORING_SETUP_SQPOLL,60 // entries out of bounds, IORING_SETUP_SQ_AFF was specified without IORING_SETUP_SQPOLL,
61 // or IORING_SETUP_CQSIZE was specified but io_uring_params.cq_entries was invalid:61 // or IORING_SETUP_CQSIZE was specified but io_uring_params.cq_entries was invalid:
62 linux.EINVAL => return error.ArgumentsInvalid,62 .INVAL => return error.ArgumentsInvalid,
63 linux.EMFILE => return error.ProcessFdQuotaExceeded,63 .MFILE => return error.ProcessFdQuotaExceeded,
64 linux.ENFILE => return error.SystemFdQuotaExceeded,64 .NFILE => return error.SystemFdQuotaExceeded,
65 linux.ENOMEM => return error.SystemResources,65 .NOMEM => return error.SystemResources,
66 // IORING_SETUP_SQPOLL was specified but effective user ID lacks sufficient privileges,66 // IORING_SETUP_SQPOLL was specified but effective user ID lacks sufficient privileges,
67 // or a container seccomp policy prohibits io_uring syscalls:67 // or a container seccomp policy prohibits io_uring syscalls:
68 linux.EPERM => return error.PermissionDenied,68 .PERM => return error.PermissionDenied,
69 linux.ENOSYS => return error.SystemOutdated,69 .NOSYS => return error.SystemOutdated,
70 else => |errno| return os.unexpectedErrno(errno),70 else => |errno| return os.unexpectedErrno(errno),
71 }71 }
72 const fd = @intCast(os.fd_t, res);72 const fd = @intCast(os.fd_t, res);
...@@ -180,31 +180,31 @@ pub const IO_Uring = struct {...@@ -180,31 +180,31 @@ pub const IO_Uring = struct {
180 assert(self.fd >= 0);180 assert(self.fd >= 0);
181 const res = linux.io_uring_enter(self.fd, to_submit, min_complete, flags, null);181 const res = linux.io_uring_enter(self.fd, to_submit, min_complete, flags, null);
182 switch (linux.getErrno(res)) {182 switch (linux.getErrno(res)) {
183 0 => {},183 .SUCCESS => {},
184 // The kernel was unable to allocate memory or ran out of resources for the request.184 // The kernel was unable to allocate memory or ran out of resources for the request.
185 // The application should wait for some completions and try again:185 // The application should wait for some completions and try again:
186 linux.EAGAIN => return error.SystemResources,186 .AGAIN => return error.SystemResources,
187 // The SQE `fd` is invalid, or IOSQE_FIXED_FILE was set but no files were registered:187 // The SQE `fd` is invalid, or IOSQE_FIXED_FILE was set but no files were registered:
188 linux.EBADF => return error.FileDescriptorInvalid,188 .BADF => return error.FileDescriptorInvalid,
189 // The file descriptor is valid, but the ring is not in the right state.189 // The file descriptor is valid, but the ring is not in the right state.
190 // See io_uring_register(2) for how to enable the ring.190 // See io_uring_register(2) for how to enable the ring.
191 linux.EBADFD => return error.FileDescriptorInBadState,191 .BADFD => return error.FileDescriptorInBadState,
192 // The application attempted to overcommit the number of requests it can have pending.192 // The application attempted to overcommit the number of requests it can have pending.
193 // The application should wait for some completions and try again:193 // The application should wait for some completions and try again:
194 linux.EBUSY => return error.CompletionQueueOvercommitted,194 .BUSY => return error.CompletionQueueOvercommitted,
195 // The SQE is invalid, or valid but the ring was setup with IORING_SETUP_IOPOLL:195 // The SQE is invalid, or valid but the ring was setup with IORING_SETUP_IOPOLL:
196 linux.EINVAL => return error.SubmissionQueueEntryInvalid,196 .INVAL => return error.SubmissionQueueEntryInvalid,
197 // The buffer is outside the process' accessible address space, or IORING_OP_READ_FIXED197 // The buffer is outside the process' accessible address space, or IORING_OP_READ_FIXED
198 // or IORING_OP_WRITE_FIXED was specified but no buffers were registered, or the range198 // or IORING_OP_WRITE_FIXED was specified but no buffers were registered, or the range
199 // described by `addr` and `len` is not within the buffer registered at `buf_index`:199 // described by `addr` and `len` is not within the buffer registered at `buf_index`:
200 linux.EFAULT => return error.BufferInvalid,200 .FAULT => return error.BufferInvalid,
201 linux.ENXIO => return error.RingShuttingDown,201 .NXIO => return error.RingShuttingDown,
202 // The kernel believes our `self.fd` does not refer to an io_uring instance,202 // The kernel believes our `self.fd` does not refer to an io_uring instance,
203 // or the opcode is valid but not supported by this kernel (more likely):203 // or the opcode is valid but not supported by this kernel (more likely):
204 linux.EOPNOTSUPP => return error.OpcodeNotSupported,204 .OPNOTSUPP => return error.OpcodeNotSupported,
205 // The operation was interrupted by a delivery of a signal before it could complete.205 // The operation was interrupted by a delivery of a signal before it could complete.
206 // This can happen while waiting for events with IORING_ENTER_GETEVENTS:206 // This can happen while waiting for events with IORING_ENTER_GETEVENTS:
207 linux.EINTR => return error.SignalInterrupt,207 .INTR => return error.SignalInterrupt,
208 else => |errno| return os.unexpectedErrno(errno),208 else => |errno| return os.unexpectedErrno(errno),
209 }209 }
210 return @intCast(u32, res);210 return @intCast(u32, res);
...@@ -681,22 +681,22 @@ pub const IO_Uring = struct {...@@ -681,22 +681,22 @@ pub const IO_Uring = struct {
681681
682 fn handle_registration_result(res: usize) !void {682 fn handle_registration_result(res: usize) !void {
683 switch (linux.getErrno(res)) {683 switch (linux.getErrno(res)) {
684 0 => {},684 .SUCCESS => {},
685 // One or more fds in the array are invalid, or the kernel does not support sparse sets:685 // One or more fds in the array are invalid, or the kernel does not support sparse sets:
686 linux.EBADF => return error.FileDescriptorInvalid,686 .BADF => return error.FileDescriptorInvalid,
687 linux.EBUSY => return error.FilesAlreadyRegistered,687 .BUSY => return error.FilesAlreadyRegistered,
688 linux.EINVAL => return error.FilesEmpty,688 .INVAL => return error.FilesEmpty,
689 // Adding `nr_args` file references would exceed the maximum allowed number of files the689 // Adding `nr_args` file references would exceed the maximum allowed number of files the
690 // user is allowed to have according to the per-user RLIMIT_NOFILE resource limit and690 // user is allowed to have according to the per-user RLIMIT_NOFILE resource limit and
691 // the CAP_SYS_RESOURCE capability is not set, or `nr_args` exceeds the maximum allowed691 // the CAP_SYS_RESOURCE capability is not set, or `nr_args` exceeds the maximum allowed
692 // for a fixed file set (older kernels have a limit of 1024 files vs 64K files):692 // for a fixed file set (older kernels have a limit of 1024 files vs 64K files):
693 linux.EMFILE => return error.UserFdQuotaExceeded,693 .MFILE => return error.UserFdQuotaExceeded,
694 // Insufficient kernel resources, or the caller had a non-zero RLIMIT_MEMLOCK soft694 // Insufficient kernel resources, or the caller had a non-zero RLIMIT_MEMLOCK soft
695 // resource limit but tried to lock more memory than the limit permitted (not enforced695 // resource limit but tried to lock more memory than the limit permitted (not enforced
696 // when the process is privileged with CAP_IPC_LOCK):696 // when the process is privileged with CAP_IPC_LOCK):
697 linux.ENOMEM => return error.SystemResources,697 .NOMEM => return error.SystemResources,
698 // Attempt to register files on a ring already registering files or being torn down:698 // Attempt to register files on a ring already registering files or being torn down:
699 linux.ENXIO => return error.RingShuttingDownOrAlreadyRegisteringFiles,699 .NXIO => return error.RingShuttingDownOrAlreadyRegisteringFiles,
700 else => |errno| return os.unexpectedErrno(errno),700 else => |errno| return os.unexpectedErrno(errno),
701 }701 }
702 }702 }
...@@ -706,8 +706,8 @@ pub const IO_Uring = struct {...@@ -706,8 +706,8 @@ pub const IO_Uring = struct {
706 assert(self.fd >= 0);706 assert(self.fd >= 0);
707 const res = linux.io_uring_register(self.fd, .UNREGISTER_FILES, null, 0);707 const res = linux.io_uring_register(self.fd, .UNREGISTER_FILES, null, 0);
708 switch (linux.getErrno(res)) {708 switch (linux.getErrno(res)) {
709 0 => {},709 .SUCCESS => {},
710 linux.ENXIO => return error.FilesNotRegistered,710 .NXIO => return error.FilesNotRegistered,
711 else => |errno| return os.unexpectedErrno(errno),711 else => |errno| return os.unexpectedErrno(errno),
712 }712 }
713 }713 }
...@@ -1272,8 +1272,8 @@ test "write/read" {...@@ -1272,8 +1272,8 @@ test "write/read" {
1272 const cqe_read = try ring.copy_cqe();1272 const cqe_read = try ring.copy_cqe();
1273 // Prior to Linux Kernel 5.6 this is the only way to test for read/write support:1273 // Prior to Linux Kernel 5.6 this is the only way to test for read/write support:
1274 // https://lwn.net/Articles/809820/1274 // https://lwn.net/Articles/809820/
1275 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;1275 if (cqe_write.err() == .INVAL) return error.SkipZigTest;
1276 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;1276 if (cqe_read.err() == .INVAL) return error.SkipZigTest;
1277 try testing.expectEqual(linux.io_uring_cqe{1277 try testing.expectEqual(linux.io_uring_cqe{
1278 .user_data = 0x11111111,1278 .user_data = 0x11111111,
1279 .res = buffer_write.len,1279 .res = buffer_write.len,
...@@ -1322,11 +1322,11 @@ test "openat" {...@@ -1322,11 +1322,11 @@ test "openat" {
13221322
1323 const cqe_openat = try ring.copy_cqe();1323 const cqe_openat = try ring.copy_cqe();
1324 try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);1324 try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
1325 if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;1325 if (cqe_openat.err() == .INVAL) return error.SkipZigTest;
1326 // AT_FDCWD is not fully supported before kernel 5.6:1326 // AT_FDCWD is not fully supported before kernel 5.6:
1327 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/1327 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
1328 // We use IORING_FEAT_RW_CUR_POS to know if we are pre-5.6 since that feature was added in 5.6.1328 // We use IORING_FEAT_RW_CUR_POS to know if we are pre-5.6 since that feature was added in 5.6.
1329 if (cqe_openat.res == -linux.EBADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) {1329 if (cqe_openat.err() == .BADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) {
1330 return error.SkipZigTest;1330 return error.SkipZigTest;
1331 }1331 }
1332 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});1332 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
...@@ -1357,7 +1357,7 @@ test "close" {...@@ -1357,7 +1357,7 @@ test "close" {
1357 try testing.expectEqual(@as(u32, 1), try ring.submit());1357 try testing.expectEqual(@as(u32, 1), try ring.submit());
13581358
1359 const cqe_close = try ring.copy_cqe();1359 const cqe_close = try ring.copy_cqe();
1360 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;1360 if (cqe_close.err() == .INVAL) return error.SkipZigTest;
1361 try testing.expectEqual(linux.io_uring_cqe{1361 try testing.expectEqual(linux.io_uring_cqe{
1362 .user_data = 0x44444444,1362 .user_data = 0x44444444,
1363 .res = 0,1363 .res = 0,
...@@ -1397,9 +1397,9 @@ test "accept/connect/send/recv" {...@@ -1397,9 +1397,9 @@ test "accept/connect/send/recv" {
1397 try testing.expectEqual(@as(u32, 1), try ring.submit());1397 try testing.expectEqual(@as(u32, 1), try ring.submit());
13981398
1399 var cqe_accept = try ring.copy_cqe();1399 var cqe_accept = try ring.copy_cqe();
1400 if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;1400 if (cqe_accept.err() == .INVAL) return error.SkipZigTest;
1401 var cqe_connect = try ring.copy_cqe();1401 var cqe_connect = try ring.copy_cqe();
1402 if (cqe_connect.res == -linux.EINVAL) return error.SkipZigTest;1402 if (cqe_connect.err() == .INVAL) return error.SkipZigTest;
14031403
1404 // The accept/connect CQEs may arrive in any order, the connect CQE will sometimes come first:1404 // The accept/connect CQEs may arrive in any order, the connect CQE will sometimes come first:
1405 if (cqe_accept.user_data == 0xcccccccc and cqe_connect.user_data == 0xaaaaaaaa) {1405 if (cqe_accept.user_data == 0xcccccccc and cqe_connect.user_data == 0xaaaaaaaa) {
...@@ -1425,7 +1425,7 @@ test "accept/connect/send/recv" {...@@ -1425,7 +1425,7 @@ test "accept/connect/send/recv" {
1425 try testing.expectEqual(@as(u32, 2), try ring.submit());1425 try testing.expectEqual(@as(u32, 2), try ring.submit());
14261426
1427 const cqe_send = try ring.copy_cqe();1427 const cqe_send = try ring.copy_cqe();
1428 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;1428 if (cqe_send.err() == .INVAL) return error.SkipZigTest;
1429 try testing.expectEqual(linux.io_uring_cqe{1429 try testing.expectEqual(linux.io_uring_cqe{
1430 .user_data = 0xeeeeeeee,1430 .user_data = 0xeeeeeeee,
1431 .res = buffer_send.len,1431 .res = buffer_send.len,
...@@ -1433,7 +1433,7 @@ test "accept/connect/send/recv" {...@@ -1433,7 +1433,7 @@ test "accept/connect/send/recv" {
1433 }, cqe_send);1433 }, cqe_send);
14341434
1435 const cqe_recv = try ring.copy_cqe();1435 const cqe_recv = try ring.copy_cqe();
1436 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;1436 if (cqe_recv.err() == .INVAL) return error.SkipZigTest;
1437 try testing.expectEqual(linux.io_uring_cqe{1437 try testing.expectEqual(linux.io_uring_cqe{
1438 .user_data = 0xffffffff,1438 .user_data = 0xffffffff,
1439 .res = buffer_recv.len,1439 .res = buffer_recv.len,
...@@ -1466,7 +1466,7 @@ test "timeout (after a relative time)" {...@@ -1466,7 +1466,7 @@ test "timeout (after a relative time)" {
14661466
1467 try testing.expectEqual(linux.io_uring_cqe{1467 try testing.expectEqual(linux.io_uring_cqe{
1468 .user_data = 0x55555555,1468 .user_data = 0x55555555,
1469 .res = -linux.ETIME,1469 .res = -@as(i32, @enumToInt(linux.E.TIME)),
1470 .flags = 0,1470 .flags = 0,
1471 }, cqe);1471 }, cqe);
14721472
...@@ -1535,14 +1535,14 @@ test "timeout_remove" {...@@ -1535,14 +1535,14 @@ test "timeout_remove" {
1535 // We use IORING_FEAT_RW_CUR_POS as a safety check here to make sure we are at least pre-5.6.1535 // We use IORING_FEAT_RW_CUR_POS as a safety check here to make sure we are at least pre-5.6.
1536 // We don't want to skip this test for newer kernels.1536 // We don't want to skip this test for newer kernels.
1537 if (cqe_timeout.user_data == 0x99999999 and1537 if (cqe_timeout.user_data == 0x99999999 and
1538 cqe_timeout.res == -linux.EBADF and1538 cqe_timeout.err() == .BADF and
1539 (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0)1539 (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0)
1540 {1540 {
1541 return error.SkipZigTest;1541 return error.SkipZigTest;
1542 }1542 }
1543 try testing.expectEqual(linux.io_uring_cqe{1543 try testing.expectEqual(linux.io_uring_cqe{
1544 .user_data = 0x88888888,1544 .user_data = 0x88888888,
1545 .res = -linux.ECANCELED,1545 .res = -@as(i32, @enumToInt(linux.E.CANCELED)),
1546 .flags = 0,1546 .flags = 0,
1547 }, cqe_timeout);1547 }, cqe_timeout);
15481548
...@@ -1578,15 +1578,15 @@ test "fallocate" {...@@ -1578,15 +1578,15 @@ test "fallocate" {
1578 try testing.expectEqual(@as(u32, 1), try ring.submit());1578 try testing.expectEqual(@as(u32, 1), try ring.submit());
15791579
1580 const cqe = try ring.copy_cqe();1580 const cqe = try ring.copy_cqe();
1581 switch (-cqe.res) {1581 switch (cqe.err()) {
1582 0 => {},1582 .SUCCESS => {},
1583 // This kernel's io_uring does not yet implement fallocate():1583 // This kernel's io_uring does not yet implement fallocate():
1584 linux.EINVAL => return error.SkipZigTest,1584 .INVAL => return error.SkipZigTest,
1585 // This kernel does not implement fallocate():1585 // This kernel does not implement fallocate():
1586 linux.ENOSYS => return error.SkipZigTest,1586 .NOSYS => return error.SkipZigTest,
1587 // The filesystem containing the file referred to by fd does not support this operation;1587 // The filesystem containing the file referred to by fd does not support this operation;
1588 // or the mode is not supported by the filesystem containing the file referred to by fd:1588 // or the mode is not supported by the filesystem containing the file referred to by fd:
1589 linux.EOPNOTSUPP => return error.SkipZigTest,1589 .OPNOTSUPP => return error.SkipZigTest,
1590 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),1590 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
1591 }1591 }
1592 try testing.expectEqual(linux.io_uring_cqe{1592 try testing.expectEqual(linux.io_uring_cqe{
lib/std/os/linux/test.zig+15-15
...@@ -22,9 +22,9 @@ test "fallocate" {...@@ -22,9 +22,9 @@ test "fallocate" {
2222
23 const len: i64 = 65536;23 const len: i64 = 65536;
24 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {24 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
25 0 => {},25 .SUCCESS => {},
26 linux.ENOSYS => return error.SkipZigTest,26 .NOSYS => return error.SkipZigTest,
27 linux.EOPNOTSUPP => return error.SkipZigTest,27 .OPNOTSUPP => return error.SkipZigTest,
28 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),28 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
29 }29 }
3030
...@@ -37,11 +37,11 @@ test "getpid" {...@@ -37,11 +37,11 @@ test "getpid" {
3737
38test "timer" {38test "timer" {
39 const epoll_fd = linux.epoll_create();39 const epoll_fd = linux.epoll_create();
40 var err: usize = linux.getErrno(epoll_fd);40 var err: linux.E = linux.getErrno(epoll_fd);
41 try expect(err == 0);41 try expect(err == .SUCCESS);
4242
43 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);43 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
44 try expect(linux.getErrno(timer_fd) == 0);44 try expect(linux.getErrno(timer_fd) == .SUCCESS);
4545
46 const time_interval = linux.timespec{46 const time_interval = linux.timespec{
47 .tv_sec = 0,47 .tv_sec = 0,
...@@ -53,22 +53,22 @@ test "timer" {...@@ -53,22 +53,22 @@ test "timer" {
53 .it_value = time_interval,53 .it_value = time_interval,
54 };54 };
5555
56 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);56 err = linux.getErrno(linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null));
57 try expect(err == 0);57 try expect(err == .SUCCESS);
5858
59 var event = linux.epoll_event{59 var event = linux.epoll_event{
60 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,60 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
61 .data = linux.epoll_data{ .ptr = 0 },61 .data = linux.epoll_data{ .ptr = 0 },
62 };62 };
6363
64 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);64 err = linux.getErrno(linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event));
65 try expect(err == 0);65 try expect(err == .SUCCESS);
6666
67 const events_one: linux.epoll_event = undefined;67 const events_one: linux.epoll_event = undefined;
68 var events = [_]linux.epoll_event{events_one} ** 8;68 var events = [_]linux.epoll_event{events_one} ** 8;
6969
70 // TODO implicit cast from *[N]T to [*]T70 err = linux.getErrno(linux.epoll_wait(@intCast(i32, epoll_fd), &events, 8, -1));
71 err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);71 try expect(err == .SUCCESS);
72}72}
7373
74test "statx" {74test "statx" {
...@@ -81,15 +81,15 @@ test "statx" {...@@ -81,15 +81,15 @@ test "statx" {
8181
82 var statx_buf: linux.Statx = undefined;82 var statx_buf: linux.Statx = undefined;
83 switch (linux.getErrno(linux.statx(file.handle, "", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {83 switch (linux.getErrno(linux.statx(file.handle, "", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
84 0 => {},84 .SUCCESS => {},
85 // The statx syscall was only introduced in linux 4.1185 // The statx syscall was only introduced in linux 4.11
86 linux.ENOSYS => return error.SkipZigTest,86 .NOSYS => return error.SkipZigTest,
87 else => unreachable,87 else => unreachable,
88 }88 }
8989
90 var stat_buf: linux.kernel_stat = undefined;90 var stat_buf: linux.kernel_stat = undefined;
91 switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {91 switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
92 0 => {},92 .SUCCESS => {},
93 else => unreachable,93 else => unreachable,
94 }94 }
9595
lib/std/os/wasi.zig+1-1
...@@ -83,6 +83,6 @@ pub extern "wasi_snapshot_preview1" fn sock_send(sock: fd_t, si_data: *const cio...@@ -83,6 +83,6 @@ pub extern "wasi_snapshot_preview1" fn sock_send(sock: fd_t, si_data: *const cio
83pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t;83pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t;
8484
85/// Get the errno from a syscall return value, or 0 for no error.85/// Get the errno from a syscall return value, or 0 for no error.
86pub fn getErrno(r: errno_t) usize {86pub fn getErrno(r: errno_t) errno_t {
87 return r;87 return r;
88}88}
lib/std/process.zig+4-4
...@@ -93,7 +93,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {...@@ -93,7 +93,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
93 var environ_buf_size: usize = undefined;93 var environ_buf_size: usize = undefined;
9494
95 const environ_sizes_get_ret = os.wasi.environ_sizes_get(&environ_count, &environ_buf_size);95 const environ_sizes_get_ret = os.wasi.environ_sizes_get(&environ_count, &environ_buf_size);
96 if (environ_sizes_get_ret != os.wasi.ESUCCESS) {96 if (environ_sizes_get_ret != .SUCCESS) {
97 return os.unexpectedErrno(environ_sizes_get_ret);97 return os.unexpectedErrno(environ_sizes_get_ret);
98 }98 }
9999
...@@ -103,7 +103,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {...@@ -103,7 +103,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
103 defer allocator.free(environ_buf);103 defer allocator.free(environ_buf);
104104
105 const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);105 const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);
106 if (environ_get_ret != os.wasi.ESUCCESS) {106 if (environ_get_ret != .SUCCESS) {
107 return os.unexpectedErrno(environ_get_ret);107 return os.unexpectedErrno(environ_get_ret);
108 }108 }
109109
...@@ -255,7 +255,7 @@ pub const ArgIteratorWasi = struct {...@@ -255,7 +255,7 @@ pub const ArgIteratorWasi = struct {
255 var buf_size: usize = undefined;255 var buf_size: usize = undefined;
256256
257 switch (w.args_sizes_get(&count, &buf_size)) {257 switch (w.args_sizes_get(&count, &buf_size)) {
258 w.ESUCCESS => {},258 .SUCCESS => {},
259 else => |err| return os.unexpectedErrno(err),259 else => |err| return os.unexpectedErrno(err),
260 }260 }
261261
...@@ -265,7 +265,7 @@ pub const ArgIteratorWasi = struct {...@@ -265,7 +265,7 @@ pub const ArgIteratorWasi = struct {
265 var argv_buf = try allocator.alloc(u8, buf_size);265 var argv_buf = try allocator.alloc(u8, buf_size);
266266
267 switch (w.args_get(argv.ptr, argv_buf.ptr)) {267 switch (w.args_get(argv.ptr, argv_buf.ptr)) {
268 w.ESUCCESS => {},268 .SUCCESS => {},
269 else => |err| return os.unexpectedErrno(err),269 else => |err| return os.unexpectedErrno(err),
270 }270 }
271271
lib/std/special/compiler_rt/emutls.zig+3-3
...@@ -201,7 +201,7 @@ const current_thread_storage = struct {...@@ -201,7 +201,7 @@ const current_thread_storage = struct {
201201
202 /// Initialize pthread_key_t.202 /// Initialize pthread_key_t.
203 fn init() void {203 fn init() void {
204 if (std.c.pthread_key_create(&current_thread_storage.key, current_thread_storage.deinit) != 0) {204 if (std.c.pthread_key_create(&current_thread_storage.key, current_thread_storage.deinit) != .SUCCESS) {
205 abort();205 abort();
206 }206 }
207 }207 }
...@@ -248,14 +248,14 @@ const emutls_control = extern struct {...@@ -248,14 +248,14 @@ const emutls_control = extern struct {
248248
249 /// Simple wrapper for global lock.249 /// Simple wrapper for global lock.
250 fn lock() void {250 fn lock() void {
251 if (std.c.pthread_mutex_lock(&emutls_control.mutex) != 0) {251 if (std.c.pthread_mutex_lock(&emutls_control.mutex) != .SUCCESS) {
252 abort();252 abort();
253 }253 }
254 }254 }
255255
256 /// Simple wrapper for global unlock.256 /// Simple wrapper for global unlock.
257 fn unlock() void {257 fn unlock() void {
258 if (std.c.pthread_mutex_unlock(&emutls_control.mutex) != 0) {258 if (std.c.pthread_mutex_unlock(&emutls_control.mutex) != .SUCCESS) {
259 abort();259 abort();
260 }260 }
261 }261 }
lib/std/time.zig+1-1
...@@ -92,7 +92,7 @@ pub fn nanoTimestamp() i128 {...@@ -92,7 +92,7 @@ pub fn nanoTimestamp() i128 {
92 if (builtin.os.tag == .wasi and !builtin.link_libc) {92 if (builtin.os.tag == .wasi and !builtin.link_libc) {
93 var ns: os.wasi.timestamp_t = undefined;93 var ns: os.wasi.timestamp_t = undefined;
94 const err = os.wasi.clock_time_get(os.wasi.CLOCK_REALTIME, 1, &ns);94 const err = os.wasi.clock_time_get(os.wasi.CLOCK_REALTIME, 1, &ns);
95 assert(err == os.wasi.ESUCCESS);95 assert(err == .SUCCESS);
96 return ns;96 return ns;
97 }97 }
98 var ts: os.timespec = undefined;98 var ts: os.timespec = undefined;
lib/std/x/os/socket_posix.zig+49-49
...@@ -82,32 +82,32 @@ pub fn Mixin(comptime Socket: type) type {...@@ -82,32 +82,32 @@ pub fn Mixin(comptime Socket: type) type {
82 while (true) {82 while (true) {
83 const rc = os.system.sendmsg(self.fd, &msg, @intCast(c_int, flags));83 const rc = os.system.sendmsg(self.fd, &msg, @intCast(c_int, flags));
84 return switch (os.errno(rc)) {84 return switch (os.errno(rc)) {
85 0 => return @intCast(usize, rc),85 .SUCCESS => return @intCast(usize, rc),
86 os.EACCES => error.AccessDenied,86 .ACCES => error.AccessDenied,
87 os.EAGAIN => error.WouldBlock,87 .AGAIN => error.WouldBlock,
88 os.EALREADY => error.FastOpenAlreadyInProgress,88 .ALREADY => error.FastOpenAlreadyInProgress,
89 os.EBADF => unreachable, // always a race condition89 .BADF => unreachable, // always a race condition
90 os.ECONNRESET => error.ConnectionResetByPeer,90 .CONNRESET => error.ConnectionResetByPeer,
91 os.EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.91 .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
92 os.EFAULT => unreachable, // An invalid user space address was specified for an argument.92 .FAULT => unreachable, // An invalid user space address was specified for an argument.
93 os.EINTR => continue,93 .INTR => continue,
94 os.EINVAL => unreachable, // Invalid argument passed.94 .INVAL => unreachable, // Invalid argument passed.
95 os.EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified95 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
96 os.EMSGSIZE => error.MessageTooBig,96 .MSGSIZE => error.MessageTooBig,
97 os.ENOBUFS => error.SystemResources,97 .NOBUFS => error.SystemResources,
98 os.ENOMEM => error.SystemResources,98 .NOMEM => error.SystemResources,
99 os.ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.99 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
100 os.EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.100 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
101 os.EPIPE => error.BrokenPipe,101 .PIPE => error.BrokenPipe,
102 os.EAFNOSUPPORT => error.AddressFamilyNotSupported,102 .AFNOSUPPORT => error.AddressFamilyNotSupported,
103 os.ELOOP => error.SymLinkLoop,103 .LOOP => error.SymLinkLoop,
104 os.ENAMETOOLONG => error.NameTooLong,104 .NAMETOOLONG => error.NameTooLong,
105 os.ENOENT => error.FileNotFound,105 .NOENT => error.FileNotFound,
106 os.ENOTDIR => error.NotDir,106 .NOTDIR => error.NotDir,
107 os.EHOSTUNREACH => error.NetworkUnreachable,107 .HOSTUNREACH => error.NetworkUnreachable,
108 os.ENETUNREACH => error.NetworkUnreachable,108 .NETUNREACH => error.NetworkUnreachable,
109 os.ENOTCONN => error.SocketNotConnected,109 .NOTCONN => error.SocketNotConnected,
110 os.ENETDOWN => error.NetworkSubsystemFailed,110 .NETDOWN => error.NetworkSubsystemFailed,
111 else => |err| os.unexpectedErrno(err),111 else => |err| os.unexpectedErrno(err),
112 };112 };
113 }113 }
...@@ -120,17 +120,17 @@ pub fn Mixin(comptime Socket: type) type {...@@ -120,17 +120,17 @@ pub fn Mixin(comptime Socket: type) type {
120 while (true) {120 while (true) {
121 const rc = os.system.recvmsg(self.fd, msg, @intCast(c_int, flags));121 const rc = os.system.recvmsg(self.fd, msg, @intCast(c_int, flags));
122 return switch (os.errno(rc)) {122 return switch (os.errno(rc)) {
123 0 => @intCast(usize, rc),123 .SUCCESS => @intCast(usize, rc),
124 os.EBADF => unreachable, // always a race condition124 .BADF => unreachable, // always a race condition
125 os.EFAULT => unreachable,125 .FAULT => unreachable,
126 os.EINVAL => unreachable,126 .INVAL => unreachable,
127 os.ENOTCONN => unreachable,127 .NOTCONN => unreachable,
128 os.ENOTSOCK => unreachable,128 .NOTSOCK => unreachable,
129 os.EINTR => continue,129 .INTR => continue,
130 os.EAGAIN => error.WouldBlock,130 .AGAIN => error.WouldBlock,
131 os.ENOMEM => error.SystemResources,131 .NOMEM => error.SystemResources,
132 os.ECONNREFUSED => error.ConnectionRefused,132 .CONNREFUSED => error.ConnectionRefused,
133 os.ECONNRESET => error.ConnectionResetByPeer,133 .CONNRESET => error.ConnectionResetByPeer,
134 else => |err| os.unexpectedErrno(err),134 else => |err| os.unexpectedErrno(err),
135 };135 };
136 }136 }
...@@ -164,12 +164,12 @@ pub fn Mixin(comptime Socket: type) type {...@@ -164,12 +164,12 @@ pub fn Mixin(comptime Socket: type) type {
164164
165 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&value), &value_len);165 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&value), &value_len);
166 return switch (os.errno(rc)) {166 return switch (os.errno(rc)) {
167 0 => value,167 .SUCCESS => value,
168 os.EBADF => error.BadFileDescriptor,168 .BADF => error.BadFileDescriptor,
169 os.EFAULT => error.InvalidAddressSpace,169 .FAULT => error.InvalidAddressSpace,
170 os.EINVAL => error.InvalidSocketOption,170 .INVAL => error.InvalidSocketOption,
171 os.ENOPROTOOPT => error.UnknownSocketOption,171 .NOPROTOOPT => error.UnknownSocketOption,
172 os.ENOTSOCK => error.NotASocket,172 .NOTSOCK => error.NotASocket,
173 else => |err| os.unexpectedErrno(err),173 else => |err| os.unexpectedErrno(err),
174 };174 };
175 }175 }
...@@ -181,12 +181,12 @@ pub fn Mixin(comptime Socket: type) type {...@@ -181,12 +181,12 @@ pub fn Mixin(comptime Socket: type) type {
181181
182 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&value), &value_len);182 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&value), &value_len);
183 return switch (os.errno(rc)) {183 return switch (os.errno(rc)) {
184 0 => value,184 .SUCCESS => value,
185 os.EBADF => error.BadFileDescriptor,185 .BADF => error.BadFileDescriptor,
186 os.EFAULT => error.InvalidAddressSpace,186 .FAULT => error.InvalidAddressSpace,
187 os.EINVAL => error.InvalidSocketOption,187 .INVAL => error.InvalidSocketOption,
188 os.ENOPROTOOPT => error.UnknownSocketOption,188 .NOPROTOOPT => error.UnknownSocketOption,
189 os.ENOTSOCK => error.NotASocket,189 .NOTSOCK => error.NotASocket,
190 else => |err| os.unexpectedErrno(err),190 else => |err| os.unexpectedErrno(err),
191 };191 };
192 }192 }