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
426426 "${CMAKE_SOURCE_DIR}/lib/std/os.zig"
427427 "${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"
428428 "${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"
430430 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"
431431 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"
432432 "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"
lib/std/Thread.zig+85-81
......@@ -9,9 +9,10 @@
99//! both evented I/O and async I/O, see the respective names in the top level std namespace.
1010
1111const std = @import("std.zig");
12const builtin = @import("builtin");
1213const os = std.os;
1314const assert = std.debug.assert;
14const target = std.Target.current;
15const target = builtin.target;
1516const Atomic = std.atomic.Atomic;
1617
1718pub const AutoResetEvent = @import("Thread/AutoResetEvent.zig");
......@@ -24,7 +25,8 @@ pub const Condition = @import("Thread/Condition.zig");
2425
2526pub 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
2931const Thread = @This();
3032const Impl = if (target.os.tag == .windows)
......@@ -38,7 +40,7 @@ else
3840
3941impl: Impl,
4042
41pub const max_name_len = switch (std.Target.current.os.tag) {
43pub const max_name_len = switch (target.os.tag) {
4244 .linux => 15,
4345 .windows => 31,
4446 .macos, .ios, .watchos, .tvos => 63,
......@@ -64,20 +66,21 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
6466 break :blk name_buf[0..name.len :0];
6567 };
6668
67 switch (std.Target.current.os.tag) {
69 switch (target.os.tag) {
6870 .linux => if (use_pthreads) {
6971 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
70 return switch (err) {
71 0 => {},
72 os.ERANGE => unreachable,
73 else => return os.unexpectedErrno(err),
74 };
72 switch (err) {
73 .SUCCESS => return,
74 .RANGE => unreachable,
75 else => |e| return os.unexpectedErrno(e),
76 }
7577 } 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?
7679 const err = try os.prctl(.SET_NAME, .{@ptrToInt(name_with_terminator.ptr)});
77 return switch (err) {
78 0 => {},
79 else => return os.unexpectedErrno(err),
80 };
80 switch (@intToEnum(os.E, err)) {
81 .SUCCESS => return,
82 else => |e| return os.unexpectedErrno(e),
83 }
8184 } else {
8285 var buf: [32]u8 = undefined;
8386 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 {
8790
8891 try file.writer().writeAll(name);
8992 },
90 .windows => if (std.Target.current.os.isAtLeast(.windows, .win10_rs1)) |res| {
93 .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| {
9194 // SetThreadDescription is only available since version 1607, which is 10.0.14393.795
9295 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
9396 if (!res) {
......@@ -110,24 +113,25 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
110113 if (self.getHandle() != std.c.pthread_self()) return error.Unsupported;
111114
112115 const err = std.c.pthread_setname_np(name_with_terminator.ptr);
113 return switch (err) {
114 0 => {},
115 else => return os.unexpectedErrno(err),
116 };
116 switch (err) {
117 .SUCCESS => return,
118 else => |e| return os.unexpectedErrno(e),
119 }
117120 },
118121 .netbsd => if (use_pthreads) {
119122 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null);
120 return switch (err) {
121 0 => {},
122 os.EINVAL => unreachable,
123 os.ESRCH => unreachable,
124 os.ENOMEM => unreachable,
125 else => return os.unexpectedErrno(err),
126 };
123 switch (err) {
124 .SUCCESS => return,
125 .INVAL => unreachable,
126 .SRCH => unreachable,
127 .NOMEM => unreachable,
128 else => |e| return os.unexpectedErrno(e),
129 }
127130 },
128131 .freebsd, .openbsd => if (use_pthreads) {
129132 // 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
132136 std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr);
133137 },
......@@ -151,20 +155,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
151155 buffer_ptr[max_name_len] = 0;
152156 var buffer = std.mem.span(buffer_ptr);
153157
154 switch (std.Target.current.os.tag) {
155 .linux => if (use_pthreads and comptime std.Target.current.abi.isGnu()) {
158 switch (target.os.tag) {
159 .linux => if (use_pthreads and is_gnu) {
156160 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
157 return switch (err) {
158 0 => std.mem.sliceTo(buffer, 0),
159 os.ERANGE => unreachable,
160 else => return os.unexpectedErrno(err),
161 };
161 switch (err) {
162 .SUCCESS => return std.mem.sliceTo(buffer, 0),
163 .RANGE => unreachable,
164 else => |e| return os.unexpectedErrno(e),
165 }
162166 } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) {
163167 const err = try os.prctl(.GET_NAME, .{@ptrToInt(buffer.ptr)});
164 return switch (err) {
165 0 => std.mem.sliceTo(buffer, 0),
166 else => return os.unexpectedErrno(err),
167 };
168 switch (@intToEnum(os.E, err)) {
169 .SUCCESS => return std.mem.sliceTo(buffer, 0),
170 else => |e| return os.unexpectedErrno(e),
171 }
168172 } else if (!use_pthreads) {
169173 var buf: [32]u8 = undefined;
170174 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
179183 // musl doesn't provide pthread_getname_np and there's no way to retrieve the thread id of an arbitrary thread.
180184 return error.Unsupported;
181185 },
182 .windows => if (std.Target.current.os.isAtLeast(.windows, .win10_rs1)) |res| {
186 .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| {
183187 // GetThreadDescription is only available since version 1607, which is 10.0.14393.795
184188 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
185189 if (!res) {
......@@ -198,20 +202,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
198202 },
199203 .macos, .ios, .watchos, .tvos => if (use_pthreads) {
200204 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
201 return switch (err) {
202 0 => std.mem.sliceTo(buffer, 0),
203 os.ESRCH => unreachable,
204 else => return os.unexpectedErrno(err),
205 };
205 switch (err) {
206 .SUCCESS => return std.mem.sliceTo(buffer, 0),
207 .SRCH => unreachable,
208 else => |e| return os.unexpectedErrno(e),
209 }
206210 },
207211 .netbsd => if (use_pthreads) {
208212 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
209 return switch (err) {
210 0 => std.mem.sliceTo(buffer, 0),
211 os.EINVAL => unreachable,
212 os.ESRCH => unreachable,
213 else => return os.unexpectedErrno(err),
214 };
213 switch (err) {
214 .SUCCESS => return std.mem.sliceTo(buffer, 0),
215 .INVAL => unreachable,
216 .SRCH => unreachable,
217 else => |e| return os.unexpectedErrno(e),
218 }
215219 },
216220 .freebsd, .openbsd => if (use_pthreads) {
217221 // Use pthread_get_name_np for FreeBSD because pthread_getname_np is FreeBSD 12.2+ only.
......@@ -288,7 +292,7 @@ pub const SpawnError = error{
288292/// The caller must eventually either call `join()` to wait for the thread to finish and free its resources
289293/// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`.
290294pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread {
291 if (std.builtin.single_threaded) {
295 if (builtin.single_threaded) {
292296 @compileError("Cannot spawn thread when building in single-threaded mode");
293297 }
294298
......@@ -611,13 +615,13 @@ const PosixThreadImpl = struct {
611615 errdefer allocator.destroy(args_ptr);
612616
613617 var attr: c.pthread_attr_t = undefined;
614 if (c.pthread_attr_init(&attr) != 0) return error.SystemResources;
615 defer assert(c.pthread_attr_destroy(&attr) == 0);
618 if (c.pthread_attr_init(&attr) != .SUCCESS) return error.SystemResources;
619 defer assert(c.pthread_attr_destroy(&attr) == .SUCCESS);
616620
617621 // Use the same set of parameters used by the libc-less impl.
618622 const stack_size = std.math.max(config.stack_size, 16 * 1024);
619 assert(c.pthread_attr_setstacksize(&attr, stack_size) == 0);
620 assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == 0);
623 assert(c.pthread_attr_setstacksize(&attr, stack_size) == .SUCCESS);
624 assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == .SUCCESS);
621625
622626 var handle: c.pthread_t = undefined;
623627 switch (c.pthread_create(
......@@ -626,10 +630,10 @@ const PosixThreadImpl = struct {
626630 Instance.entryFn,
627631 if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined,
628632 )) {
629 0 => return Impl{ .handle = handle },
630 os.EAGAIN => return error.SystemResources,
631 os.EPERM => unreachable,
632 os.EINVAL => unreachable,
633 .SUCCESS => return Impl{ .handle = handle },
634 .AGAIN => return error.SystemResources,
635 .PERM => unreachable,
636 .INVAL => unreachable,
633637 else => |err| return os.unexpectedErrno(err),
634638 }
635639 }
......@@ -640,19 +644,19 @@ const PosixThreadImpl = struct {
640644
641645 fn detach(self: Impl) void {
642646 switch (c.pthread_detach(self.handle)) {
643 0 => {},
644 os.EINVAL => unreachable, // thread handle is not joinable
645 os.ESRCH => unreachable, // thread handle is invalid
647 .SUCCESS => {},
648 .INVAL => unreachable, // thread handle is not joinable
649 .SRCH => unreachable, // thread handle is invalid
646650 else => unreachable,
647651 }
648652 }
649653
650654 fn join(self: Impl) void {
651655 switch (c.pthread_join(self.handle, null)) {
652 0 => {},
653 os.EINVAL => unreachable, // thread handle is not joinable (or another thread is already joining in)
654 os.ESRCH => unreachable, // thread handle is invalid
655 os.EDEADLK => unreachable, // two threads tried to join each other
656 .SUCCESS => {},
657 .INVAL => unreachable, // thread handle is not joinable (or another thread is already joining in)
658 .SRCH => unreachable, // thread handle is invalid
659 .DEADLK => unreachable, // two threads tried to join each other
656660 else => unreachable,
657661 }
658662 }
......@@ -937,13 +941,13 @@ const LinuxThreadImpl = struct {
937941 tls_ptr,
938942 &instance.thread.child_tid.value,
939943 ))) {
940 0 => return Impl{ .thread = &instance.thread },
941 os.EAGAIN => return error.ThreadQuotaExceeded,
942 os.EINVAL => unreachable,
943 os.ENOMEM => return error.SystemResources,
944 os.ENOSPC => unreachable,
945 os.EPERM => unreachable,
946 os.EUSERS => unreachable,
944 .SUCCESS => return Impl{ .thread = &instance.thread },
945 .AGAIN => return error.ThreadQuotaExceeded,
946 .INVAL => unreachable,
947 .NOMEM => return error.SystemResources,
948 .NOSPC => unreachable,
949 .PERM => unreachable,
950 .USERS => unreachable,
947951 else => |err| return os.unexpectedErrno(err),
948952 }
949953 }
......@@ -982,9 +986,9 @@ const LinuxThreadImpl = struct {
982986 tid,
983987 null,
984988 ))) {
985 0 => continue,
986 os.EINTR => continue,
987 os.EAGAIN => continue,
989 .SUCCESS => continue,
990 .INTR => continue,
991 .AGAIN => continue,
988992 else => unreachable,
989993 }
990994 }
......@@ -1011,7 +1015,7 @@ fn testThreadName(thread: *Thread) !void {
10111015}
10121016
10131017test "setName, getName" {
1014 if (std.builtin.single_threaded) return error.SkipZigTest;
1018 if (builtin.single_threaded) return error.SkipZigTest;
10151019
10161020 const Context = struct {
10171021 start_wait_event: ResetEvent = undefined,
......@@ -1029,7 +1033,7 @@ test "setName, getName" {
10291033 // Wait for the main thread to have set the thread field in the context.
10301034 ctx.start_wait_event.wait();
10311035
1032 switch (std.Target.current.os.tag) {
1036 switch (target.os.tag) {
10331037 .windows => testThreadName(&ctx.thread) catch |err| switch (err) {
10341038 error.Unsupported => return error.SkipZigTest,
10351039 else => return err,
......@@ -1054,7 +1058,7 @@ test "setName, getName" {
10541058 context.start_wait_event.set();
10551059 context.test_done_event.wait();
10561060
1057 switch (std.Target.current.os.tag) {
1061 switch (target.os.tag) {
10581062 .macos, .ios, .watchos, .tvos => {
10591063 const res = thread.setName("foobar");
10601064 try std.testing.expectError(error.Unsupported, res);
......@@ -1063,7 +1067,7 @@ test "setName, getName" {
10631067 error.Unsupported => return error.SkipZigTest,
10641068 else => return err,
10651069 },
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()) {
10671071 try thread.setName("foobar");
10681072
10691073 var name_buffer: [max_name_len:0]u8 = undefined;
......@@ -1096,7 +1100,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {
10961100}
10971101
10981102test "Thread.join" {
1099 if (std.builtin.single_threaded) return error.SkipZigTest;
1103 if (builtin.single_threaded) return error.SkipZigTest;
11001104
11011105 var value: usize = 0;
11021106 var event: ResetEvent = undefined;
......@@ -1110,7 +1114,7 @@ test "Thread.join" {
11101114}
11111115
11121116test "Thread.detach" {
1113 if (std.builtin.single_threaded) return error.SkipZigTest;
1117 if (builtin.single_threaded) return error.SkipZigTest;
11141118
11151119 var value: usize = 0;
11161120 var event: ResetEvent = undefined;
lib/std/Thread/Condition.zig+8-8
......@@ -81,17 +81,17 @@ pub const PthreadCondition = struct {
8181
8282 pub fn wait(cond: *PthreadCondition, mutex: *Mutex) void {
8383 const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.impl.pthread_mutex);
84 assert(rc == 0);
84 assert(rc == .SUCCESS);
8585 }
8686
8787 pub fn signal(cond: *PthreadCondition) void {
8888 const rc = std.c.pthread_cond_signal(&cond.cond);
89 assert(rc == 0);
89 assert(rc == .SUCCESS);
9090 }
9191
9292 pub fn broadcast(cond: *PthreadCondition) void {
9393 const rc = std.c.pthread_cond_broadcast(&cond.cond);
94 assert(rc == 0);
94 assert(rc == .SUCCESS);
9595 }
9696};
9797
......@@ -115,9 +115,9 @@ pub const AtomicCondition = struct {
115115 0,
116116 null,
117117 ))) {
118 0 => {},
119 std.os.EINTR => {},
120 std.os.EAGAIN => {},
118 .SUCCESS => {},
119 .INTR => {},
120 .AGAIN => {},
121121 else => unreachable,
122122 }
123123 },
......@@ -136,8 +136,8 @@ pub const AtomicCondition = struct {
136136 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
137137 1,
138138 ))) {
139 0 => {},
140 std.os.EFAULT => {},
139 .SUCCESS => {},
140 .FAULT => {},
141141 else => unreachable,
142142 }
143143 },
lib/std/Thread/Futex.zig+39-39
......@@ -152,12 +152,12 @@ const LinuxFutex = struct {
152152 @bitCast(i32, expect),
153153 ts_ptr,
154154 ))) {
155 0 => {}, // notified by `wake()`
156 std.os.EINTR => {}, // spurious wakeup
157 std.os.EAGAIN => {}, // ptr.* != expect
158 std.os.ETIMEDOUT => return error.TimedOut,
159 std.os.EINVAL => {}, // possibly timeout overflow
160 std.os.EFAULT => unreachable,
155 .SUCCESS => {}, // notified by `wake()`
156 .INTR => {}, // spurious wakeup
157 .AGAIN => {}, // ptr.* != expect
158 .TIMEDOUT => return error.TimedOut,
159 .INVAL => {}, // possibly timeout overflow
160 .FAULT => unreachable,
161161 else => unreachable,
162162 }
163163 }
......@@ -168,9 +168,9 @@ const LinuxFutex = struct {
168168 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
169169 std.math.cast(i32, num_waiters) catch std.math.maxInt(i32),
170170 ))) {
171 0 => {}, // successful wake up
172 std.os.EINVAL => {}, // invalid futex_wait() on ptr done elsewhere
173 std.os.EFAULT => {}, // pointer became invalid while doing the wake
171 .SUCCESS => {}, // successful wake up
172 .INVAL => {}, // invalid futex_wait() on ptr done elsewhere
173 .FAULT => {}, // pointer became invalid while doing the wake
174174 else => unreachable,
175175 }
176176 }
......@@ -215,13 +215,13 @@ const DarwinFutex = struct {
215215 };
216216
217217 if (status >= 0) return;
218 switch (-status) {
219 darwin.EINTR => {},
218 switch (@intToEnum(std.os.E, -status)) {
219 .INTR => {},
220220 // Address of the futex is paged out. This is unlikely, but possible in theory, and
221221 // pthread/libdispatch on darwin bother to handle it. In this case we'll return
222222 // without waiting, but the caller should retry anyway.
223 darwin.EFAULT => {},
224 darwin.ETIMEDOUT => if (!timeout_overflowed) return error.TimedOut,
223 .FAULT => {},
224 .TIMEDOUT => if (!timeout_overflowed) return error.TimedOut,
225225 else => unreachable,
226226 }
227227 }
......@@ -237,11 +237,11 @@ const DarwinFutex = struct {
237237 const status = darwin.__ulock_wake(flags, addr, 0);
238238
239239 if (status >= 0) return;
240 switch (-status) {
241 darwin.EINTR => continue, // spurious wake()
242 darwin.EFAULT => continue, // address of the lock was paged out
243 darwin.ENOENT => return, // nothing was woken up
244 darwin.EALREADY => unreachable, // only for ULF_WAKE_THREAD
240 switch (@intToEnum(std.os.E, -status)) {
241 .INTR => continue, // spurious wake()
242 .FAULT => continue, // address of the lock was paged out
243 .NOENT => return, // nothing was woken up
244 .ALREADY => unreachable, // only for ULF_WAKE_THREAD
245245 else => unreachable,
246246 }
247247 }
......@@ -255,8 +255,8 @@ const PosixFutex = struct {
255255 var waiter: List.Node = undefined;
256256
257257 {
258 assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);
259 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);
258 assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
259 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
260260
261261 if (ptr.load(.SeqCst) != expect) {
262262 return;
......@@ -272,8 +272,8 @@ const PosixFutex = struct {
272272 waiter.data.wait(null) catch unreachable;
273273 };
274274
275 assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);
276 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);
275 assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
276 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
277277
278278 if (waiter.data.address == address) {
279279 timed_out = true;
......@@ -297,8 +297,8 @@ const PosixFutex = struct {
297297 waiter.data.notify();
298298 };
299299
300 assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0);
301 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0);
300 assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
301 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
302302
303303 var waiters = bucket.list.first;
304304 while (waiters) |waiter| {
......@@ -340,16 +340,13 @@ const PosixFutex = struct {
340340 };
341341
342342 fn deinit(self: *Self) void {
343 const rc = std.c.pthread_cond_destroy(&self.cond);
344 assert(rc == 0 or rc == std.os.EINVAL);
345
346 const rm = std.c.pthread_mutex_destroy(&self.mutex);
347 assert(rm == 0 or rm == std.os.EINVAL);
343 _ = std.c.pthread_cond_destroy(&self.cond);
344 _ = std.c.pthread_mutex_destroy(&self.mutex);
348345 }
349346
350347 fn wait(self: *Self, timeout: ?u64) error{TimedOut}!void {
351 assert(std.c.pthread_mutex_lock(&self.mutex) == 0);
352 defer assert(std.c.pthread_mutex_unlock(&self.mutex) == 0);
348 assert(std.c.pthread_mutex_lock(&self.mutex) == .SUCCESS);
349 defer assert(std.c.pthread_mutex_unlock(&self.mutex) == .SUCCESS);
353350
354351 switch (self.state) {
355352 .empty => self.state = .waiting,
......@@ -378,28 +375,31 @@ const PosixFutex = struct {
378375 }
379376
380377 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);
382379 continue;
383380 };
384381
385382 const rc = std.c.pthread_cond_timedwait(&self.cond, &self.mutex, ts_ref);
386 assert(rc == 0 or rc == std.os.ETIMEDOUT);
387 if (rc == std.os.ETIMEDOUT) {
388 self.state = .empty;
389 return error.TimedOut;
383 switch (rc) {
384 .SUCCESS => {},
385 .TIMEDOUT => {
386 self.state = .empty;
387 return error.TimedOut;
388 },
389 else => unreachable,
390390 }
391391 }
392392 }
393393
394394 fn notify(self: *Self) void {
395 assert(std.c.pthread_mutex_lock(&self.mutex) == 0);
396 defer assert(std.c.pthread_mutex_unlock(&self.mutex) == 0);
395 assert(std.c.pthread_mutex_lock(&self.mutex) == .SUCCESS);
396 defer assert(std.c.pthread_mutex_unlock(&self.mutex) == .SUCCESS);
397397
398398 switch (self.state) {
399399 .empty => self.state = .notified,
400400 .waiting => {
401401 self.state = .notified;
402 assert(std.c.pthread_cond_signal(&self.cond) == 0);
402 assert(std.c.pthread_cond_signal(&self.cond) == .SUCCESS);
403403 },
404404 .notified => unreachable,
405405 }
lib/std/Thread/Mutex.zig+16-16
......@@ -143,9 +143,9 @@ pub const AtomicMutex = struct {
143143 @enumToInt(new_state),
144144 null,
145145 ))) {
146 0 => {},
147 std.os.EINTR => {},
148 std.os.EAGAIN => {},
146 .SUCCESS => {},
147 .INTR => {},
148 .AGAIN => {},
149149 else => unreachable,
150150 }
151151 },
......@@ -164,8 +164,8 @@ pub const AtomicMutex = struct {
164164 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
165165 1,
166166 ))) {
167 0 => {},
168 std.os.EFAULT => {},
167 .SUCCESS => {},
168 .FAULT => unreachable, // invalid pointer passed to futex_wake
169169 else => unreachable,
170170 }
171171 },
......@@ -182,10 +182,10 @@ pub const PthreadMutex = struct {
182182
183183 pub fn release(held: Held) void {
184184 switch (std.c.pthread_mutex_unlock(&held.mutex.pthread_mutex)) {
185 0 => return,
186 std.c.EINVAL => unreachable,
187 std.c.EAGAIN => unreachable,
188 std.c.EPERM => unreachable,
185 .SUCCESS => return,
186 .INVAL => unreachable,
187 .AGAIN => unreachable,
188 .PERM => unreachable,
189189 else => unreachable,
190190 }
191191 }
......@@ -195,7 +195,7 @@ pub const PthreadMutex = struct {
195195 /// the mutex is unavailable. Otherwise returns Held. Call
196196 /// release on Held.
197197 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) {
199199 return Held{ .mutex = m };
200200 } else {
201201 return null;
......@@ -206,12 +206,12 @@ pub const PthreadMutex = struct {
206206 /// held by the calling thread.
207207 pub fn acquire(m: *PthreadMutex) Held {
208208 switch (std.c.pthread_mutex_lock(&m.pthread_mutex)) {
209 0 => return Held{ .mutex = m },
210 std.c.EINVAL => unreachable,
211 std.c.EBUSY => unreachable,
212 std.c.EAGAIN => unreachable,
213 std.c.EDEADLK => unreachable,
214 std.c.EPERM => unreachable,
209 .SUCCESS => return Held{ .mutex = m },
210 .INVAL => unreachable,
211 .BUSY => unreachable,
212 .AGAIN => unreachable,
213 .DEADLK => unreachable,
214 .PERM => unreachable,
215215 else => unreachable,
216216 }
217217 }
lib/std/Thread/ResetEvent.zig+12-12
......@@ -130,7 +130,7 @@ pub const PosixEvent = struct {
130130
131131 pub fn init(ev: *PosixEvent) !void {
132132 switch (c.getErrno(c.sem_init(&ev.sem, 0, 0))) {
133 0 => return,
133 .SUCCESS => return,
134134 else => return error.SystemResources,
135135 }
136136 }
......@@ -147,9 +147,9 @@ pub const PosixEvent = struct {
147147 pub fn wait(ev: *PosixEvent) void {
148148 while (true) {
149149 switch (c.getErrno(c.sem_wait(&ev.sem))) {
150 0 => return,
151 c.EINTR => continue,
152 c.EINVAL => unreachable,
150 .SUCCESS => return,
151 .INTR => continue,
152 .INVAL => unreachable,
153153 else => unreachable,
154154 }
155155 }
......@@ -165,10 +165,10 @@ pub const PosixEvent = struct {
165165 ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.ns_per_s));
166166 while (true) {
167167 switch (c.getErrno(c.sem_timedwait(&ev.sem, &ts))) {
168 0 => return .event_set,
169 c.EINTR => continue,
170 c.EINVAL => unreachable,
171 c.ETIMEDOUT => return .timed_out,
168 .SUCCESS => return .event_set,
169 .INTR => continue,
170 .INVAL => unreachable,
171 .TIMEDOUT => return .timed_out,
172172 else => unreachable,
173173 }
174174 }
......@@ -177,10 +177,10 @@ pub const PosixEvent = struct {
177177 pub fn reset(ev: *PosixEvent) void {
178178 while (true) {
179179 switch (c.getErrno(c.sem_trywait(&ev.sem))) {
180 0 => continue, // Need to make it go to zero.
181 c.EINTR => continue,
182 c.EINVAL => unreachable,
183 c.EAGAIN => return, // The semaphore currently has the value zero.
180 .SUCCESS => continue, // Need to make it go to zero.
181 .INTR => continue,
182 .INVAL => unreachable,
183 .AGAIN => return, // The semaphore currently has the value zero.
184184 else => unreachable,
185185 }
186186 }
lib/std/Thread/RwLock.zig+11-13
......@@ -13,7 +13,7 @@ impl: Impl,
1313
1414const RwLock = @This();
1515const std = @import("../std.zig");
16const builtin = std.builtin;
16const builtin = @import("builtin");
1717const assert = std.debug.assert;
1818const Mutex = std.Thread.Mutex;
1919const Semaphore = std.Semaphore;
......@@ -165,43 +165,41 @@ pub const PthreadRwLock = struct {
165165 }
166166
167167 pub fn deinit(rwl: *PthreadRwLock) void {
168 const safe_rc = switch (std.builtin.os.tag) {
169 .dragonfly, .netbsd => std.os.EAGAIN,
170 else => 0,
168 const safe_rc: std.os.E = switch (builtin.os.tag) {
169 .dragonfly, .netbsd => .AGAIN,
170 else => .SUCCESS,
171171 };
172
173172 const rc = std.c.pthread_rwlock_destroy(&rwl.rwlock);
174 assert(rc == 0 or rc == safe_rc);
175
173 assert(rc == .SUCCESS or rc == safe_rc);
176174 rwl.* = undefined;
177175 }
178176
179177 pub fn tryLock(rwl: *PthreadRwLock) bool {
180 return pthread_rwlock_trywrlock(&rwl.rwlock) == 0;
178 return pthread_rwlock_trywrlock(&rwl.rwlock) == .SUCCESS;
181179 }
182180
183181 pub fn lock(rwl: *PthreadRwLock) void {
184182 const rc = pthread_rwlock_wrlock(&rwl.rwlock);
185 assert(rc == 0);
183 assert(rc == .SUCCESS);
186184 }
187185
188186 pub fn unlock(rwl: *PthreadRwLock) void {
189187 const rc = pthread_rwlock_unlock(&rwl.rwlock);
190 assert(rc == 0);
188 assert(rc == .SUCCESS);
191189 }
192190
193191 pub fn tryLockShared(rwl: *PthreadRwLock) bool {
194 return pthread_rwlock_tryrdlock(&rwl.rwlock) == 0;
192 return pthread_rwlock_tryrdlock(&rwl.rwlock) == .SUCCESS;
195193 }
196194
197195 pub fn lockShared(rwl: *PthreadRwLock) void {
198196 const rc = pthread_rwlock_rdlock(&rwl.rwlock);
199 assert(rc == 0);
197 assert(rc == .SUCCESS);
200198 }
201199
202200 pub fn unlockShared(rwl: *PthreadRwLock) void {
203201 const rc = pthread_rwlock_unlock(&rwl.rwlock);
204 assert(rc == 0);
202 assert(rc == .SUCCESS);
205203 }
206204};
207205
lib/std/Thread/StaticResetEvent.zig+5-5
......@@ -201,7 +201,7 @@ pub const AtomicEvent = struct {
201201 const waiting = std.math.maxInt(i32); // wake_count
202202 const ptr = @ptrCast(*const i32, waiters);
203203 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);
205205 }
206206
207207 fn wait(waiters: *u32, timeout: ?u64) !void {
......@@ -221,10 +221,10 @@ pub const AtomicEvent = struct {
221221 const ptr = @ptrCast(*const i32, waiters);
222222 const rc = linux.futex_wait(ptr, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, expected, ts_ptr);
223223 switch (linux.getErrno(rc)) {
224 0 => continue,
225 os.ETIMEDOUT => return error.TimedOut,
226 os.EINTR => continue,
227 os.EAGAIN => return,
224 .SUCCESS => continue,
225 .TIMEDOUT => return error.TimedOut,
226 .INTR => continue,
227 .AGAIN => return,
228228 else => unreachable,
229229 }
230230 }
lib/std/c.zig+29-29
......@@ -35,11 +35,11 @@ pub usingnamespace switch (std.Target.current.os.tag) {
3535 else => struct {},
3636};
3737
38pub fn getErrno(rc: anytype) c_int {
38pub fn getErrno(rc: anytype) E {
3939 if (rc == -1) {
40 return _errno().*;
40 return @intToEnum(E, _errno().*);
4141 } else {
42 return 0;
42 return .SUCCESS;
4343 }
4444}
4545
......@@ -270,22 +270,22 @@ pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
270270pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
271271pub 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;
274pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
275pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
276pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) c_int;
277pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;
278pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) 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) E;
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) E;
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) E;
279279pub extern "c" fn pthread_self() pthread_t;
280pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
281pub extern "c" fn pthread_detach(thread: pthread_t) 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) E;
282282pub extern "c" fn pthread_atfork(
283283 prepare: ?fn () callconv(.C) void,
284284 parent: ?fn () callconv(.C) void,
285285 child: ?fn () callconv(.C) void,
286286) c_int;
287pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) c_int;
288pub extern "c" fn pthread_key_delete(key: pthread_key_t) 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) E;
289289pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*c_void;
290290pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*c_void) c_int;
291291pub 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(
339339) c_int;
340340
341341pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
342pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;
343pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;
344pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c_int;
345pub extern "c" fn pthread_mutex_destroy(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) E;
344pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) E;
345pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) E;
346346
347347pub 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;
349pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) c_int;
350pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c_int;
351pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int;
352pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c_int;
353
354pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) c_int;
355pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
356pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
357pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
358pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) c_int;
359pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) 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) E;
350pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
351pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
352pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;
353
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) E;
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) E;
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) E;
360360
361361pub const pthread_t = *opaque {};
362362pub const FILE = opaque {};
lib/std/c/darwin.zig+2-2
......@@ -193,8 +193,8 @@ pub const pthread_attr_t = extern struct {
193193
194194const pthread_t = std.c.pthread_t;
195195pub 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;
197pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) 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) E;
198198
199199pub 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) {
186186};
187187const __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;
190pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) 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) E;
191191
192192pub const RTLD_LAZY = 1;
193193pub const RTLD_NOW = 2;
lib/std/c/netbsd.zig+2-2
......@@ -95,5 +95,5 @@ pub const pthread_attr_t = extern struct {
9595
9696pub 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;
99pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) 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) E;
lib/std/fs.zig+28-28
......@@ -339,10 +339,10 @@ pub const Dir = struct {
339339 if (rc == 0) return null;
340340 if (rc < 0) {
341341 switch (os.errno(rc)) {
342 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
343 os.EFAULT => unreachable,
344 os.ENOTDIR => unreachable,
345 os.EINVAL => unreachable,
342 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
343 .FAULT => unreachable,
344 .NOTDIR => unreachable,
345 .INVAL => unreachable,
346346 else => |err| return os.unexpectedErrno(err),
347347 }
348348 }
......@@ -385,11 +385,11 @@ pub const Dir = struct {
385385 else
386386 os.system.getdents(self.dir.fd, &self.buf, self.buf.len);
387387 switch (os.errno(rc)) {
388 0 => {},
389 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
390 os.EFAULT => unreachable,
391 os.ENOTDIR => unreachable,
392 os.EINVAL => unreachable,
388 .SUCCESS => {},
389 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
390 .FAULT => unreachable,
391 .NOTDIR => unreachable,
392 .INVAL => unreachable,
393393 else => |err| return os.unexpectedErrno(err),
394394 }
395395 if (rc == 0) return null;
......@@ -457,10 +457,10 @@ pub const Dir = struct {
457457 if (rc == 0) return null;
458458 if (rc < 0) {
459459 switch (os.errno(rc)) {
460 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
461 os.EFAULT => unreachable,
462 os.ENOTDIR => unreachable,
463 os.EINVAL => unreachable,
460 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
461 .FAULT => unreachable,
462 .NOTDIR => unreachable,
463 .INVAL => unreachable,
464464 else => |err| return os.unexpectedErrno(err),
465465 }
466466 }
......@@ -522,11 +522,11 @@ pub const Dir = struct {
522522 if (self.index >= self.end_index) {
523523 const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
524524 switch (os.linux.getErrno(rc)) {
525 0 => {},
526 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
527 os.EFAULT => unreachable,
528 os.ENOTDIR => unreachable,
529 os.EINVAL => unreachable,
525 .SUCCESS => {},
526 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
527 .FAULT => unreachable,
528 .NOTDIR => unreachable,
529 .INVAL => unreachable,
530530 else => |err| return os.unexpectedErrno(err),
531531 }
532532 if (rc == 0) return null;
......@@ -655,12 +655,12 @@ pub const Dir = struct {
655655 if (self.index >= self.end_index) {
656656 var bufused: usize = undefined;
657657 switch (w.fd_readdir(self.dir.fd, &self.buf, self.buf.len, self.cookie, &bufused)) {
658 w.ESUCCESS => {},
659 w.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
660 w.EFAULT => unreachable,
661 w.ENOTDIR => unreachable,
662 w.EINVAL => unreachable,
663 w.ENOTCAPABLE => return error.AccessDenied,
658 .SUCCESS => {},
659 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
660 .FAULT => unreachable,
661 .NOTDIR => unreachable,
662 .INVAL => unreachable,
663 .NOTCAPABLE => return error.AccessDenied,
664664 else => |err| return os.unexpectedErrno(err),
665665 }
666666 if (bufused == 0) return null;
......@@ -2557,12 +2557,12 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {
25572557 if (comptime std.Target.current.isDarwin()) {
25582558 const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);
25592559 switch (os.errno(rc)) {
2560 0 => return,
2561 os.EINVAL => unreachable,
2562 os.ENOMEM => return error.SystemResources,
2560 .SUCCESS => return,
2561 .INVAL => unreachable,
2562 .NOMEM => return error.SystemResources,
25632563 // The source file is not a directory, symbolic link, or regular file.
25642564 // Try with the fallback path before giving up.
2565 os.ENOTSUP => {},
2565 .OPNOTSUPP => {},
25662566 else => |err| return os.unexpectedErrno(err),
25672567 }
25682568 }
lib/std/fs/wasi.zig+4-4
......@@ -121,13 +121,13 @@ pub const PreopenList = struct {
121121 while (true) {
122122 var buf: prestat_t = undefined;
123123 switch (fd_prestat_get(fd, &buf)) {
124 ESUCCESS => {},
125 ENOTSUP => {
124 .SUCCESS => {},
125 .OPNOTSUPP => {
126126 // not a preopen, so keep going
127127 fd = try math.add(fd_t, fd, 1);
128128 continue;
129129 },
130 EBADF => {
130 .BADF => {
131131 // OK, no more fds available
132132 break;
133133 },
......@@ -137,7 +137,7 @@ pub const PreopenList = struct {
137137 const path_buf = try self.buffer.allocator.alloc(u8, preopen_len);
138138 mem.set(u8, path_buf, 0);
139139 switch (fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) {
140 ESUCCESS => {},
140 .SUCCESS => {},
141141 else => |err| return os.unexpectedErrno(err),
142142 }
143143 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 {
1717fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {
1818 const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);
1919 if (amt_written >= 0) return amt_written;
20 switch (std.c._errno().*) {
21 0 => unreachable,
22 os.EINVAL => unreachable,
23 os.EFAULT => unreachable,
24 os.EAGAIN => unreachable, // this is a blocking API
25 os.EBADF => unreachable, // always a race condition
26 os.EDESTADDRREQ => unreachable, // connect was never called
27 os.EDQUOT => return error.DiskQuota,
28 os.EFBIG => return error.FileTooBig,
29 os.EIO => return error.InputOutput,
30 os.ENOSPC => return error.NoSpaceLeft,
31 os.EPERM => return error.AccessDenied,
32 os.EPIPE => return error.BrokenPipe,
20 switch (@intToEnum(os.E, std.c._errno().*)) {
21 .SUCCESS => unreachable,
22 .INVAL => unreachable,
23 .FAULT => unreachable,
24 .AGAIN => unreachable, // this is a blocking API
25 .BADF => unreachable, // always a race condition
26 .DESTADDRREQ => unreachable, // connect was never called
27 .DQUOT => return error.DiskQuota,
28 .FBIG => return error.FileTooBig,
29 .IO => return error.InputOutput,
30 .NOSPC => return error.NoSpaceLeft,
31 .PERM => return error.AccessDenied,
32 .PIPE => return error.BrokenPipe,
3333 else => |err| return os.unexpectedErrno(err),
3434 }
3535}
lib/std/os.zig+1304-1304
......@@ -116,13 +116,13 @@ pub fn close(fd: fd_t) void {
116116 if (comptime std.Target.current.isDarwin()) {
117117 // This avoids the EINTR problem.
118118 switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) {
119 EBADF => unreachable, // Always a race condition.
119 .BADF => unreachable, // Always a race condition.
120120 else => return,
121121 }
122122 }
123123 switch (errno(system.close(fd))) {
124 EBADF => unreachable, // Always a race condition.
125 EINTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425
124 .BADF => unreachable, // Always a race condition.
125 .INTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425
126126 else => return,
127127 }
128128}
......@@ -159,11 +159,11 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
159159 };
160160
161161 switch (res.err) {
162 0 => buf = buf[res.num_read..],
163 EINVAL => unreachable,
164 EFAULT => unreachable,
165 EINTR => continue,
166 ENOSYS => return getRandomBytesDevURandom(buf),
162 .SUCCESS => buf = buf[res.num_read..],
163 .INVAL => unreachable,
164 .FAULT => unreachable,
165 .INTR => continue,
166 .NOSYS => return getRandomBytesDevURandom(buf),
167167 else => return unexpectedErrno(res.err),
168168 }
169169 }
......@@ -175,7 +175,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
175175 return;
176176 },
177177 .wasi => switch (wasi.random_get(buffer.ptr, buffer.len)) {
178 0 => return,
178 .SUCCESS => return,
179179 else => |err| return unexpectedErrno(err),
180180 },
181181 else => return getRandomBytesDevURandom(buffer),
......@@ -238,7 +238,7 @@ pub const RaiseError = UnexpectedError;
238238pub fn raise(sig: u8) RaiseError!void {
239239 if (builtin.link_libc) {
240240 switch (errno(system.raise(sig))) {
241 0 => return,
241 .SUCCESS => return,
242242 else => |err| return unexpectedErrno(err),
243243 }
244244 }
......@@ -255,7 +255,7 @@ pub fn raise(sig: u8) RaiseError!void {
255255 _ = linux.sigprocmask(SIG_SETMASK, &set, null);
256256
257257 switch (errno(rc)) {
258 0 => return,
258 .SUCCESS => return,
259259 else => |err| return unexpectedErrno(err),
260260 }
261261 }
......@@ -267,10 +267,10 @@ pub const KillError = error{PermissionDenied} || UnexpectedError;
267267
268268pub fn kill(pid: pid_t, sig: u8) KillError!void {
269269 switch (errno(system.kill(pid, sig))) {
270 0 => return,
271 EINVAL => unreachable, // invalid signal
272 EPERM => return error.PermissionDenied,
273 ESRCH => unreachable, // always a race condition
270 .SUCCESS => return,
271 .INVAL => unreachable, // invalid signal
272 .PERM => return error.PermissionDenied,
273 .SRCH => unreachable, // always a race condition
274274 else => |err| return unexpectedErrno(err),
275275 }
276276}
......@@ -342,19 +342,19 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
342342
343343 var nread: usize = undefined;
344344 switch (wasi.fd_read(fd, &iovs, iovs.len, &nread)) {
345 wasi.ESUCCESS => return nread,
346 wasi.EINTR => unreachable,
347 wasi.EINVAL => unreachable,
348 wasi.EFAULT => unreachable,
349 wasi.EAGAIN => unreachable,
350 wasi.EBADF => return error.NotOpenForReading, // Can be a race condition.
351 wasi.EIO => return error.InputOutput,
352 wasi.EISDIR => return error.IsDir,
353 wasi.ENOBUFS => return error.SystemResources,
354 wasi.ENOMEM => return error.SystemResources,
355 wasi.ECONNRESET => return error.ConnectionResetByPeer,
356 wasi.ETIMEDOUT => return error.ConnectionTimedOut,
357 wasi.ENOTCAPABLE => return error.AccessDenied,
345 .SUCCESS => return nread,
346 .INTR => unreachable,
347 .INVAL => unreachable,
348 .FAULT => unreachable,
349 .AGAIN => unreachable,
350 .BADF => return error.NotOpenForReading, // Can be a race condition.
351 .IO => return error.InputOutput,
352 .ISDIR => return error.IsDir,
353 .NOBUFS => return error.SystemResources,
354 .NOMEM => return error.SystemResources,
355 .CONNRESET => return error.ConnectionResetByPeer,
356 .TIMEDOUT => return error.ConnectionTimedOut,
357 .NOTCAPABLE => return error.AccessDenied,
358358 else => |err| return unexpectedErrno(err),
359359 }
360360 }
......@@ -370,18 +370,18 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
370370 while (true) {
371371 const rc = system.read(fd, buf.ptr, adjusted_len);
372372 switch (errno(rc)) {
373 0 => return @intCast(usize, rc),
374 EINTR => continue,
375 EINVAL => unreachable,
376 EFAULT => unreachable,
377 EAGAIN => return error.WouldBlock,
378 EBADF => return error.NotOpenForReading, // Can be a race condition.
379 EIO => return error.InputOutput,
380 EISDIR => return error.IsDir,
381 ENOBUFS => return error.SystemResources,
382 ENOMEM => return error.SystemResources,
383 ECONNRESET => return error.ConnectionResetByPeer,
384 ETIMEDOUT => return error.ConnectionTimedOut,
373 .SUCCESS => return @intCast(usize, rc),
374 .INTR => continue,
375 .INVAL => unreachable,
376 .FAULT => unreachable,
377 .AGAIN => return error.WouldBlock,
378 .BADF => return error.NotOpenForReading, // Can be a race condition.
379 .IO => return error.InputOutput,
380 .ISDIR => return error.IsDir,
381 .NOBUFS => return error.SystemResources,
382 .NOMEM => return error.SystemResources,
383 .CONNRESET => return error.ConnectionResetByPeer,
384 .TIMEDOUT => return error.ConnectionTimedOut,
385385 else => |err| return unexpectedErrno(err),
386386 }
387387 }
......@@ -407,17 +407,17 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
407407 if (builtin.os.tag == .wasi and !builtin.link_libc) {
408408 var nread: usize = undefined;
409409 switch (wasi.fd_read(fd, iov.ptr, iov.len, &nread)) {
410 wasi.ESUCCESS => return nread,
411 wasi.EINTR => unreachable,
412 wasi.EINVAL => unreachable,
413 wasi.EFAULT => unreachable,
414 wasi.EAGAIN => unreachable, // currently not support in WASI
415 wasi.EBADF => return error.NotOpenForReading, // can be a race condition
416 wasi.EIO => return error.InputOutput,
417 wasi.EISDIR => return error.IsDir,
418 wasi.ENOBUFS => return error.SystemResources,
419 wasi.ENOMEM => return error.SystemResources,
420 wasi.ENOTCAPABLE => return error.AccessDenied,
410 .SUCCESS => return nread,
411 .INTR => unreachable,
412 .INVAL => unreachable,
413 .FAULT => unreachable,
414 .AGAIN => unreachable, // currently not support in WASI
415 .BADF => return error.NotOpenForReading, // can be a race condition
416 .IO => return error.InputOutput,
417 .ISDIR => return error.IsDir,
418 .NOBUFS => return error.SystemResources,
419 .NOMEM => return error.SystemResources,
420 .NOTCAPABLE => return error.AccessDenied,
421421 else => |err| return unexpectedErrno(err),
422422 }
423423 }
......@@ -426,16 +426,16 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
426426 // TODO handle the case when iov_len is too large and get rid of this @intCast
427427 const rc = system.readv(fd, iov.ptr, iov_count);
428428 switch (errno(rc)) {
429 0 => return @intCast(usize, rc),
430 EINTR => continue,
431 EINVAL => unreachable,
432 EFAULT => unreachable,
433 EAGAIN => return error.WouldBlock,
434 EBADF => return error.NotOpenForReading, // can be a race condition
435 EIO => return error.InputOutput,
436 EISDIR => return error.IsDir,
437 ENOBUFS => return error.SystemResources,
438 ENOMEM => return error.SystemResources,
429 .SUCCESS => return @intCast(usize, rc),
430 .INTR => continue,
431 .INVAL => unreachable,
432 .FAULT => unreachable,
433 .AGAIN => return error.WouldBlock,
434 .BADF => return error.NotOpenForReading, // can be a race condition
435 .IO => return error.InputOutput,
436 .ISDIR => return error.IsDir,
437 .NOBUFS => return error.SystemResources,
438 .NOMEM => return error.SystemResources,
439439 else => |err| return unexpectedErrno(err),
440440 }
441441 }
......@@ -469,21 +469,21 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
469469
470470 var nread: usize = undefined;
471471 switch (wasi.fd_pread(fd, &iovs, iovs.len, offset, &nread)) {
472 wasi.ESUCCESS => return nread,
473 wasi.EINTR => unreachable,
474 wasi.EINVAL => unreachable,
475 wasi.EFAULT => unreachable,
476 wasi.EAGAIN => unreachable,
477 wasi.EBADF => return error.NotOpenForReading, // Can be a race condition.
478 wasi.EIO => return error.InputOutput,
479 wasi.EISDIR => return error.IsDir,
480 wasi.ENOBUFS => return error.SystemResources,
481 wasi.ENOMEM => return error.SystemResources,
482 wasi.ECONNRESET => return error.ConnectionResetByPeer,
483 wasi.ENXIO => return error.Unseekable,
484 wasi.ESPIPE => return error.Unseekable,
485 wasi.EOVERFLOW => return error.Unseekable,
486 wasi.ENOTCAPABLE => return error.AccessDenied,
472 .SUCCESS => return nread,
473 .INTR => unreachable,
474 .INVAL => unreachable,
475 .FAULT => unreachable,
476 .AGAIN => unreachable,
477 .BADF => return error.NotOpenForReading, // Can be a race condition.
478 .IO => return error.InputOutput,
479 .ISDIR => return error.IsDir,
480 .NOBUFS => return error.SystemResources,
481 .NOMEM => return error.SystemResources,
482 .CONNRESET => return error.ConnectionResetByPeer,
483 .NXIO => return error.Unseekable,
484 .SPIPE => return error.Unseekable,
485 .OVERFLOW => return error.Unseekable,
486 .NOTCAPABLE => return error.AccessDenied,
487487 else => |err| return unexpectedErrno(err),
488488 }
489489 }
......@@ -505,20 +505,20 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
505505 while (true) {
506506 const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset);
507507 switch (errno(rc)) {
508 0 => return @intCast(usize, rc),
509 EINTR => continue,
510 EINVAL => unreachable,
511 EFAULT => unreachable,
512 EAGAIN => return error.WouldBlock,
513 EBADF => return error.NotOpenForReading, // Can be a race condition.
514 EIO => return error.InputOutput,
515 EISDIR => return error.IsDir,
516 ENOBUFS => return error.SystemResources,
517 ENOMEM => return error.SystemResources,
518 ECONNRESET => return error.ConnectionResetByPeer,
519 ENXIO => return error.Unseekable,
520 ESPIPE => return error.Unseekable,
521 EOVERFLOW => return error.Unseekable,
508 .SUCCESS => return @intCast(usize, rc),
509 .INTR => continue,
510 .INVAL => unreachable,
511 .FAULT => unreachable,
512 .AGAIN => return error.WouldBlock,
513 .BADF => return error.NotOpenForReading, // Can be a race condition.
514 .IO => return error.InputOutput,
515 .ISDIR => return error.IsDir,
516 .NOBUFS => return error.SystemResources,
517 .NOMEM => return error.SystemResources,
518 .CONNRESET => return error.ConnectionResetByPeer,
519 .NXIO => return error.Unseekable,
520 .SPIPE => return error.Unseekable,
521 .OVERFLOW => return error.Unseekable,
522522 else => |err| return unexpectedErrno(err),
523523 }
524524 }
......@@ -558,15 +558,15 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
558558 }
559559 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
560560 switch (wasi.fd_filestat_set_size(fd, length)) {
561 wasi.ESUCCESS => return,
562 wasi.EINTR => unreachable,
563 wasi.EFBIG => return error.FileTooBig,
564 wasi.EIO => return error.InputOutput,
565 wasi.EPERM => return error.AccessDenied,
566 wasi.ETXTBSY => return error.FileBusy,
567 wasi.EBADF => unreachable, // Handle not open for writing
568 wasi.EINVAL => unreachable, // Handle not open for writing
569 wasi.ENOTCAPABLE => return error.AccessDenied,
561 .SUCCESS => return,
562 .INTR => unreachable,
563 .FBIG => return error.FileTooBig,
564 .IO => return error.InputOutput,
565 .PERM => return error.AccessDenied,
566 .TXTBSY => return error.FileBusy,
567 .BADF => unreachable, // Handle not open for writing
568 .INVAL => unreachable, // Handle not open for writing
569 .NOTCAPABLE => return error.AccessDenied,
570570 else => |err| return unexpectedErrno(err),
571571 }
572572 }
......@@ -579,14 +579,14 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
579579
580580 const ilen = @bitCast(i64, length); // the OS treats this as unsigned
581581 switch (errno(ftruncate_sym(fd, ilen))) {
582 0 => return,
583 EINTR => continue,
584 EFBIG => return error.FileTooBig,
585 EIO => return error.InputOutput,
586 EPERM => return error.AccessDenied,
587 ETXTBSY => return error.FileBusy,
588 EBADF => unreachable, // Handle not open for writing
589 EINVAL => unreachable, // Handle not open for writing
582 .SUCCESS => return,
583 .INTR => continue,
584 .FBIG => return error.FileTooBig,
585 .IO => return error.InputOutput,
586 .PERM => return error.AccessDenied,
587 .TXTBSY => return error.FileBusy,
588 .BADF => unreachable, // Handle not open for writing
589 .INVAL => unreachable, // Handle not open for writing
590590 else => |err| return unexpectedErrno(err),
591591 }
592592 }
......@@ -620,20 +620,20 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
620620 if (builtin.os.tag == .wasi and !builtin.link_libc) {
621621 var nread: usize = undefined;
622622 switch (wasi.fd_pread(fd, iov.ptr, iov.len, offset, &nread)) {
623 wasi.ESUCCESS => return nread,
624 wasi.EINTR => unreachable,
625 wasi.EINVAL => unreachable,
626 wasi.EFAULT => unreachable,
627 wasi.EAGAIN => unreachable,
628 wasi.EBADF => return error.NotOpenForReading, // can be a race condition
629 wasi.EIO => return error.InputOutput,
630 wasi.EISDIR => return error.IsDir,
631 wasi.ENOBUFS => return error.SystemResources,
632 wasi.ENOMEM => return error.SystemResources,
633 wasi.ENXIO => return error.Unseekable,
634 wasi.ESPIPE => return error.Unseekable,
635 wasi.EOVERFLOW => return error.Unseekable,
636 wasi.ENOTCAPABLE => return error.AccessDenied,
623 .SUCCESS => return nread,
624 .INTR => unreachable,
625 .INVAL => unreachable,
626 .FAULT => unreachable,
627 .AGAIN => unreachable,
628 .BADF => return error.NotOpenForReading, // can be a race condition
629 .IO => return error.InputOutput,
630 .ISDIR => return error.IsDir,
631 .NOBUFS => return error.SystemResources,
632 .NOMEM => return error.SystemResources,
633 .NXIO => return error.Unseekable,
634 .SPIPE => return error.Unseekable,
635 .OVERFLOW => return error.Unseekable,
636 .NOTCAPABLE => return error.AccessDenied,
637637 else => |err| return unexpectedErrno(err),
638638 }
639639 }
......@@ -649,19 +649,19 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
649649 while (true) {
650650 const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset);
651651 switch (errno(rc)) {
652 0 => return @bitCast(usize, rc),
653 EINTR => continue,
654 EINVAL => unreachable,
655 EFAULT => unreachable,
656 EAGAIN => return error.WouldBlock,
657 EBADF => return error.NotOpenForReading, // can be a race condition
658 EIO => return error.InputOutput,
659 EISDIR => return error.IsDir,
660 ENOBUFS => return error.SystemResources,
661 ENOMEM => return error.SystemResources,
662 ENXIO => return error.Unseekable,
663 ESPIPE => return error.Unseekable,
664 EOVERFLOW => return error.Unseekable,
652 .SUCCESS => return @bitCast(usize, rc),
653 .INTR => continue,
654 .INVAL => unreachable,
655 .FAULT => unreachable,
656 .AGAIN => return error.WouldBlock,
657 .BADF => return error.NotOpenForReading, // can be a race condition
658 .IO => return error.InputOutput,
659 .ISDIR => return error.IsDir,
660 .NOBUFS => return error.SystemResources,
661 .NOMEM => return error.SystemResources,
662 .NXIO => return error.Unseekable,
663 .SPIPE => return error.Unseekable,
664 .OVERFLOW => return error.Unseekable,
665665 else => |err| return unexpectedErrno(err),
666666 }
667667 }
......@@ -723,20 +723,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
723723 }};
724724 var nwritten: usize = undefined;
725725 switch (wasi.fd_write(fd, &ciovs, ciovs.len, &nwritten)) {
726 wasi.ESUCCESS => return nwritten,
727 wasi.EINTR => unreachable,
728 wasi.EINVAL => unreachable,
729 wasi.EFAULT => unreachable,
730 wasi.EAGAIN => unreachable,
731 wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
732 wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
733 wasi.EDQUOT => return error.DiskQuota,
734 wasi.EFBIG => return error.FileTooBig,
735 wasi.EIO => return error.InputOutput,
736 wasi.ENOSPC => return error.NoSpaceLeft,
737 wasi.EPERM => return error.AccessDenied,
738 wasi.EPIPE => return error.BrokenPipe,
739 wasi.ENOTCAPABLE => return error.AccessDenied,
726 .SUCCESS => return nwritten,
727 .INTR => unreachable,
728 .INVAL => unreachable,
729 .FAULT => unreachable,
730 .AGAIN => unreachable,
731 .BADF => return error.NotOpenForWriting, // can be a race condition.
732 .DESTADDRREQ => unreachable, // `connect` was never called.
733 .DQUOT => return error.DiskQuota,
734 .FBIG => return error.FileTooBig,
735 .IO => return error.InputOutput,
736 .NOSPC => return error.NoSpaceLeft,
737 .PERM => return error.AccessDenied,
738 .PIPE => return error.BrokenPipe,
739 .NOTCAPABLE => return error.AccessDenied,
740740 else => |err| return unexpectedErrno(err),
741741 }
742742 }
......@@ -751,20 +751,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
751751 while (true) {
752752 const rc = system.write(fd, bytes.ptr, adjusted_len);
753753 switch (errno(rc)) {
754 0 => return @intCast(usize, rc),
755 EINTR => continue,
756 EINVAL => unreachable,
757 EFAULT => unreachable,
758 EAGAIN => return error.WouldBlock,
759 EBADF => return error.NotOpenForWriting, // can be a race condition.
760 EDESTADDRREQ => unreachable, // `connect` was never called.
761 EDQUOT => return error.DiskQuota,
762 EFBIG => return error.FileTooBig,
763 EIO => return error.InputOutput,
764 ENOSPC => return error.NoSpaceLeft,
765 EPERM => return error.AccessDenied,
766 EPIPE => return error.BrokenPipe,
767 ECONNRESET => return error.ConnectionResetByPeer,
754 .SUCCESS => return @intCast(usize, rc),
755 .INTR => continue,
756 .INVAL => unreachable,
757 .FAULT => unreachable,
758 .AGAIN => return error.WouldBlock,
759 .BADF => return error.NotOpenForWriting, // can be a race condition.
760 .DESTADDRREQ => unreachable, // `connect` was never called.
761 .DQUOT => return error.DiskQuota,
762 .FBIG => return error.FileTooBig,
763 .IO => return error.InputOutput,
764 .NOSPC => return error.NoSpaceLeft,
765 .PERM => return error.AccessDenied,
766 .PIPE => return error.BrokenPipe,
767 .CONNRESET => return error.ConnectionResetByPeer,
768768 else => |err| return unexpectedErrno(err),
769769 }
770770 }
......@@ -798,20 +798,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
798798 if (builtin.os.tag == .wasi and !builtin.link_libc) {
799799 var nwritten: usize = undefined;
800800 switch (wasi.fd_write(fd, iov.ptr, iov.len, &nwritten)) {
801 wasi.ESUCCESS => return nwritten,
802 wasi.EINTR => unreachable,
803 wasi.EINVAL => unreachable,
804 wasi.EFAULT => unreachable,
805 wasi.EAGAIN => unreachable,
806 wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
807 wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
808 wasi.EDQUOT => return error.DiskQuota,
809 wasi.EFBIG => return error.FileTooBig,
810 wasi.EIO => return error.InputOutput,
811 wasi.ENOSPC => return error.NoSpaceLeft,
812 wasi.EPERM => return error.AccessDenied,
813 wasi.EPIPE => return error.BrokenPipe,
814 wasi.ENOTCAPABLE => return error.AccessDenied,
801 .SUCCESS => return nwritten,
802 .INTR => unreachable,
803 .INVAL => unreachable,
804 .FAULT => unreachable,
805 .AGAIN => unreachable,
806 .BADF => return error.NotOpenForWriting, // can be a race condition.
807 .DESTADDRREQ => unreachable, // `connect` was never called.
808 .DQUOT => return error.DiskQuota,
809 .FBIG => return error.FileTooBig,
810 .IO => return error.InputOutput,
811 .NOSPC => return error.NoSpaceLeft,
812 .PERM => return error.AccessDenied,
813 .PIPE => return error.BrokenPipe,
814 .NOTCAPABLE => return error.AccessDenied,
815815 else => |err| return unexpectedErrno(err),
816816 }
817817 }
......@@ -820,20 +820,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
820820 while (true) {
821821 const rc = system.writev(fd, iov.ptr, iov_count);
822822 switch (errno(rc)) {
823 0 => return @intCast(usize, rc),
824 EINTR => continue,
825 EINVAL => unreachable,
826 EFAULT => unreachable,
827 EAGAIN => return error.WouldBlock,
828 EBADF => return error.NotOpenForWriting, // Can be a race condition.
829 EDESTADDRREQ => unreachable, // `connect` was never called.
830 EDQUOT => return error.DiskQuota,
831 EFBIG => return error.FileTooBig,
832 EIO => return error.InputOutput,
833 ENOSPC => return error.NoSpaceLeft,
834 EPERM => return error.AccessDenied,
835 EPIPE => return error.BrokenPipe,
836 ECONNRESET => return error.ConnectionResetByPeer,
823 .SUCCESS => return @intCast(usize, rc),
824 .INTR => continue,
825 .INVAL => unreachable,
826 .FAULT => unreachable,
827 .AGAIN => return error.WouldBlock,
828 .BADF => return error.NotOpenForWriting, // Can be a race condition.
829 .DESTADDRREQ => unreachable, // `connect` was never called.
830 .DQUOT => return error.DiskQuota,
831 .FBIG => return error.FileTooBig,
832 .IO => return error.InputOutput,
833 .NOSPC => return error.NoSpaceLeft,
834 .PERM => return error.AccessDenied,
835 .PIPE => return error.BrokenPipe,
836 .CONNRESET => return error.ConnectionResetByPeer,
837837 else => |err| return unexpectedErrno(err),
838838 }
839839 }
......@@ -875,23 +875,23 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
875875
876876 var nwritten: usize = undefined;
877877 switch (wasi.fd_pwrite(fd, &ciovs, ciovs.len, offset, &nwritten)) {
878 wasi.ESUCCESS => return nwritten,
879 wasi.EINTR => unreachable,
880 wasi.EINVAL => unreachable,
881 wasi.EFAULT => unreachable,
882 wasi.EAGAIN => unreachable,
883 wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
884 wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
885 wasi.EDQUOT => return error.DiskQuota,
886 wasi.EFBIG => return error.FileTooBig,
887 wasi.EIO => return error.InputOutput,
888 wasi.ENOSPC => return error.NoSpaceLeft,
889 wasi.EPERM => return error.AccessDenied,
890 wasi.EPIPE => return error.BrokenPipe,
891 wasi.ENXIO => return error.Unseekable,
892 wasi.ESPIPE => return error.Unseekable,
893 wasi.EOVERFLOW => return error.Unseekable,
894 wasi.ENOTCAPABLE => return error.AccessDenied,
878 .SUCCESS => return nwritten,
879 .INTR => unreachable,
880 .INVAL => unreachable,
881 .FAULT => unreachable,
882 .AGAIN => unreachable,
883 .BADF => return error.NotOpenForWriting, // can be a race condition.
884 .DESTADDRREQ => unreachable, // `connect` was never called.
885 .DQUOT => return error.DiskQuota,
886 .FBIG => return error.FileTooBig,
887 .IO => return error.InputOutput,
888 .NOSPC => return error.NoSpaceLeft,
889 .PERM => return error.AccessDenied,
890 .PIPE => return error.BrokenPipe,
891 .NXIO => return error.Unseekable,
892 .SPIPE => return error.Unseekable,
893 .OVERFLOW => return error.Unseekable,
894 .NOTCAPABLE => return error.AccessDenied,
895895 else => |err| return unexpectedErrno(err),
896896 }
897897 }
......@@ -913,22 +913,22 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
913913 while (true) {
914914 const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset);
915915 switch (errno(rc)) {
916 0 => return @intCast(usize, rc),
917 EINTR => continue,
918 EINVAL => unreachable,
919 EFAULT => unreachable,
920 EAGAIN => return error.WouldBlock,
921 EBADF => return error.NotOpenForWriting, // Can be a race condition.
922 EDESTADDRREQ => unreachable, // `connect` was never called.
923 EDQUOT => return error.DiskQuota,
924 EFBIG => return error.FileTooBig,
925 EIO => return error.InputOutput,
926 ENOSPC => return error.NoSpaceLeft,
927 EPERM => return error.AccessDenied,
928 EPIPE => return error.BrokenPipe,
929 ENXIO => return error.Unseekable,
930 ESPIPE => return error.Unseekable,
931 EOVERFLOW => return error.Unseekable,
916 .SUCCESS => return @intCast(usize, rc),
917 .INTR => continue,
918 .INVAL => unreachable,
919 .FAULT => unreachable,
920 .AGAIN => return error.WouldBlock,
921 .BADF => return error.NotOpenForWriting, // Can be a race condition.
922 .DESTADDRREQ => unreachable, // `connect` was never called.
923 .DQUOT => return error.DiskQuota,
924 .FBIG => return error.FileTooBig,
925 .IO => return error.InputOutput,
926 .NOSPC => return error.NoSpaceLeft,
927 .PERM => return error.AccessDenied,
928 .PIPE => return error.BrokenPipe,
929 .NXIO => return error.Unseekable,
930 .SPIPE => return error.Unseekable,
931 .OVERFLOW => return error.Unseekable,
932932 else => |err| return unexpectedErrno(err),
933933 }
934934 }
......@@ -971,23 +971,23 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
971971 if (builtin.os.tag == .wasi and !builtin.link_libc) {
972972 var nwritten: usize = undefined;
973973 switch (wasi.fd_pwrite(fd, iov.ptr, iov.len, offset, &nwritten)) {
974 wasi.ESUCCESS => return nwritten,
975 wasi.EINTR => unreachable,
976 wasi.EINVAL => unreachable,
977 wasi.EFAULT => unreachable,
978 wasi.EAGAIN => unreachable,
979 wasi.EBADF => return error.NotOpenForWriting, // Can be a race condition.
980 wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
981 wasi.EDQUOT => return error.DiskQuota,
982 wasi.EFBIG => return error.FileTooBig,
983 wasi.EIO => return error.InputOutput,
984 wasi.ENOSPC => return error.NoSpaceLeft,
985 wasi.EPERM => return error.AccessDenied,
986 wasi.EPIPE => return error.BrokenPipe,
987 wasi.ENXIO => return error.Unseekable,
988 wasi.ESPIPE => return error.Unseekable,
989 wasi.EOVERFLOW => return error.Unseekable,
990 wasi.ENOTCAPABLE => return error.AccessDenied,
974 .SUCCESS => return nwritten,
975 .INTR => unreachable,
976 .INVAL => unreachable,
977 .FAULT => unreachable,
978 .AGAIN => unreachable,
979 .BADF => return error.NotOpenForWriting, // Can be a race condition.
980 .DESTADDRREQ => unreachable, // `connect` was never called.
981 .DQUOT => return error.DiskQuota,
982 .FBIG => return error.FileTooBig,
983 .IO => return error.InputOutput,
984 .NOSPC => return error.NoSpaceLeft,
985 .PERM => return error.AccessDenied,
986 .PIPE => return error.BrokenPipe,
987 .NXIO => return error.Unseekable,
988 .SPIPE => return error.Unseekable,
989 .OVERFLOW => return error.Unseekable,
990 .NOTCAPABLE => return error.AccessDenied,
991991 else => |err| return unexpectedErrno(err),
992992 }
993993 }
......@@ -1002,22 +1002,22 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
10021002 while (true) {
10031003 const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset);
10041004 switch (errno(rc)) {
1005 0 => return @intCast(usize, rc),
1006 EINTR => continue,
1007 EINVAL => unreachable,
1008 EFAULT => unreachable,
1009 EAGAIN => return error.WouldBlock,
1010 EBADF => return error.NotOpenForWriting, // Can be a race condition.
1011 EDESTADDRREQ => unreachable, // `connect` was never called.
1012 EDQUOT => return error.DiskQuota,
1013 EFBIG => return error.FileTooBig,
1014 EIO => return error.InputOutput,
1015 ENOSPC => return error.NoSpaceLeft,
1016 EPERM => return error.AccessDenied,
1017 EPIPE => return error.BrokenPipe,
1018 ENXIO => return error.Unseekable,
1019 ESPIPE => return error.Unseekable,
1020 EOVERFLOW => return error.Unseekable,
1005 .SUCCESS => return @intCast(usize, rc),
1006 .INTR => continue,
1007 .INVAL => unreachable,
1008 .FAULT => unreachable,
1009 .AGAIN => return error.WouldBlock,
1010 .BADF => return error.NotOpenForWriting, // Can be a race condition.
1011 .DESTADDRREQ => unreachable, // `connect` was never called.
1012 .DQUOT => return error.DiskQuota,
1013 .FBIG => return error.FileTooBig,
1014 .IO => return error.InputOutput,
1015 .NOSPC => return error.NoSpaceLeft,
1016 .PERM => return error.AccessDenied,
1017 .PIPE => return error.BrokenPipe,
1018 .NXIO => return error.Unseekable,
1019 .SPIPE => return error.Unseekable,
1020 .OVERFLOW => return error.Unseekable,
10211021 else => |err| return unexpectedErrno(err),
10221022 }
10231023 }
......@@ -1098,27 +1098,27 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t
10981098 while (true) {
10991099 const rc = open_sym(file_path, flags, perm);
11001100 switch (errno(rc)) {
1101 0 => return @intCast(fd_t, rc),
1102 EINTR => continue,
1103
1104 EFAULT => unreachable,
1105 EINVAL => unreachable,
1106 EACCES => return error.AccessDenied,
1107 EFBIG => return error.FileTooBig,
1108 EOVERFLOW => return error.FileTooBig,
1109 EISDIR => return error.IsDir,
1110 ELOOP => return error.SymLinkLoop,
1111 EMFILE => return error.ProcessFdQuotaExceeded,
1112 ENAMETOOLONG => return error.NameTooLong,
1113 ENFILE => return error.SystemFdQuotaExceeded,
1114 ENODEV => return error.NoDevice,
1115 ENOENT => return error.FileNotFound,
1116 ENOMEM => return error.SystemResources,
1117 ENOSPC => return error.NoSpaceLeft,
1118 ENOTDIR => return error.NotDir,
1119 EPERM => return error.AccessDenied,
1120 EEXIST => return error.PathAlreadyExists,
1121 EBUSY => return error.DeviceBusy,
1101 .SUCCESS => return @intCast(fd_t, rc),
1102 .INTR => continue,
1103
1104 .FAULT => unreachable,
1105 .INVAL => unreachable,
1106 .ACCES => return error.AccessDenied,
1107 .FBIG => return error.FileTooBig,
1108 .OVERFLOW => return error.FileTooBig,
1109 .ISDIR => return error.IsDir,
1110 .LOOP => return error.SymLinkLoop,
1111 .MFILE => return error.ProcessFdQuotaExceeded,
1112 .NAMETOOLONG => return error.NameTooLong,
1113 .NFILE => return error.SystemFdQuotaExceeded,
1114 .NODEV => return error.NoDevice,
1115 .NOENT => return error.FileNotFound,
1116 .NOMEM => return error.SystemResources,
1117 .NOSPC => return error.NoSpaceLeft,
1118 .NOTDIR => return error.NotDir,
1119 .PERM => return error.AccessDenied,
1120 .EXIST => return error.PathAlreadyExists,
1121 .BUSY => return error.DeviceBusy,
11221122 else => |err| return unexpectedErrno(err),
11231123 }
11241124 }
......@@ -1193,28 +1193,28 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, lookup_flags: lookupflags
11931193 while (true) {
11941194 var fd: fd_t = undefined;
11951195 switch (wasi.path_open(dir_fd, lookup_flags, file_path.ptr, file_path.len, oflags, base, inheriting, fdflags, &fd)) {
1196 wasi.ESUCCESS => return fd,
1197 wasi.EINTR => continue,
1198
1199 wasi.EFAULT => unreachable,
1200 wasi.EINVAL => unreachable,
1201 wasi.EACCES => return error.AccessDenied,
1202 wasi.EFBIG => return error.FileTooBig,
1203 wasi.EOVERFLOW => return error.FileTooBig,
1204 wasi.EISDIR => return error.IsDir,
1205 wasi.ELOOP => return error.SymLinkLoop,
1206 wasi.EMFILE => return error.ProcessFdQuotaExceeded,
1207 wasi.ENAMETOOLONG => return error.NameTooLong,
1208 wasi.ENFILE => return error.SystemFdQuotaExceeded,
1209 wasi.ENODEV => return error.NoDevice,
1210 wasi.ENOENT => return error.FileNotFound,
1211 wasi.ENOMEM => return error.SystemResources,
1212 wasi.ENOSPC => return error.NoSpaceLeft,
1213 wasi.ENOTDIR => return error.NotDir,
1214 wasi.EPERM => return error.AccessDenied,
1215 wasi.EEXIST => return error.PathAlreadyExists,
1216 wasi.EBUSY => return error.DeviceBusy,
1217 wasi.ENOTCAPABLE => return error.AccessDenied,
1196 .SUCCESS => return fd,
1197 .INTR => continue,
1198
1199 .FAULT => unreachable,
1200 .INVAL => unreachable,
1201 .ACCES => return error.AccessDenied,
1202 .FBIG => return error.FileTooBig,
1203 .OVERFLOW => return error.FileTooBig,
1204 .ISDIR => return error.IsDir,
1205 .LOOP => return error.SymLinkLoop,
1206 .MFILE => return error.ProcessFdQuotaExceeded,
1207 .NAMETOOLONG => return error.NameTooLong,
1208 .NFILE => return error.SystemFdQuotaExceeded,
1209 .NODEV => return error.NoDevice,
1210 .NOENT => return error.FileNotFound,
1211 .NOMEM => return error.SystemResources,
1212 .NOSPC => return error.NoSpaceLeft,
1213 .NOTDIR => return error.NotDir,
1214 .PERM => return error.AccessDenied,
1215 .EXIST => return error.PathAlreadyExists,
1216 .BUSY => return error.DeviceBusy,
1217 .NOTCAPABLE => return error.AccessDenied,
12181218 else => |err| return unexpectedErrno(err),
12191219 }
12201220 }
......@@ -1239,30 +1239,30 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
12391239 while (true) {
12401240 const rc = openat_sym(dir_fd, file_path, flags, mode);
12411241 switch (errno(rc)) {
1242 0 => return @intCast(fd_t, rc),
1243 EINTR => continue,
1244
1245 EFAULT => unreachable,
1246 EINVAL => unreachable,
1247 EBADF => unreachable,
1248 EACCES => return error.AccessDenied,
1249 EFBIG => return error.FileTooBig,
1250 EOVERFLOW => return error.FileTooBig,
1251 EISDIR => return error.IsDir,
1252 ELOOP => return error.SymLinkLoop,
1253 EMFILE => return error.ProcessFdQuotaExceeded,
1254 ENAMETOOLONG => return error.NameTooLong,
1255 ENFILE => return error.SystemFdQuotaExceeded,
1256 ENODEV => return error.NoDevice,
1257 ENOENT => return error.FileNotFound,
1258 ENOMEM => return error.SystemResources,
1259 ENOSPC => return error.NoSpaceLeft,
1260 ENOTDIR => return error.NotDir,
1261 EPERM => return error.AccessDenied,
1262 EEXIST => return error.PathAlreadyExists,
1263 EBUSY => return error.DeviceBusy,
1264 EOPNOTSUPP => return error.FileLocksNotSupported,
1265 EWOULDBLOCK => return error.WouldBlock,
1242 .SUCCESS => return @intCast(fd_t, rc),
1243 .INTR => continue,
1244
1245 .FAULT => unreachable,
1246 .INVAL => unreachable,
1247 .BADF => unreachable,
1248 .ACCES => return error.AccessDenied,
1249 .FBIG => return error.FileTooBig,
1250 .OVERFLOW => return error.FileTooBig,
1251 .ISDIR => return error.IsDir,
1252 .LOOP => return error.SymLinkLoop,
1253 .MFILE => return error.ProcessFdQuotaExceeded,
1254 .NAMETOOLONG => return error.NameTooLong,
1255 .NFILE => return error.SystemFdQuotaExceeded,
1256 .NODEV => return error.NoDevice,
1257 .NOENT => return error.FileNotFound,
1258 .NOMEM => return error.SystemResources,
1259 .NOSPC => return error.NoSpaceLeft,
1260 .NOTDIR => return error.NotDir,
1261 .PERM => return error.AccessDenied,
1262 .EXIST => return error.PathAlreadyExists,
1263 .BUSY => return error.DeviceBusy,
1264 .OPNOTSUPP => return error.FileLocksNotSupported,
1265 .AGAIN => return error.WouldBlock,
12661266 else => |err| return unexpectedErrno(err),
12671267 }
12681268 }
......@@ -1286,9 +1286,9 @@ pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t)
12861286pub fn dup(old_fd: fd_t) !fd_t {
12871287 const rc = system.dup(old_fd);
12881288 return switch (errno(rc)) {
1289 0 => return @intCast(fd_t, rc),
1290 EMFILE => error.ProcessFdQuotaExceeded,
1291 EBADF => unreachable, // invalid file descriptor
1289 .SUCCESS => return @intCast(fd_t, rc),
1290 .MFILE => error.ProcessFdQuotaExceeded,
1291 .BADF => unreachable, // invalid file descriptor
12921292 else => |err| return unexpectedErrno(err),
12931293 };
12941294}
......@@ -1296,11 +1296,11 @@ pub fn dup(old_fd: fd_t) !fd_t {
12961296pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
12971297 while (true) {
12981298 switch (errno(system.dup2(old_fd, new_fd))) {
1299 0 => return,
1300 EBUSY, EINTR => continue,
1301 EMFILE => return error.ProcessFdQuotaExceeded,
1302 EINVAL => unreachable, // invalid parameters passed to dup2
1303 EBADF => unreachable, // invalid file descriptor
1299 .SUCCESS => return,
1300 .BUSY, .INTR => continue,
1301 .MFILE => return error.ProcessFdQuotaExceeded,
1302 .INVAL => unreachable, // invalid parameters passed to dup2
1303 .BADF => unreachable, // invalid file descriptor
13041304 else => |err| return unexpectedErrno(err),
13051305 }
13061306 }
......@@ -1331,23 +1331,23 @@ pub fn execveZ(
13311331 envp: [*:null]const ?[*:0]const u8,
13321332) ExecveError {
13331333 switch (errno(system.execve(path, child_argv, envp))) {
1334 0 => unreachable,
1335 EFAULT => unreachable,
1336 E2BIG => return error.SystemResources,
1337 EMFILE => return error.ProcessFdQuotaExceeded,
1338 ENAMETOOLONG => return error.NameTooLong,
1339 ENFILE => return error.SystemFdQuotaExceeded,
1340 ENOMEM => return error.SystemResources,
1341 EACCES => return error.AccessDenied,
1342 EPERM => return error.AccessDenied,
1343 EINVAL => return error.InvalidExe,
1344 ENOEXEC => return error.InvalidExe,
1345 EIO => return error.FileSystem,
1346 ELOOP => return error.FileSystem,
1347 EISDIR => return error.IsDir,
1348 ENOENT => return error.FileNotFound,
1349 ENOTDIR => return error.NotDir,
1350 ETXTBSY => return error.FileBusy,
1334 .SUCCESS => unreachable,
1335 .FAULT => unreachable,
1336 .@"2BIG" => return error.SystemResources,
1337 .MFILE => return error.ProcessFdQuotaExceeded,
1338 .NAMETOOLONG => return error.NameTooLong,
1339 .NFILE => return error.SystemFdQuotaExceeded,
1340 .NOMEM => return error.SystemResources,
1341 .ACCES => return error.AccessDenied,
1342 .PERM => return error.AccessDenied,
1343 .INVAL => return error.InvalidExe,
1344 .NOEXEC => return error.InvalidExe,
1345 .IO => return error.FileSystem,
1346 .LOOP => return error.FileSystem,
1347 .ISDIR => return error.IsDir,
1348 .NOENT => return error.FileNotFound,
1349 .NOTDIR => return error.NotDir,
1350 .TXTBSY => return error.FileBusy,
13511351 else => |err| return unexpectedErrno(err),
13521352 }
13531353}
......@@ -1543,16 +1543,17 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
15431543 }
15441544
15451545 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);
15471548 } else blk: {
15481549 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
15491550 };
15501551 switch (err) {
1551 0 => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)),
1552 EFAULT => unreachable,
1553 EINVAL => unreachable,
1554 ENOENT => return error.CurrentWorkingDirectoryUnlinked,
1555 ERANGE => return error.NameTooLong,
1552 .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)),
1553 .FAULT => unreachable,
1554 .INVAL => unreachable,
1555 .NOENT => return error.CurrentWorkingDirectoryUnlinked,
1556 .RANGE => return error.NameTooLong,
15561557 else => return unexpectedErrno(err),
15571558 }
15581559}
......@@ -1601,21 +1602,21 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin
16011602 @compileError("symlink is not supported on Windows; use std.os.windows.CreateSymbolicLink instead");
16021603 }
16031604 switch (errno(system.symlink(target_path, sym_link_path))) {
1604 0 => return,
1605 EFAULT => unreachable,
1606 EINVAL => unreachable,
1607 EACCES => return error.AccessDenied,
1608 EPERM => return error.AccessDenied,
1609 EDQUOT => return error.DiskQuota,
1610 EEXIST => return error.PathAlreadyExists,
1611 EIO => return error.FileSystem,
1612 ELOOP => return error.SymLinkLoop,
1613 ENAMETOOLONG => return error.NameTooLong,
1614 ENOENT => return error.FileNotFound,
1615 ENOTDIR => return error.NotDir,
1616 ENOMEM => return error.SystemResources,
1617 ENOSPC => return error.NoSpaceLeft,
1618 EROFS => return error.ReadOnlyFileSystem,
1605 .SUCCESS => return,
1606 .FAULT => unreachable,
1607 .INVAL => unreachable,
1608 .ACCES => return error.AccessDenied,
1609 .PERM => return error.AccessDenied,
1610 .DQUOT => return error.DiskQuota,
1611 .EXIST => return error.PathAlreadyExists,
1612 .IO => return error.FileSystem,
1613 .LOOP => return error.SymLinkLoop,
1614 .NAMETOOLONG => return error.NameTooLong,
1615 .NOENT => return error.FileNotFound,
1616 .NOTDIR => return error.NotDir,
1617 .NOMEM => return error.SystemResources,
1618 .NOSPC => return error.NoSpaceLeft,
1619 .ROFS => return error.ReadOnlyFileSystem,
16191620 else => |err| return unexpectedErrno(err),
16201621 }
16211622}
......@@ -1644,22 +1645,22 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
16441645/// See also `symlinkat`.
16451646pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
16461647 switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) {
1647 wasi.ESUCCESS => {},
1648 wasi.EFAULT => unreachable,
1649 wasi.EINVAL => unreachable,
1650 wasi.EACCES => return error.AccessDenied,
1651 wasi.EPERM => return error.AccessDenied,
1652 wasi.EDQUOT => return error.DiskQuota,
1653 wasi.EEXIST => return error.PathAlreadyExists,
1654 wasi.EIO => return error.FileSystem,
1655 wasi.ELOOP => return error.SymLinkLoop,
1656 wasi.ENAMETOOLONG => return error.NameTooLong,
1657 wasi.ENOENT => return error.FileNotFound,
1658 wasi.ENOTDIR => return error.NotDir,
1659 wasi.ENOMEM => return error.SystemResources,
1660 wasi.ENOSPC => return error.NoSpaceLeft,
1661 wasi.EROFS => return error.ReadOnlyFileSystem,
1662 wasi.ENOTCAPABLE => return error.AccessDenied,
1648 .SUCCESS => {},
1649 .FAULT => unreachable,
1650 .INVAL => unreachable,
1651 .ACCES => return error.AccessDenied,
1652 .PERM => return error.AccessDenied,
1653 .DQUOT => return error.DiskQuota,
1654 .EXIST => return error.PathAlreadyExists,
1655 .IO => return error.FileSystem,
1656 .LOOP => return error.SymLinkLoop,
1657 .NAMETOOLONG => return error.NameTooLong,
1658 .NOENT => return error.FileNotFound,
1659 .NOTDIR => return error.NotDir,
1660 .NOMEM => return error.SystemResources,
1661 .NOSPC => return error.NoSpaceLeft,
1662 .ROFS => return error.ReadOnlyFileSystem,
1663 .NOTCAPABLE => return error.AccessDenied,
16631664 else => |err| return unexpectedErrno(err),
16641665 }
16651666}
......@@ -1671,21 +1672,21 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:
16711672 @compileError("symlinkat is not supported on Windows; use std.os.windows.CreateSymbolicLink instead");
16721673 }
16731674 switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) {
1674 0 => return,
1675 EFAULT => unreachable,
1676 EINVAL => unreachable,
1677 EACCES => return error.AccessDenied,
1678 EPERM => return error.AccessDenied,
1679 EDQUOT => return error.DiskQuota,
1680 EEXIST => return error.PathAlreadyExists,
1681 EIO => return error.FileSystem,
1682 ELOOP => return error.SymLinkLoop,
1683 ENAMETOOLONG => return error.NameTooLong,
1684 ENOENT => return error.FileNotFound,
1685 ENOTDIR => return error.NotDir,
1686 ENOMEM => return error.SystemResources,
1687 ENOSPC => return error.NoSpaceLeft,
1688 EROFS => return error.ReadOnlyFileSystem,
1675 .SUCCESS => return,
1676 .FAULT => unreachable,
1677 .INVAL => unreachable,
1678 .ACCES => return error.AccessDenied,
1679 .PERM => return error.AccessDenied,
1680 .DQUOT => return error.DiskQuota,
1681 .EXIST => return error.PathAlreadyExists,
1682 .IO => return error.FileSystem,
1683 .LOOP => return error.SymLinkLoop,
1684 .NAMETOOLONG => return error.NameTooLong,
1685 .NOENT => return error.FileNotFound,
1686 .NOTDIR => return error.NotDir,
1687 .NOMEM => return error.SystemResources,
1688 .NOSPC => return error.NoSpaceLeft,
1689 .ROFS => return error.ReadOnlyFileSystem,
16891690 else => |err| return unexpectedErrno(err),
16901691 }
16911692}
......@@ -1707,22 +1708,22 @@ pub const LinkError = UnexpectedError || error{
17071708
17081709pub fn linkZ(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) LinkError!void {
17091710 switch (errno(system.link(oldpath, newpath, flags))) {
1710 0 => return,
1711 EACCES => return error.AccessDenied,
1712 EDQUOT => return error.DiskQuota,
1713 EEXIST => return error.PathAlreadyExists,
1714 EFAULT => unreachable,
1715 EIO => return error.FileSystem,
1716 ELOOP => return error.SymLinkLoop,
1717 EMLINK => return error.LinkQuotaExceeded,
1718 ENAMETOOLONG => return error.NameTooLong,
1719 ENOENT => return error.FileNotFound,
1720 ENOMEM => return error.SystemResources,
1721 ENOSPC => return error.NoSpaceLeft,
1722 EPERM => return error.AccessDenied,
1723 EROFS => return error.ReadOnlyFileSystem,
1724 EXDEV => return error.NotSameFileSystem,
1725 EINVAL => unreachable,
1711 .SUCCESS => return,
1712 .ACCES => return error.AccessDenied,
1713 .DQUOT => return error.DiskQuota,
1714 .EXIST => return error.PathAlreadyExists,
1715 .FAULT => unreachable,
1716 .IO => return error.FileSystem,
1717 .LOOP => return error.SymLinkLoop,
1718 .MLINK => return error.LinkQuotaExceeded,
1719 .NAMETOOLONG => return error.NameTooLong,
1720 .NOENT => return error.FileNotFound,
1721 .NOMEM => return error.SystemResources,
1722 .NOSPC => return error.NoSpaceLeft,
1723 .PERM => return error.AccessDenied,
1724 .ROFS => return error.ReadOnlyFileSystem,
1725 .XDEV => return error.NotSameFileSystem,
1726 .INVAL => unreachable,
17261727 else => |err| return unexpectedErrno(err),
17271728 }
17281729}
......@@ -1743,23 +1744,23 @@ pub fn linkatZ(
17431744 flags: i32,
17441745) LinkatError!void {
17451746 switch (errno(system.linkat(olddir, oldpath, newdir, newpath, flags))) {
1746 0 => return,
1747 EACCES => return error.AccessDenied,
1748 EDQUOT => return error.DiskQuota,
1749 EEXIST => return error.PathAlreadyExists,
1750 EFAULT => unreachable,
1751 EIO => return error.FileSystem,
1752 ELOOP => return error.SymLinkLoop,
1753 EMLINK => return error.LinkQuotaExceeded,
1754 ENAMETOOLONG => return error.NameTooLong,
1755 ENOENT => return error.FileNotFound,
1756 ENOMEM => return error.SystemResources,
1757 ENOSPC => return error.NoSpaceLeft,
1758 ENOTDIR => return error.NotDir,
1759 EPERM => return error.AccessDenied,
1760 EROFS => return error.ReadOnlyFileSystem,
1761 EXDEV => return error.NotSameFileSystem,
1762 EINVAL => unreachable,
1747 .SUCCESS => return,
1748 .ACCES => return error.AccessDenied,
1749 .DQUOT => return error.DiskQuota,
1750 .EXIST => return error.PathAlreadyExists,
1751 .FAULT => unreachable,
1752 .IO => return error.FileSystem,
1753 .LOOP => return error.SymLinkLoop,
1754 .MLINK => return error.LinkQuotaExceeded,
1755 .NAMETOOLONG => return error.NameTooLong,
1756 .NOENT => return error.FileNotFound,
1757 .NOMEM => return error.SystemResources,
1758 .NOSPC => return error.NoSpaceLeft,
1759 .NOTDIR => return error.NotDir,
1760 .PERM => return error.AccessDenied,
1761 .ROFS => return error.ReadOnlyFileSystem,
1762 .XDEV => return error.NotSameFileSystem,
1763 .INVAL => unreachable,
17631764 else => |err| return unexpectedErrno(err),
17641765 }
17651766}
......@@ -1822,20 +1823,20 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
18221823 return unlinkW(file_path_w.span());
18231824 }
18241825 switch (errno(system.unlink(file_path))) {
1825 0 => return,
1826 EACCES => return error.AccessDenied,
1827 EPERM => return error.AccessDenied,
1828 EBUSY => return error.FileBusy,
1829 EFAULT => unreachable,
1830 EINVAL => unreachable,
1831 EIO => return error.FileSystem,
1832 EISDIR => return error.IsDir,
1833 ELOOP => return error.SymLinkLoop,
1834 ENAMETOOLONG => return error.NameTooLong,
1835 ENOENT => return error.FileNotFound,
1836 ENOTDIR => return error.NotDir,
1837 ENOMEM => return error.SystemResources,
1838 EROFS => return error.ReadOnlyFileSystem,
1826 .SUCCESS => return,
1827 .ACCES => return error.AccessDenied,
1828 .PERM => return error.AccessDenied,
1829 .BUSY => return error.FileBusy,
1830 .FAULT => unreachable,
1831 .INVAL => unreachable,
1832 .IO => return error.FileSystem,
1833 .ISDIR => return error.IsDir,
1834 .LOOP => return error.SymLinkLoop,
1835 .NAMETOOLONG => return error.NameTooLong,
1836 .NOENT => return error.FileNotFound,
1837 .NOTDIR => return error.NotDir,
1838 .NOMEM => return error.SystemResources,
1839 .ROFS => return error.ReadOnlyFileSystem,
18391840 else => |err| return unexpectedErrno(err),
18401841 }
18411842}
......@@ -1875,24 +1876,24 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro
18751876 else
18761877 wasi.path_unlink_file(dirfd, file_path.ptr, file_path.len);
18771878 switch (res) {
1878 wasi.ESUCCESS => return,
1879 wasi.EACCES => return error.AccessDenied,
1880 wasi.EPERM => return error.AccessDenied,
1881 wasi.EBUSY => return error.FileBusy,
1882 wasi.EFAULT => unreachable,
1883 wasi.EIO => return error.FileSystem,
1884 wasi.EISDIR => return error.IsDir,
1885 wasi.ELOOP => return error.SymLinkLoop,
1886 wasi.ENAMETOOLONG => return error.NameTooLong,
1887 wasi.ENOENT => return error.FileNotFound,
1888 wasi.ENOTDIR => return error.NotDir,
1889 wasi.ENOMEM => return error.SystemResources,
1890 wasi.EROFS => return error.ReadOnlyFileSystem,
1891 wasi.ENOTEMPTY => return error.DirNotEmpty,
1892 wasi.ENOTCAPABLE => return error.AccessDenied,
1893
1894 wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component
1895 wasi.EBADF => unreachable, // always a race condition
1879 .SUCCESS => return,
1880 .ACCES => return error.AccessDenied,
1881 .PERM => return error.AccessDenied,
1882 .BUSY => return error.FileBusy,
1883 .FAULT => unreachable,
1884 .IO => return error.FileSystem,
1885 .ISDIR => return error.IsDir,
1886 .LOOP => return error.SymLinkLoop,
1887 .NAMETOOLONG => return error.NameTooLong,
1888 .NOENT => return error.FileNotFound,
1889 .NOTDIR => return error.NotDir,
1890 .NOMEM => return error.SystemResources,
1891 .ROFS => return error.ReadOnlyFileSystem,
1892 .NOTEMPTY => return error.DirNotEmpty,
1893 .NOTCAPABLE => return error.AccessDenied,
1894
1895 .INVAL => unreachable, // invalid flags, or pathname has . as last component
1896 .BADF => unreachable, // always a race condition
18961897
18971898 else => |err| return unexpectedErrno(err),
18981899 }
......@@ -1905,23 +1906,23 @@ pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatEr
19051906 return unlinkatW(dirfd, file_path_w.span(), flags);
19061907 }
19071908 switch (errno(system.unlinkat(dirfd, file_path_c, flags))) {
1908 0 => return,
1909 EACCES => return error.AccessDenied,
1910 EPERM => return error.AccessDenied,
1911 EBUSY => return error.FileBusy,
1912 EFAULT => unreachable,
1913 EIO => return error.FileSystem,
1914 EISDIR => return error.IsDir,
1915 ELOOP => return error.SymLinkLoop,
1916 ENAMETOOLONG => return error.NameTooLong,
1917 ENOENT => return error.FileNotFound,
1918 ENOTDIR => return error.NotDir,
1919 ENOMEM => return error.SystemResources,
1920 EROFS => return error.ReadOnlyFileSystem,
1921 ENOTEMPTY => return error.DirNotEmpty,
1922
1923 EINVAL => unreachable, // invalid flags, or pathname has . as last component
1924 EBADF => unreachable, // always a race condition
1909 .SUCCESS => return,
1910 .ACCES => return error.AccessDenied,
1911 .PERM => return error.AccessDenied,
1912 .BUSY => return error.FileBusy,
1913 .FAULT => unreachable,
1914 .IO => return error.FileSystem,
1915 .ISDIR => return error.IsDir,
1916 .LOOP => return error.SymLinkLoop,
1917 .NAMETOOLONG => return error.NameTooLong,
1918 .NOENT => return error.FileNotFound,
1919 .NOTDIR => return error.NotDir,
1920 .NOMEM => return error.SystemResources,
1921 .ROFS => return error.ReadOnlyFileSystem,
1922 .NOTEMPTY => return error.DirNotEmpty,
1923
1924 .INVAL => unreachable, // invalid flags, or pathname has . as last component
1925 .BADF => unreachable, // always a race condition
19251926
19261927 else => |err| return unexpectedErrno(err),
19271928 }
......@@ -1982,25 +1983,25 @@ pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!voi
19821983 return renameW(old_path_w.span().ptr, new_path_w.span().ptr);
19831984 }
19841985 switch (errno(system.rename(old_path, new_path))) {
1985 0 => return,
1986 EACCES => return error.AccessDenied,
1987 EPERM => return error.AccessDenied,
1988 EBUSY => return error.FileBusy,
1989 EDQUOT => return error.DiskQuota,
1990 EFAULT => unreachable,
1991 EINVAL => unreachable,
1992 EISDIR => return error.IsDir,
1993 ELOOP => return error.SymLinkLoop,
1994 EMLINK => return error.LinkQuotaExceeded,
1995 ENAMETOOLONG => return error.NameTooLong,
1996 ENOENT => return error.FileNotFound,
1997 ENOTDIR => return error.NotDir,
1998 ENOMEM => return error.SystemResources,
1999 ENOSPC => return error.NoSpaceLeft,
2000 EEXIST => return error.PathAlreadyExists,
2001 ENOTEMPTY => return error.PathAlreadyExists,
2002 EROFS => return error.ReadOnlyFileSystem,
2003 EXDEV => return error.RenameAcrossMountPoints,
1986 .SUCCESS => return,
1987 .ACCES => return error.AccessDenied,
1988 .PERM => return error.AccessDenied,
1989 .BUSY => return error.FileBusy,
1990 .DQUOT => return error.DiskQuota,
1991 .FAULT => unreachable,
1992 .INVAL => unreachable,
1993 .ISDIR => return error.IsDir,
1994 .LOOP => return error.SymLinkLoop,
1995 .MLINK => return error.LinkQuotaExceeded,
1996 .NAMETOOLONG => return error.NameTooLong,
1997 .NOENT => return error.FileNotFound,
1998 .NOTDIR => return error.NotDir,
1999 .NOMEM => return error.SystemResources,
2000 .NOSPC => return error.NoSpaceLeft,
2001 .EXIST => return error.PathAlreadyExists,
2002 .NOTEMPTY => return error.PathAlreadyExists,
2003 .ROFS => return error.ReadOnlyFileSystem,
2004 .XDEV => return error.RenameAcrossMountPoints,
20042005 else => |err| return unexpectedErrno(err),
20052006 }
20062007}
......@@ -2036,26 +2037,26 @@ pub fn renameat(
20362037/// See also `renameat`.
20372038pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void {
20382039 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 wasi.EACCES => return error.AccessDenied,
2041 wasi.EPERM => return error.AccessDenied,
2042 wasi.EBUSY => return error.FileBusy,
2043 wasi.EDQUOT => return error.DiskQuota,
2044 wasi.EFAULT => unreachable,
2045 wasi.EINVAL => unreachable,
2046 wasi.EISDIR => return error.IsDir,
2047 wasi.ELOOP => return error.SymLinkLoop,
2048 wasi.EMLINK => return error.LinkQuotaExceeded,
2049 wasi.ENAMETOOLONG => return error.NameTooLong,
2050 wasi.ENOENT => return error.FileNotFound,
2051 wasi.ENOTDIR => return error.NotDir,
2052 wasi.ENOMEM => return error.SystemResources,
2053 wasi.ENOSPC => return error.NoSpaceLeft,
2054 wasi.EEXIST => return error.PathAlreadyExists,
2055 wasi.ENOTEMPTY => return error.PathAlreadyExists,
2056 wasi.EROFS => return error.ReadOnlyFileSystem,
2057 wasi.EXDEV => return error.RenameAcrossMountPoints,
2058 wasi.ENOTCAPABLE => return error.AccessDenied,
2040 .SUCCESS => return,
2041 .ACCES => return error.AccessDenied,
2042 .PERM => return error.AccessDenied,
2043 .BUSY => return error.FileBusy,
2044 .DQUOT => return error.DiskQuota,
2045 .FAULT => unreachable,
2046 .INVAL => unreachable,
2047 .ISDIR => return error.IsDir,
2048 .LOOP => return error.SymLinkLoop,
2049 .MLINK => return error.LinkQuotaExceeded,
2050 .NAMETOOLONG => return error.NameTooLong,
2051 .NOENT => return error.FileNotFound,
2052 .NOTDIR => return error.NotDir,
2053 .NOMEM => return error.SystemResources,
2054 .NOSPC => return error.NoSpaceLeft,
2055 .EXIST => return error.PathAlreadyExists,
2056 .NOTEMPTY => return error.PathAlreadyExists,
2057 .ROFS => return error.ReadOnlyFileSystem,
2058 .XDEV => return error.RenameAcrossMountPoints,
2059 .NOTCAPABLE => return error.AccessDenied,
20592060 else => |err| return unexpectedErrno(err),
20602061 }
20612062}
......@@ -2074,25 +2075,25 @@ pub fn renameatZ(
20742075 }
20752076
20762077 switch (errno(system.renameat(old_dir_fd, old_path, new_dir_fd, new_path))) {
2077 0 => return,
2078 EACCES => return error.AccessDenied,
2079 EPERM => return error.AccessDenied,
2080 EBUSY => return error.FileBusy,
2081 EDQUOT => return error.DiskQuota,
2082 EFAULT => unreachable,
2083 EINVAL => unreachable,
2084 EISDIR => return error.IsDir,
2085 ELOOP => return error.SymLinkLoop,
2086 EMLINK => return error.LinkQuotaExceeded,
2087 ENAMETOOLONG => return error.NameTooLong,
2088 ENOENT => return error.FileNotFound,
2089 ENOTDIR => return error.NotDir,
2090 ENOMEM => return error.SystemResources,
2091 ENOSPC => return error.NoSpaceLeft,
2092 EEXIST => return error.PathAlreadyExists,
2093 ENOTEMPTY => return error.PathAlreadyExists,
2094 EROFS => return error.ReadOnlyFileSystem,
2095 EXDEV => return error.RenameAcrossMountPoints,
2078 .SUCCESS => return,
2079 .ACCES => return error.AccessDenied,
2080 .PERM => return error.AccessDenied,
2081 .BUSY => return error.FileBusy,
2082 .DQUOT => return error.DiskQuota,
2083 .FAULT => unreachable,
2084 .INVAL => unreachable,
2085 .ISDIR => return error.IsDir,
2086 .LOOP => return error.SymLinkLoop,
2087 .MLINK => return error.LinkQuotaExceeded,
2088 .NAMETOOLONG => return error.NameTooLong,
2089 .NOENT => return error.FileNotFound,
2090 .NOTDIR => return error.NotDir,
2091 .NOMEM => return error.SystemResources,
2092 .NOSPC => return error.NoSpaceLeft,
2093 .EXIST => return error.PathAlreadyExists,
2094 .NOTEMPTY => return error.PathAlreadyExists,
2095 .ROFS => return error.ReadOnlyFileSystem,
2096 .XDEV => return error.RenameAcrossMountPoints,
20962097 else => |err| return unexpectedErrno(err),
20972098 }
20982099}
......@@ -2172,22 +2173,22 @@ pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
21722173pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
21732174 _ = mode;
21742175 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {
2175 wasi.ESUCCESS => return,
2176 wasi.EACCES => return error.AccessDenied,
2177 wasi.EBADF => unreachable,
2178 wasi.EPERM => return error.AccessDenied,
2179 wasi.EDQUOT => return error.DiskQuota,
2180 wasi.EEXIST => return error.PathAlreadyExists,
2181 wasi.EFAULT => unreachable,
2182 wasi.ELOOP => return error.SymLinkLoop,
2183 wasi.EMLINK => return error.LinkQuotaExceeded,
2184 wasi.ENAMETOOLONG => return error.NameTooLong,
2185 wasi.ENOENT => return error.FileNotFound,
2186 wasi.ENOMEM => return error.SystemResources,
2187 wasi.ENOSPC => return error.NoSpaceLeft,
2188 wasi.ENOTDIR => return error.NotDir,
2189 wasi.EROFS => return error.ReadOnlyFileSystem,
2190 wasi.ENOTCAPABLE => return error.AccessDenied,
2176 .SUCCESS => return,
2177 .ACCES => return error.AccessDenied,
2178 .BADF => unreachable,
2179 .PERM => return error.AccessDenied,
2180 .DQUOT => return error.DiskQuota,
2181 .EXIST => return error.PathAlreadyExists,
2182 .FAULT => unreachable,
2183 .LOOP => return error.SymLinkLoop,
2184 .MLINK => return error.LinkQuotaExceeded,
2185 .NAMETOOLONG => return error.NameTooLong,
2186 .NOENT => return error.FileNotFound,
2187 .NOMEM => return error.SystemResources,
2188 .NOSPC => return error.NoSpaceLeft,
2189 .NOTDIR => return error.NotDir,
2190 .ROFS => return error.ReadOnlyFileSystem,
2191 .NOTCAPABLE => return error.AccessDenied,
21912192 else => |err| return unexpectedErrno(err),
21922193 }
21932194}
......@@ -2198,21 +2199,21 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirErr
21982199 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);
21992200 }
22002201 switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) {
2201 0 => return,
2202 EACCES => return error.AccessDenied,
2203 EBADF => unreachable,
2204 EPERM => return error.AccessDenied,
2205 EDQUOT => return error.DiskQuota,
2206 EEXIST => return error.PathAlreadyExists,
2207 EFAULT => unreachable,
2208 ELOOP => return error.SymLinkLoop,
2209 EMLINK => return error.LinkQuotaExceeded,
2210 ENAMETOOLONG => return error.NameTooLong,
2211 ENOENT => return error.FileNotFound,
2212 ENOMEM => return error.SystemResources,
2213 ENOSPC => return error.NoSpaceLeft,
2214 ENOTDIR => return error.NotDir,
2215 EROFS => return error.ReadOnlyFileSystem,
2202 .SUCCESS => return,
2203 .ACCES => return error.AccessDenied,
2204 .BADF => unreachable,
2205 .PERM => return error.AccessDenied,
2206 .DQUOT => return error.DiskQuota,
2207 .EXIST => return error.PathAlreadyExists,
2208 .FAULT => unreachable,
2209 .LOOP => return error.SymLinkLoop,
2210 .MLINK => return error.LinkQuotaExceeded,
2211 .NAMETOOLONG => return error.NameTooLong,
2212 .NOENT => return error.FileNotFound,
2213 .NOMEM => return error.SystemResources,
2214 .NOSPC => return error.NoSpaceLeft,
2215 .NOTDIR => return error.NotDir,
2216 .ROFS => return error.ReadOnlyFileSystem,
22162217 else => |err| return unexpectedErrno(err),
22172218 }
22182219}
......@@ -2274,20 +2275,20 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
22742275 return mkdirW(dir_path_w.span(), mode);
22752276 }
22762277 switch (errno(system.mkdir(dir_path, mode))) {
2277 0 => return,
2278 EACCES => return error.AccessDenied,
2279 EPERM => return error.AccessDenied,
2280 EDQUOT => return error.DiskQuota,
2281 EEXIST => return error.PathAlreadyExists,
2282 EFAULT => unreachable,
2283 ELOOP => return error.SymLinkLoop,
2284 EMLINK => return error.LinkQuotaExceeded,
2285 ENAMETOOLONG => return error.NameTooLong,
2286 ENOENT => return error.FileNotFound,
2287 ENOMEM => return error.SystemResources,
2288 ENOSPC => return error.NoSpaceLeft,
2289 ENOTDIR => return error.NotDir,
2290 EROFS => return error.ReadOnlyFileSystem,
2278 .SUCCESS => return,
2279 .ACCES => return error.AccessDenied,
2280 .PERM => return error.AccessDenied,
2281 .DQUOT => return error.DiskQuota,
2282 .EXIST => return error.PathAlreadyExists,
2283 .FAULT => unreachable,
2284 .LOOP => return error.SymLinkLoop,
2285 .MLINK => return error.LinkQuotaExceeded,
2286 .NAMETOOLONG => return error.NameTooLong,
2287 .NOENT => return error.FileNotFound,
2288 .NOMEM => return error.SystemResources,
2289 .NOSPC => return error.NoSpaceLeft,
2290 .NOTDIR => return error.NotDir,
2291 .ROFS => return error.ReadOnlyFileSystem,
22912292 else => |err| return unexpectedErrno(err),
22922293 }
22932294}
......@@ -2346,20 +2347,20 @@ pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {
23462347 return rmdirW(dir_path_w.span());
23472348 }
23482349 switch (errno(system.rmdir(dir_path))) {
2349 0 => return,
2350 EACCES => return error.AccessDenied,
2351 EPERM => return error.AccessDenied,
2352 EBUSY => return error.FileBusy,
2353 EFAULT => unreachable,
2354 EINVAL => unreachable,
2355 ELOOP => return error.SymLinkLoop,
2356 ENAMETOOLONG => return error.NameTooLong,
2357 ENOENT => return error.FileNotFound,
2358 ENOMEM => return error.SystemResources,
2359 ENOTDIR => return error.NotDir,
2360 EEXIST => return error.DirNotEmpty,
2361 ENOTEMPTY => return error.DirNotEmpty,
2362 EROFS => return error.ReadOnlyFileSystem,
2350 .SUCCESS => return,
2351 .ACCES => return error.AccessDenied,
2352 .PERM => return error.AccessDenied,
2353 .BUSY => return error.FileBusy,
2354 .FAULT => unreachable,
2355 .INVAL => unreachable,
2356 .LOOP => return error.SymLinkLoop,
2357 .NAMETOOLONG => return error.NameTooLong,
2358 .NOENT => return error.FileNotFound,
2359 .NOMEM => return error.SystemResources,
2360 .NOTDIR => return error.NotDir,
2361 .EXIST => return error.DirNotEmpty,
2362 .NOTEMPTY => return error.DirNotEmpty,
2363 .ROFS => return error.ReadOnlyFileSystem,
23632364 else => |err| return unexpectedErrno(err),
23642365 }
23652366}
......@@ -2413,15 +2414,15 @@ pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {
24132414 return chdirW(utf16_dir_path[0..len]);
24142415 }
24152416 switch (errno(system.chdir(dir_path))) {
2416 0 => return,
2417 EACCES => return error.AccessDenied,
2418 EFAULT => unreachable,
2419 EIO => return error.FileSystem,
2420 ELOOP => return error.SymLinkLoop,
2421 ENAMETOOLONG => return error.NameTooLong,
2422 ENOENT => return error.FileNotFound,
2423 ENOMEM => return error.SystemResources,
2424 ENOTDIR => return error.NotDir,
2417 .SUCCESS => return,
2418 .ACCES => return error.AccessDenied,
2419 .FAULT => unreachable,
2420 .IO => return error.FileSystem,
2421 .LOOP => return error.SymLinkLoop,
2422 .NAMETOOLONG => return error.NameTooLong,
2423 .NOENT => return error.FileNotFound,
2424 .NOMEM => return error.SystemResources,
2425 .NOTDIR => return error.NotDir,
24252426 else => |err| return unexpectedErrno(err),
24262427 }
24272428}
......@@ -2443,12 +2444,12 @@ pub const FchdirError = error{
24432444pub fn fchdir(dirfd: fd_t) FchdirError!void {
24442445 while (true) {
24452446 switch (errno(system.fchdir(dirfd))) {
2446 0 => return,
2447 EACCES => return error.AccessDenied,
2448 EBADF => unreachable,
2449 ENOTDIR => return error.NotDir,
2450 EINTR => continue,
2451 EIO => return error.FileSystem,
2447 .SUCCESS => return,
2448 .ACCES => return error.AccessDenied,
2449 .BADF => unreachable,
2450 .NOTDIR => return error.NotDir,
2451 .INTR => continue,
2452 .IO => return error.FileSystem,
24522453 else => |err| return unexpectedErrno(err),
24532454 }
24542455 }
......@@ -2501,16 +2502,16 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
25012502 }
25022503 const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len);
25032504 switch (errno(rc)) {
2504 0 => return out_buffer[0..@bitCast(usize, rc)],
2505 EACCES => return error.AccessDenied,
2506 EFAULT => unreachable,
2507 EINVAL => unreachable,
2508 EIO => return error.FileSystem,
2509 ELOOP => return error.SymLinkLoop,
2510 ENAMETOOLONG => return error.NameTooLong,
2511 ENOENT => return error.FileNotFound,
2512 ENOMEM => return error.SystemResources,
2513 ENOTDIR => return error.NotDir,
2505 .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
2506 .ACCES => return error.AccessDenied,
2507 .FAULT => unreachable,
2508 .INVAL => unreachable,
2509 .IO => return error.FileSystem,
2510 .LOOP => return error.SymLinkLoop,
2511 .NAMETOOLONG => return error.NameTooLong,
2512 .NOENT => return error.FileNotFound,
2513 .NOMEM => return error.SystemResources,
2514 .NOTDIR => return error.NotDir,
25142515 else => |err| return unexpectedErrno(err),
25152516 }
25162517}
......@@ -2537,17 +2538,17 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
25372538pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
25382539 var bufused: usize = undefined;
25392540 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 wasi.EACCES => return error.AccessDenied,
2542 wasi.EFAULT => unreachable,
2543 wasi.EINVAL => unreachable,
2544 wasi.EIO => return error.FileSystem,
2545 wasi.ELOOP => return error.SymLinkLoop,
2546 wasi.ENAMETOOLONG => return error.NameTooLong,
2547 wasi.ENOENT => return error.FileNotFound,
2548 wasi.ENOMEM => return error.SystemResources,
2549 wasi.ENOTDIR => return error.NotDir,
2550 wasi.ENOTCAPABLE => return error.AccessDenied,
2541 .SUCCESS => return out_buffer[0..bufused],
2542 .ACCES => return error.AccessDenied,
2543 .FAULT => unreachable,
2544 .INVAL => unreachable,
2545 .IO => return error.FileSystem,
2546 .LOOP => return error.SymLinkLoop,
2547 .NAMETOOLONG => return error.NameTooLong,
2548 .NOENT => return error.FileNotFound,
2549 .NOMEM => return error.SystemResources,
2550 .NOTDIR => return error.NotDir,
2551 .NOTCAPABLE => return error.AccessDenied,
25512552 else => |err| return unexpectedErrno(err),
25522553 }
25532554}
......@@ -2567,16 +2568,16 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read
25672568 }
25682569 const rc = system.readlinkat(dirfd, file_path, out_buffer.ptr, out_buffer.len);
25692570 switch (errno(rc)) {
2570 0 => return out_buffer[0..@bitCast(usize, rc)],
2571 EACCES => return error.AccessDenied,
2572 EFAULT => unreachable,
2573 EINVAL => unreachable,
2574 EIO => return error.FileSystem,
2575 ELOOP => return error.SymLinkLoop,
2576 ENAMETOOLONG => return error.NameTooLong,
2577 ENOENT => return error.FileNotFound,
2578 ENOMEM => return error.SystemResources,
2579 ENOTDIR => return error.NotDir,
2571 .SUCCESS => return out_buffer[0..@bitCast(usize, rc)],
2572 .ACCES => return error.AccessDenied,
2573 .FAULT => unreachable,
2574 .INVAL => unreachable,
2575 .IO => return error.FileSystem,
2576 .LOOP => return error.SymLinkLoop,
2577 .NAMETOOLONG => return error.NameTooLong,
2578 .NOENT => return error.FileNotFound,
2579 .NOMEM => return error.SystemResources,
2580 .NOTDIR => return error.NotDir,
25802581 else => |err| return unexpectedErrno(err),
25812582 }
25822583}
......@@ -2590,58 +2591,58 @@ pub const SetIdError = error{ResourceLimitReached} || SetEidError;
25902591
25912592pub fn setuid(uid: uid_t) SetIdError!void {
25922593 switch (errno(system.setuid(uid))) {
2593 0 => return,
2594 EAGAIN => return error.ResourceLimitReached,
2595 EINVAL => return error.InvalidUserId,
2596 EPERM => return error.PermissionDenied,
2594 .SUCCESS => return,
2595 .AGAIN => return error.ResourceLimitReached,
2596 .INVAL => return error.InvalidUserId,
2597 .PERM => return error.PermissionDenied,
25972598 else => |err| return unexpectedErrno(err),
25982599 }
25992600}
26002601
26012602pub fn seteuid(uid: uid_t) SetEidError!void {
26022603 switch (errno(system.seteuid(uid))) {
2603 0 => return,
2604 EINVAL => return error.InvalidUserId,
2605 EPERM => return error.PermissionDenied,
2604 .SUCCESS => return,
2605 .INVAL => return error.InvalidUserId,
2606 .PERM => return error.PermissionDenied,
26062607 else => |err| return unexpectedErrno(err),
26072608 }
26082609}
26092610
26102611pub fn setreuid(ruid: uid_t, euid: uid_t) SetIdError!void {
26112612 switch (errno(system.setreuid(ruid, euid))) {
2612 0 => return,
2613 EAGAIN => return error.ResourceLimitReached,
2614 EINVAL => return error.InvalidUserId,
2615 EPERM => return error.PermissionDenied,
2613 .SUCCESS => return,
2614 .AGAIN => return error.ResourceLimitReached,
2615 .INVAL => return error.InvalidUserId,
2616 .PERM => return error.PermissionDenied,
26162617 else => |err| return unexpectedErrno(err),
26172618 }
26182619}
26192620
26202621pub fn setgid(gid: gid_t) SetIdError!void {
26212622 switch (errno(system.setgid(gid))) {
2622 0 => return,
2623 EAGAIN => return error.ResourceLimitReached,
2624 EINVAL => return error.InvalidUserId,
2625 EPERM => return error.PermissionDenied,
2623 .SUCCESS => return,
2624 .AGAIN => return error.ResourceLimitReached,
2625 .INVAL => return error.InvalidUserId,
2626 .PERM => return error.PermissionDenied,
26262627 else => |err| return unexpectedErrno(err),
26272628 }
26282629}
26292630
26302631pub fn setegid(uid: uid_t) SetEidError!void {
26312632 switch (errno(system.setegid(uid))) {
2632 0 => return,
2633 EINVAL => return error.InvalidUserId,
2634 EPERM => return error.PermissionDenied,
2633 .SUCCESS => return,
2634 .INVAL => return error.InvalidUserId,
2635 .PERM => return error.PermissionDenied,
26352636 else => |err| return unexpectedErrno(err),
26362637 }
26372638}
26382639
26392640pub fn setregid(rgid: gid_t, egid: gid_t) SetIdError!void {
26402641 switch (errno(system.setregid(rgid, egid))) {
2641 0 => return,
2642 EAGAIN => return error.ResourceLimitReached,
2643 EINVAL => return error.InvalidUserId,
2644 EPERM => return error.PermissionDenied,
2642 .SUCCESS => return,
2643 .AGAIN => return error.ResourceLimitReached,
2644 .INVAL => return error.InvalidUserId,
2645 .PERM => return error.PermissionDenied,
26452646 else => |err| return unexpectedErrno(err),
26462647 }
26472648}
......@@ -2680,9 +2681,10 @@ pub fn isatty(handle: fd_t) bool {
26802681 while (true) {
26812682 var wsz: linux.winsize = undefined;
26822683 const fd = @bitCast(usize, @as(isize, handle));
2683 switch (linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz))) {
2684 0 => return true,
2685 EINTR => continue,
2684 const rc = linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz));
2685 switch (linux.getErrno(rc)) {
2686 .SUCCESS => return true,
2687 .INTR => continue,
26862688 else => return false,
26872689 }
26882690 }
......@@ -2777,22 +2779,22 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
27772779 socket_type;
27782780 const rc = system.socket(domain, filtered_sock_type, protocol);
27792781 switch (errno(rc)) {
2780 0 => {
2782 .SUCCESS => {
27812783 const fd = @intCast(fd_t, rc);
27822784 if (!have_sock_flags) {
27832785 try setSockFlags(fd, socket_type);
27842786 }
27852787 return fd;
27862788 },
2787 EACCES => return error.PermissionDenied,
2788 EAFNOSUPPORT => return error.AddressFamilyNotSupported,
2789 EINVAL => return error.ProtocolFamilyNotAvailable,
2790 EMFILE => return error.ProcessFdQuotaExceeded,
2791 ENFILE => return error.SystemFdQuotaExceeded,
2792 ENOBUFS => return error.SystemResources,
2793 ENOMEM => return error.SystemResources,
2794 EPROTONOSUPPORT => return error.ProtocolNotSupported,
2795 EPROTOTYPE => return error.SocketTypeNotSupported,
2789 .ACCES => return error.PermissionDenied,
2790 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
2791 .INVAL => return error.ProtocolFamilyNotAvailable,
2792 .MFILE => return error.ProcessFdQuotaExceeded,
2793 .NFILE => return error.SystemFdQuotaExceeded,
2794 .NOBUFS => return error.SystemResources,
2795 .NOMEM => return error.SystemResources,
2796 .PROTONOSUPPORT => return error.ProtocolNotSupported,
2797 .PROTOTYPE => return error.SocketTypeNotSupported,
27962798 else => |err| return unexpectedErrno(err),
27972799 }
27982800}
......@@ -2840,12 +2842,12 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {
28402842 .both => SHUT_RDWR,
28412843 });
28422844 switch (errno(rc)) {
2843 0 => return,
2844 EBADF => unreachable,
2845 EINVAL => unreachable,
2846 ENOTCONN => return error.SocketNotConnected,
2847 ENOTSOCK => unreachable,
2848 ENOBUFS => return error.SystemResources,
2845 .SUCCESS => return,
2846 .BADF => unreachable,
2847 .INVAL => unreachable,
2848 .NOTCONN => return error.SocketNotConnected,
2849 .NOTSOCK => unreachable,
2850 .NOBUFS => return error.SystemResources,
28492851 else => |err| return unexpectedErrno(err),
28502852 }
28512853 }
......@@ -2924,20 +2926,20 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi
29242926 } else {
29252927 const rc = system.bind(sock, addr, len);
29262928 switch (errno(rc)) {
2927 0 => return,
2928 EACCES => return error.AccessDenied,
2929 EADDRINUSE => return error.AddressInUse,
2930 EBADF => unreachable, // always a race condition if this error is returned
2931 EINVAL => unreachable, // invalid parameters
2932 ENOTSOCK => unreachable, // invalid `sockfd`
2933 EADDRNOTAVAIL => return error.AddressNotAvailable,
2934 EFAULT => unreachable, // invalid `addr` pointer
2935 ELOOP => return error.SymLinkLoop,
2936 ENAMETOOLONG => return error.NameTooLong,
2937 ENOENT => return error.FileNotFound,
2938 ENOMEM => return error.SystemResources,
2939 ENOTDIR => return error.NotDir,
2940 EROFS => return error.ReadOnlyFileSystem,
2929 .SUCCESS => return,
2930 .ACCES => return error.AccessDenied,
2931 .ADDRINUSE => return error.AddressInUse,
2932 .BADF => unreachable, // always a race condition if this error is returned
2933 .INVAL => unreachable, // invalid parameters
2934 .NOTSOCK => unreachable, // invalid `sockfd`
2935 .ADDRNOTAVAIL => return error.AddressNotAvailable,
2936 .FAULT => unreachable, // invalid `addr` pointer
2937 .LOOP => return error.SymLinkLoop,
2938 .NAMETOOLONG => return error.NameTooLong,
2939 .NOENT => return error.FileNotFound,
2940 .NOMEM => return error.SystemResources,
2941 .NOTDIR => return error.NotDir,
2942 .ROFS => return error.ReadOnlyFileSystem,
29412943 else => |err| return unexpectedErrno(err),
29422944 }
29432945 }
......@@ -2993,11 +2995,11 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void {
29932995 } else {
29942996 const rc = system.listen(sock, backlog);
29952997 switch (errno(rc)) {
2996 0 => return,
2997 EADDRINUSE => return error.AddressInUse,
2998 EBADF => unreachable,
2999 ENOTSOCK => return error.FileDescriptorNotASocket,
3000 EOPNOTSUPP => return error.OperationNotSupported,
2998 .SUCCESS => return,
2999 .ADDRINUSE => return error.AddressInUse,
3000 .BADF => unreachable,
3001 .NOTSOCK => return error.FileDescriptorNotASocket,
3002 .OPNOTSUPP => return error.OperationNotSupported,
30013003 else => |err| return unexpectedErrno(err),
30023004 }
30033005 }
......@@ -3099,23 +3101,23 @@ pub fn accept(
30993101 }
31003102 } else {
31013103 switch (errno(rc)) {
3102 0 => {
3104 .SUCCESS => {
31033105 break @intCast(socket_t, rc);
31043106 },
3105 EINTR => continue,
3106 EAGAIN => return error.WouldBlock,
3107 EBADF => unreachable, // always a race condition
3108 ECONNABORTED => return error.ConnectionAborted,
3109 EFAULT => unreachable,
3110 EINVAL => return error.SocketNotListening,
3111 ENOTSOCK => unreachable,
3112 EMFILE => return error.ProcessFdQuotaExceeded,
3113 ENFILE => return error.SystemFdQuotaExceeded,
3114 ENOBUFS => return error.SystemResources,
3115 ENOMEM => return error.SystemResources,
3116 EOPNOTSUPP => unreachable,
3117 EPROTO => return error.ProtocolFailure,
3118 EPERM => return error.BlockedByFirewall,
3107 .INTR => continue,
3108 .AGAIN => return error.WouldBlock,
3109 .BADF => unreachable, // always a race condition
3110 .CONNABORTED => return error.ConnectionAborted,
3111 .FAULT => unreachable,
3112 .INVAL => return error.SocketNotListening,
3113 .NOTSOCK => unreachable,
3114 .MFILE => return error.ProcessFdQuotaExceeded,
3115 .NFILE => return error.SystemFdQuotaExceeded,
3116 .NOBUFS => return error.SystemResources,
3117 .NOMEM => return error.SystemResources,
3118 .OPNOTSUPP => unreachable,
3119 .PROTO => return error.ProtocolFailure,
3120 .PERM => return error.BlockedByFirewall,
31193121 else => |err| return unexpectedErrno(err),
31203122 }
31213123 }
......@@ -3144,13 +3146,13 @@ pub const EpollCreateError = error{
31443146pub fn epoll_create1(flags: u32) EpollCreateError!i32 {
31453147 const rc = system.epoll_create1(flags);
31463148 switch (errno(rc)) {
3147 0 => return @intCast(i32, rc),
3149 .SUCCESS => return @intCast(i32, rc),
31483150 else => |err| return unexpectedErrno(err),
31493151
3150 EINVAL => unreachable,
3151 EMFILE => return error.ProcessFdQuotaExceeded,
3152 ENFILE => return error.SystemFdQuotaExceeded,
3153 ENOMEM => return error.SystemResources,
3152 .INVAL => unreachable,
3153 .MFILE => return error.ProcessFdQuotaExceeded,
3154 .NFILE => return error.SystemFdQuotaExceeded,
3155 .NOMEM => return error.SystemResources,
31543156 }
31553157}
31563158
......@@ -3183,17 +3185,17 @@ pub const EpollCtlError = error{
31833185pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void {
31843186 const rc = system.epoll_ctl(epfd, op, fd, event);
31853187 switch (errno(rc)) {
3186 0 => return,
3188 .SUCCESS => return,
31873189 else => |err| return unexpectedErrno(err),
31883190
3189 EBADF => unreachable, // always a race condition if this happens
3190 EEXIST => return error.FileDescriptorAlreadyPresentInSet,
3191 EINVAL => unreachable,
3192 ELOOP => return error.OperationCausesCircularLoop,
3193 ENOENT => return error.FileDescriptorNotRegistered,
3194 ENOMEM => return error.SystemResources,
3195 ENOSPC => return error.UserResourceLimitReached,
3196 EPERM => return error.FileDescriptorIncompatibleWithEpoll,
3191 .BADF => unreachable, // always a race condition if this happens
3192 .EXIST => return error.FileDescriptorAlreadyPresentInSet,
3193 .INVAL => unreachable,
3194 .LOOP => return error.OperationCausesCircularLoop,
3195 .NOENT => return error.FileDescriptorNotRegistered,
3196 .NOMEM => return error.SystemResources,
3197 .NOSPC => return error.UserResourceLimitReached,
3198 .PERM => return error.FileDescriptorIncompatibleWithEpoll,
31973199 }
31983200}
31993201
......@@ -3205,11 +3207,11 @@ pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize {
32053207 // TODO get rid of the @intCast
32063208 const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);
32073209 switch (errno(rc)) {
3208 0 => return @intCast(usize, rc),
3209 EINTR => continue,
3210 EBADF => unreachable,
3211 EFAULT => unreachable,
3212 EINVAL => unreachable,
3210 .SUCCESS => return @intCast(usize, rc),
3211 .INTR => continue,
3212 .BADF => unreachable,
3213 .FAULT => unreachable,
3214 .INVAL => unreachable,
32133215 else => unreachable,
32143216 }
32153217 }
......@@ -3224,14 +3226,14 @@ pub const EventFdError = error{
32243226pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {
32253227 const rc = system.eventfd(initval, flags);
32263228 switch (errno(rc)) {
3227 0 => return @intCast(i32, rc),
3229 .SUCCESS => return @intCast(i32, rc),
32283230 else => |err| return unexpectedErrno(err),
32293231
3230 EINVAL => unreachable, // invalid parameters
3231 EMFILE => return error.ProcessFdQuotaExceeded,
3232 ENFILE => return error.SystemFdQuotaExceeded,
3233 ENODEV => return error.SystemResources,
3234 ENOMEM => return error.SystemResources,
3232 .INVAL => unreachable, // invalid parameters
3233 .MFILE => return error.ProcessFdQuotaExceeded,
3234 .NFILE => return error.SystemFdQuotaExceeded,
3235 .NODEV => return error.SystemResources,
3236 .NOMEM => return error.SystemResources,
32353237 }
32363238}
32373239
......@@ -3265,14 +3267,14 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
32653267 } else {
32663268 const rc = system.getsockname(sock, addr, addrlen);
32673269 switch (errno(rc)) {
3268 0 => return,
3270 .SUCCESS => return,
32693271 else => |err| return unexpectedErrno(err),
32703272
3271 EBADF => unreachable, // always a race condition
3272 EFAULT => unreachable,
3273 EINVAL => unreachable, // invalid parameters
3274 ENOTSOCK => return error.FileDescriptorNotASocket,
3275 ENOBUFS => return error.SystemResources,
3273 .BADF => unreachable, // always a race condition
3274 .FAULT => unreachable,
3275 .INVAL => unreachable, // invalid parameters
3276 .NOTSOCK => return error.FileDescriptorNotASocket,
3277 .NOBUFS => return error.SystemResources,
32763278 }
32773279 }
32783280}
......@@ -3294,14 +3296,14 @@ pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
32943296 } else {
32953297 const rc = system.getpeername(sock, addr, addrlen);
32963298 switch (errno(rc)) {
3297 0 => return,
3299 .SUCCESS => return,
32983300 else => |err| return unexpectedErrno(err),
32993301
3300 EBADF => unreachable, // always a race condition
3301 EFAULT => unreachable,
3302 EINVAL => unreachable, // invalid parameters
3303 ENOTSOCK => return error.FileDescriptorNotASocket,
3304 ENOBUFS => return error.SystemResources,
3302 .BADF => unreachable, // always a race condition
3303 .FAULT => unreachable,
3304 .INVAL => unreachable, // invalid parameters
3305 .NOTSOCK => return error.FileDescriptorNotASocket,
3306 .NOBUFS => return error.SystemResources,
33053307 }
33063308 }
33073309}
......@@ -3384,61 +3386,61 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
33843386
33853387 while (true) {
33863388 switch (errno(system.connect(sock, sock_addr, len))) {
3387 0 => return,
3388 EACCES => return error.PermissionDenied,
3389 EPERM => return error.PermissionDenied,
3390 EADDRINUSE => return error.AddressInUse,
3391 EADDRNOTAVAIL => return error.AddressNotAvailable,
3392 EAFNOSUPPORT => return error.AddressFamilyNotSupported,
3393 EAGAIN, EINPROGRESS => return error.WouldBlock,
3394 EALREADY => return error.ConnectionPending,
3395 EBADF => unreachable, // sockfd is not a valid open file descriptor.
3396 ECONNREFUSED => return error.ConnectionRefused,
3397 ECONNRESET => return error.ConnectionResetByPeer,
3398 EFAULT => unreachable, // The socket structure address is outside the user's address space.
3399 EINTR => continue,
3400 EISCONN => unreachable, // The socket is already connected.
3401 ENETUNREACH => return error.NetworkUnreachable,
3402 ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
3403 EPROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
3404 ETIMEDOUT => return error.ConnectionTimedOut,
3405 ENOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist.
3389 .SUCCESS => return,
3390 .ACCES => return error.PermissionDenied,
3391 .PERM => return error.PermissionDenied,
3392 .ADDRINUSE => return error.AddressInUse,
3393 .ADDRNOTAVAIL => return error.AddressNotAvailable,
3394 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
3395 .AGAIN, .INPROGRESS => return error.WouldBlock,
3396 .ALREADY => return error.ConnectionPending,
3397 .BADF => unreachable, // sockfd is not a valid open file descriptor.
3398 .CONNREFUSED => return error.ConnectionRefused,
3399 .CONNRESET => return error.ConnectionResetByPeer,
3400 .FAULT => unreachable, // The socket structure address is outside the user's address space.
3401 .INTR => continue,
3402 .ISCONN => unreachable, // The socket is already connected.
3403 .NETUNREACH => return error.NetworkUnreachable,
3404 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
3405 .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
3406 .TIMEDOUT => return error.ConnectionTimedOut,
3407 .NOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist.
34063408 else => |err| return unexpectedErrno(err),
34073409 }
34083410 }
34093411}
34103412
34113413pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
3412 var err_code: u32 = undefined;
3414 var err_code: i32 = undefined;
34133415 var size: u32 = @sizeOf(u32);
34143416 const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size);
34153417 assert(size == 4);
34163418 switch (errno(rc)) {
3417 0 => switch (err_code) {
3418 0 => return,
3419 EACCES => return error.PermissionDenied,
3420 EPERM => return error.PermissionDenied,
3421 EADDRINUSE => return error.AddressInUse,
3422 EADDRNOTAVAIL => return error.AddressNotAvailable,
3423 EAFNOSUPPORT => return error.AddressFamilyNotSupported,
3424 EAGAIN => return error.SystemResources,
3425 EALREADY => return error.ConnectionPending,
3426 EBADF => unreachable, // sockfd is not a valid open file descriptor.
3427 ECONNREFUSED => return error.ConnectionRefused,
3428 EFAULT => unreachable, // The socket structure address is outside the user's address space.
3429 EISCONN => unreachable, // The socket is already connected.
3430 ENETUNREACH => return error.NetworkUnreachable,
3431 ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
3432 EPROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
3433 ETIMEDOUT => return error.ConnectionTimedOut,
3434 ECONNRESET => return error.ConnectionResetByPeer,
3419 .SUCCESS => switch (@intToEnum(E, err_code)) {
3420 .SUCCESS => return,
3421 .ACCES => return error.PermissionDenied,
3422 .PERM => return error.PermissionDenied,
3423 .ADDRINUSE => return error.AddressInUse,
3424 .ADDRNOTAVAIL => return error.AddressNotAvailable,
3425 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
3426 .AGAIN => return error.SystemResources,
3427 .ALREADY => return error.ConnectionPending,
3428 .BADF => unreachable, // sockfd is not a valid open file descriptor.
3429 .CONNREFUSED => return error.ConnectionRefused,
3430 .FAULT => unreachable, // The socket structure address is outside the user's address space.
3431 .ISCONN => unreachable, // The socket is already connected.
3432 .NETUNREACH => return error.NetworkUnreachable,
3433 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
3434 .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
3435 .TIMEDOUT => return error.ConnectionTimedOut,
3436 .CONNRESET => return error.ConnectionResetByPeer,
34353437 else => |err| return unexpectedErrno(err),
34363438 },
3437 EBADF => 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.
3439 EINVAL => unreachable,
3440 ENOPROTOOPT => unreachable, // The option is unknown at the level indicated.
3441 ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
3439 .BADF => unreachable, // The argument sockfd is not a valid file descriptor.
3440 .FAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.
3441 .INVAL => unreachable,
3442 .NOPROTOOPT => unreachable, // The option is unknown at the level indicated.
3443 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
34423444 else => |err| return unexpectedErrno(err),
34433445 }
34443446}
......@@ -3454,13 +3456,13 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
34543456 while (true) {
34553457 const rc = system.waitpid(pid, &status, if (builtin.link_libc) @intCast(c_int, flags) else flags);
34563458 switch (errno(rc)) {
3457 0 => return .{
3459 .SUCCESS => return .{
34583460 .pid = @intCast(pid_t, rc),
34593461 .status = @bitCast(u32, status),
34603462 },
3461 EINTR => continue,
3462 ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
3463 EINVAL => unreachable, // Invalid flags.
3463 .INTR => continue,
3464 .CHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
3465 .INVAL => unreachable, // Invalid flags.
34643466 else => unreachable,
34653467 }
34663468 }
......@@ -3484,12 +3486,12 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
34843486 if (builtin.os.tag == .wasi and !builtin.link_libc) {
34853487 var stat: wasi.filestat_t = undefined;
34863488 switch (wasi.fd_filestat_get(fd, &stat)) {
3487 wasi.ESUCCESS => return Stat.fromFilestat(stat),
3488 wasi.EINVAL => unreachable,
3489 wasi.EBADF => unreachable, // Always a race condition.
3490 wasi.ENOMEM => return error.SystemResources,
3491 wasi.EACCES => return error.AccessDenied,
3492 wasi.ENOTCAPABLE => return error.AccessDenied,
3489 .SUCCESS => return Stat.fromFilestat(stat),
3490 .INVAL => unreachable,
3491 .BADF => unreachable, // Always a race condition.
3492 .NOMEM => return error.SystemResources,
3493 .ACCES => return error.AccessDenied,
3494 .NOTCAPABLE => return error.AccessDenied,
34933495 else => |err| return unexpectedErrno(err),
34943496 }
34953497 }
......@@ -3504,11 +3506,11 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
35043506
35053507 var stat = mem.zeroes(Stat);
35063508 switch (errno(fstat_sym(fd, &stat))) {
3507 0 => return stat,
3508 EINVAL => unreachable,
3509 EBADF => unreachable, // Always a race condition.
3510 ENOMEM => return error.SystemResources,
3511 EACCES => return error.AccessDenied,
3509 .SUCCESS => return stat,
3510 .INVAL => unreachable,
3511 .BADF => unreachable, // Always a race condition.
3512 .NOMEM => return error.SystemResources,
3513 .ACCES => return error.AccessDenied,
35123514 else => |err| return unexpectedErrno(err),
35133515 }
35143516}
......@@ -3536,16 +3538,16 @@ pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");
35363538pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
35373539 var stat: wasi.filestat_t = undefined;
35383540 switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
3539 wasi.ESUCCESS => return Stat.fromFilestat(stat),
3540 wasi.EINVAL => unreachable,
3541 wasi.EBADF => unreachable, // Always a race condition.
3542 wasi.ENOMEM => return error.SystemResources,
3543 wasi.EACCES => return error.AccessDenied,
3544 wasi.EFAULT => unreachable,
3545 wasi.ENAMETOOLONG => return error.NameTooLong,
3546 wasi.ENOENT => return error.FileNotFound,
3547 wasi.ENOTDIR => return error.FileNotFound,
3548 wasi.ENOTCAPABLE => return error.AccessDenied,
3541 .SUCCESS => return Stat.fromFilestat(stat),
3542 .INVAL => unreachable,
3543 .BADF => unreachable, // Always a race condition.
3544 .NOMEM => return error.SystemResources,
3545 .ACCES => return error.AccessDenied,
3546 .FAULT => unreachable,
3547 .NAMETOOLONG => return error.NameTooLong,
3548 .NOENT => return error.FileNotFound,
3549 .NOTDIR => return error.FileNotFound,
3550 .NOTCAPABLE => return error.AccessDenied,
35493551 else => |err| return unexpectedErrno(err),
35503552 }
35513553}
......@@ -3560,17 +3562,17 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
35603562
35613563 var stat = mem.zeroes(Stat);
35623564 switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) {
3563 0 => return stat,
3564 EINVAL => unreachable,
3565 EBADF => unreachable, // Always a race condition.
3566 ENOMEM => return error.SystemResources,
3567 EACCES => return error.AccessDenied,
3568 EPERM => return error.AccessDenied,
3569 EFAULT => unreachable,
3570 ENAMETOOLONG => return error.NameTooLong,
3571 ELOOP => return error.SymLinkLoop,
3572 ENOENT => return error.FileNotFound,
3573 ENOTDIR => return error.FileNotFound,
3565 .SUCCESS => return stat,
3566 .INVAL => unreachable,
3567 .BADF => unreachable, // Always a race condition.
3568 .NOMEM => return error.SystemResources,
3569 .ACCES => return error.AccessDenied,
3570 .PERM => return error.AccessDenied,
3571 .FAULT => unreachable,
3572 .NAMETOOLONG => return error.NameTooLong,
3573 .LOOP => return error.SymLinkLoop,
3574 .NOENT => return error.FileNotFound,
3575 .NOTDIR => return error.FileNotFound,
35743576 else => |err| return unexpectedErrno(err),
35753577 }
35763578}
......@@ -3586,9 +3588,9 @@ pub const KQueueError = error{
35863588pub fn kqueue() KQueueError!i32 {
35873589 const rc = system.kqueue();
35883590 switch (errno(rc)) {
3589 0 => return @intCast(i32, rc),
3590 EMFILE => return error.ProcessFdQuotaExceeded,
3591 ENFILE => return error.SystemFdQuotaExceeded,
3591 .SUCCESS => return @intCast(i32, rc),
3592 .MFILE => return error.ProcessFdQuotaExceeded,
3593 .NFILE => return error.SystemFdQuotaExceeded,
35923594 else => |err| return unexpectedErrno(err),
35933595 }
35943596}
......@@ -3627,15 +3629,15 @@ pub fn kevent(
36273629 timeout,
36283630 );
36293631 switch (errno(rc)) {
3630 0 => return @intCast(usize, rc),
3631 EACCES => return error.AccessDenied,
3632 EFAULT => unreachable,
3633 EBADF => unreachable, // Always a race condition.
3634 EINTR => continue,
3635 EINVAL => unreachable,
3636 ENOENT => return error.EventNotFound,
3637 ENOMEM => return error.SystemResources,
3638 ESRCH => return error.ProcessNotFound,
3632 .SUCCESS => return @intCast(usize, rc),
3633 .ACCES => return error.AccessDenied,
3634 .FAULT => unreachable,
3635 .BADF => unreachable, // Always a race condition.
3636 .INTR => continue,
3637 .INVAL => unreachable,
3638 .NOENT => return error.EventNotFound,
3639 .NOMEM => return error.SystemResources,
3640 .SRCH => return error.ProcessNotFound,
36393641 else => unreachable,
36403642 }
36413643 }
......@@ -3651,11 +3653,11 @@ pub const INotifyInitError = error{
36513653pub fn inotify_init1(flags: u32) INotifyInitError!i32 {
36523654 const rc = system.inotify_init1(flags);
36533655 switch (errno(rc)) {
3654 0 => return @intCast(i32, rc),
3655 EINVAL => unreachable,
3656 EMFILE => return error.ProcessFdQuotaExceeded,
3657 ENFILE => return error.SystemFdQuotaExceeded,
3658 ENOMEM => return error.SystemResources,
3656 .SUCCESS => return @intCast(i32, rc),
3657 .INVAL => unreachable,
3658 .MFILE => return error.ProcessFdQuotaExceeded,
3659 .NFILE => return error.SystemFdQuotaExceeded,
3660 .NOMEM => return error.SystemResources,
36593661 else => |err| return unexpectedErrno(err),
36603662 }
36613663}
......@@ -3681,16 +3683,16 @@ pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add
36813683pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
36823684 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
36833685 switch (errno(rc)) {
3684 0 => return @intCast(i32, rc),
3685 EACCES => return error.AccessDenied,
3686 EBADF => unreachable,
3687 EFAULT => unreachable,
3688 EINVAL => unreachable,
3689 ENAMETOOLONG => return error.NameTooLong,
3690 ENOENT => return error.FileNotFound,
3691 ENOMEM => return error.SystemResources,
3692 ENOSPC => return error.UserResourceLimitReached,
3693 ENOTDIR => return error.NotDir,
3686 .SUCCESS => return @intCast(i32, rc),
3687 .ACCES => return error.AccessDenied,
3688 .BADF => unreachable,
3689 .FAULT => unreachable,
3690 .INVAL => unreachable,
3691 .NAMETOOLONG => return error.NameTooLong,
3692 .NOENT => return error.FileNotFound,
3693 .NOMEM => return error.SystemResources,
3694 .NOSPC => return error.UserResourceLimitReached,
3695 .NOTDIR => return error.NotDir,
36943696 else => |err| return unexpectedErrno(err),
36953697 }
36963698}
......@@ -3698,9 +3700,9 @@ pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) I
36983700/// remove an existing watch from an inotify instance
36993701pub fn inotify_rm_watch(inotify_fd: i32, wd: i32) void {
37003702 switch (errno(system.inotify_rm_watch(inotify_fd, wd))) {
3701 0 => return,
3702 EBADF => unreachable,
3703 EINVAL => unreachable,
3703 .SUCCESS => return,
3704 .BADF => unreachable,
3705 .INVAL => unreachable,
37043706 else => unreachable,
37053707 }
37063708}
......@@ -3723,10 +3725,10 @@ pub const MProtectError = error{
37233725pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void {
37243726 assert(mem.isAligned(memory.len, mem.page_size));
37253727 switch (errno(system.mprotect(memory.ptr, memory.len, protection))) {
3726 0 => return,
3727 EINVAL => unreachable,
3728 EACCES => return error.AccessDenied,
3729 ENOMEM => return error.OutOfMemory,
3728 .SUCCESS => return,
3729 .INVAL => unreachable,
3730 .ACCES => return error.AccessDenied,
3731 .NOMEM => return error.OutOfMemory,
37303732 else => |err| return unexpectedErrno(err),
37313733 }
37323734}
......@@ -3736,9 +3738,9 @@ pub const ForkError = error{SystemResources} || UnexpectedError;
37363738pub fn fork() ForkError!pid_t {
37373739 const rc = system.fork();
37383740 switch (errno(rc)) {
3739 0 => return @intCast(pid_t, rc),
3740 EAGAIN => return error.SystemResources,
3741 ENOMEM => return error.SystemResources,
3741 .SUCCESS => return @intCast(pid_t, rc),
3742 .AGAIN => return error.SystemResources,
3743 .NOMEM => return error.SystemResources,
37423744 else => |err| return unexpectedErrno(err),
37433745 }
37443746}
......@@ -3782,22 +3784,23 @@ pub fn mmap(
37823784 const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);
37833785 const err = if (builtin.link_libc) blk: {
37843786 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().*);
37863788 } else blk: {
37873789 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];
37893791 break :blk err;
37903792 };
37913793 switch (err) {
3792 ETXTBSY => return error.AccessDenied,
3793 EACCES => return error.AccessDenied,
3794 EPERM => return error.PermissionDenied,
3795 EAGAIN => return error.LockedMemoryLimitExceeded,
3796 EBADF => unreachable, // Always a race condition.
3797 EOVERFLOW => unreachable, // The number of pages used for length + offset would overflow.
3798 ENODEV => return error.MemoryMappingNotSupported,
3799 EINVAL => unreachable, // Invalid parameters to mmap()
3800 ENOMEM => return error.OutOfMemory,
3794 .SUCCESS => unreachable,
3795 .TXTBSY => return error.AccessDenied,
3796 .ACCES => return error.AccessDenied,
3797 .PERM => return error.PermissionDenied,
3798 .AGAIN => return error.LockedMemoryLimitExceeded,
3799 .BADF => unreachable, // Always a race condition.
3800 .OVERFLOW => unreachable, // The number of pages used for length + offset would overflow.
3801 .NODEV => return error.MemoryMappingNotSupported,
3802 .INVAL => unreachable, // Invalid parameters to mmap()
3803 .NOMEM => return error.OutOfMemory,
38013804 else => return unexpectedErrno(err),
38023805 }
38033806}
......@@ -3810,9 +3813,9 @@ pub fn mmap(
38103813/// * The Windows function, VirtualFree, has this restriction.
38113814pub fn munmap(memory: []align(mem.page_size) const u8) void {
38123815 switch (errno(system.munmap(memory.ptr, memory.len))) {
3813 0 => return,
3814 EINVAL => unreachable, // Invalid parameters.
3815 ENOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping.
3816 .SUCCESS => return,
3817 .INVAL => unreachable, // Invalid parameters.
3818 .NOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping.
38163819 else => unreachable,
38173820 }
38183821}
......@@ -3854,18 +3857,18 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
38543857 return;
38553858 }
38563859 switch (errno(system.access(path, mode))) {
3857 0 => return,
3858 EACCES => return error.PermissionDenied,
3859 EROFS => return error.ReadOnlyFileSystem,
3860 ELOOP => return error.SymLinkLoop,
3861 ETXTBSY => return error.FileBusy,
3862 ENOTDIR => return error.FileNotFound,
3863 ENOENT => return error.FileNotFound,
3864 ENAMETOOLONG => return error.NameTooLong,
3865 EINVAL => unreachable,
3866 EFAULT => unreachable,
3867 EIO => return error.InputOutput,
3868 ENOMEM => return error.SystemResources,
3860 .SUCCESS => return,
3861 .ACCES => return error.PermissionDenied,
3862 .ROFS => return error.ReadOnlyFileSystem,
3863 .LOOP => return error.SymLinkLoop,
3864 .TXTBSY => return error.FileBusy,
3865 .NOTDIR => return error.FileNotFound,
3866 .NOENT => return error.FileNotFound,
3867 .NAMETOOLONG => return error.NameTooLong,
3868 .INVAL => unreachable,
3869 .FAULT => unreachable,
3870 .IO => return error.InputOutput,
3871 .NOMEM => return error.SystemResources,
38693872 else => |err| return unexpectedErrno(err),
38703873 }
38713874}
......@@ -3905,18 +3908,18 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
39053908 return faccessatW(dirfd, path_w.span().ptr, mode, flags);
39063909 }
39073910 switch (errno(system.faccessat(dirfd, path, mode, flags))) {
3908 0 => return,
3909 EACCES => return error.PermissionDenied,
3910 EROFS => return error.ReadOnlyFileSystem,
3911 ELOOP => return error.SymLinkLoop,
3912 ETXTBSY => return error.FileBusy,
3913 ENOTDIR => return error.FileNotFound,
3914 ENOENT => return error.FileNotFound,
3915 ENAMETOOLONG => return error.NameTooLong,
3916 EINVAL => unreachable,
3917 EFAULT => unreachable,
3918 EIO => return error.InputOutput,
3919 ENOMEM => return error.SystemResources,
3911 .SUCCESS => return,
3912 .ACCES => return error.PermissionDenied,
3913 .ROFS => return error.ReadOnlyFileSystem,
3914 .LOOP => return error.SymLinkLoop,
3915 .TXTBSY => return error.FileBusy,
3916 .NOTDIR => return error.FileNotFound,
3917 .NOENT => return error.FileNotFound,
3918 .NAMETOOLONG => return error.NameTooLong,
3919 .INVAL => unreachable,
3920 .FAULT => unreachable,
3921 .IO => return error.InputOutput,
3922 .NOMEM => return error.SystemResources,
39203923 else => |err| return unexpectedErrno(err),
39213924 }
39223925}
......@@ -3972,11 +3975,11 @@ pub const PipeError = error{
39723975pub fn pipe() PipeError![2]fd_t {
39733976 var fds: [2]fd_t = undefined;
39743977 switch (errno(system.pipe(&fds))) {
3975 0 => return fds,
3976 EINVAL => unreachable, // Invalid parameters to pipe()
3977 EFAULT => unreachable, // Invalid fds pointer
3978 ENFILE => return error.SystemFdQuotaExceeded,
3979 EMFILE => return error.ProcessFdQuotaExceeded,
3978 .SUCCESS => return fds,
3979 .INVAL => unreachable, // Invalid parameters to pipe()
3980 .FAULT => unreachable, // Invalid fds pointer
3981 .NFILE => return error.SystemFdQuotaExceeded,
3982 .MFILE => return error.ProcessFdQuotaExceeded,
39803983 else => |err| return unexpectedErrno(err),
39813984 }
39823985}
......@@ -3985,11 +3988,11 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
39853988 if (@hasDecl(system, "pipe2")) {
39863989 var fds: [2]fd_t = undefined;
39873990 switch (errno(system.pipe2(&fds, flags))) {
3988 0 => return fds,
3989 EINVAL => unreachable, // Invalid flags
3990 EFAULT => unreachable, // Invalid fds pointer
3991 ENFILE => return error.SystemFdQuotaExceeded,
3992 EMFILE => return error.ProcessFdQuotaExceeded,
3991 .SUCCESS => return fds,
3992 .INVAL => unreachable, // Invalid flags
3993 .FAULT => unreachable, // Invalid fds pointer
3994 .NFILE => return error.SystemFdQuotaExceeded,
3995 .MFILE => return error.ProcessFdQuotaExceeded,
39933996 else => |err| return unexpectedErrno(err),
39943997 }
39953998 }
......@@ -4008,9 +4011,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
40084011 if (flags & O_CLOEXEC != 0) {
40094012 for (fds) |fd| {
40104013 switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) {
4011 0 => {},
4012 EINVAL => unreachable, // Invalid flags
4013 EBADF => unreachable, // Always a race condition
4014 .SUCCESS => {},
4015 .INVAL => unreachable, // Invalid flags
4016 .BADF => unreachable, // Always a race condition
40144017 else => |err| return unexpectedErrno(err),
40154018 }
40164019 }
......@@ -4021,9 +4024,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
40214024 if (new_flags != 0) {
40224025 for (fds) |fd| {
40234026 switch (errno(system.fcntl(fd, F_SETFL, new_flags))) {
4024 0 => {},
4025 EINVAL => unreachable, // Invalid flags
4026 EBADF => unreachable, // Always a race condition
4027 .SUCCESS => {},
4028 .INVAL => unreachable, // Invalid flags
4029 .BADF => unreachable, // Always a race condition
40274030 else => |err| return unexpectedErrno(err),
40284031 }
40294032 }
......@@ -4055,11 +4058,11 @@ pub fn sysctl(
40554058
40564059 const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong;
40574060 switch (errno(system.sysctl(name.ptr, name_len, oldp, oldlenp, newp, newlen))) {
4058 0 => return,
4059 EFAULT => unreachable,
4060 EPERM => return error.PermissionDenied,
4061 ENOMEM => return error.SystemResources,
4062 ENOENT => return error.UnknownName,
4061 .SUCCESS => return,
4062 .FAULT => unreachable,
4063 .PERM => return error.PermissionDenied,
4064 .NOMEM => return error.SystemResources,
4065 .NOENT => return error.UnknownName,
40634066 else => |err| return unexpectedErrno(err),
40644067 }
40654068}
......@@ -4081,19 +4084,19 @@ pub fn sysctlbynameZ(
40814084 }
40824085
40834086 switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) {
4084 0 => return,
4085 EFAULT => unreachable,
4086 EPERM => return error.PermissionDenied,
4087 ENOMEM => return error.SystemResources,
4088 ENOENT => return error.UnknownName,
4087 .SUCCESS => return,
4088 .FAULT => unreachable,
4089 .PERM => return error.PermissionDenied,
4090 .NOMEM => return error.SystemResources,
4091 .NOENT => return error.UnknownName,
40894092 else => |err| return unexpectedErrno(err),
40904093 }
40914094}
40924095
40934096pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
40944097 switch (errno(system.gettimeofday(tv, tz))) {
4095 0 => return,
4096 EINVAL => unreachable,
4098 .SUCCESS => return,
4099 .INVAL => unreachable,
40974100 else => unreachable,
40984101 }
40994102}
......@@ -4111,12 +4114,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
41114114 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
41124115 var result: u64 = undefined;
41134116 switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) {
4114 0 => return,
4115 EBADF => unreachable, // always a race condition
4116 EINVAL => return error.Unseekable,
4117 EOVERFLOW => return error.Unseekable,
4118 ESPIPE => return error.Unseekable,
4119 ENXIO => return error.Unseekable,
4117 .SUCCESS => return,
4118 .BADF => unreachable, // always a race condition
4119 .INVAL => return error.Unseekable,
4120 .OVERFLOW => return error.Unseekable,
4121 .SPIPE => return error.Unseekable,
4122 .NXIO => return error.Unseekable,
41204123 else => |err| return unexpectedErrno(err),
41214124 }
41224125 }
......@@ -4126,13 +4129,13 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
41264129 if (builtin.os.tag == .wasi and !builtin.link_libc) {
41274130 var new_offset: wasi.filesize_t = undefined;
41284131 switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), wasi.WHENCE_SET, &new_offset)) {
4129 wasi.ESUCCESS => return,
4130 wasi.EBADF => unreachable, // always a race condition
4131 wasi.EINVAL => return error.Unseekable,
4132 wasi.EOVERFLOW => return error.Unseekable,
4133 wasi.ESPIPE => return error.Unseekable,
4134 wasi.ENXIO => return error.Unseekable,
4135 wasi.ENOTCAPABLE => return error.AccessDenied,
4132 .SUCCESS => return,
4133 .BADF => unreachable, // always a race condition
4134 .INVAL => return error.Unseekable,
4135 .OVERFLOW => return error.Unseekable,
4136 .SPIPE => return error.Unseekable,
4137 .NXIO => return error.Unseekable,
4138 .NOTCAPABLE => return error.AccessDenied,
41364139 else => |err| return unexpectedErrno(err),
41374140 }
41384141 }
......@@ -4144,12 +4147,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
41444147
41454148 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
41464149 switch (errno(lseek_sym(fd, ioffset, SEEK_SET))) {
4147 0 => return,
4148 EBADF => unreachable, // always a race condition
4149 EINVAL => return error.Unseekable,
4150 EOVERFLOW => return error.Unseekable,
4151 ESPIPE => return error.Unseekable,
4152 ENXIO => return error.Unseekable,
4150 .SUCCESS => return,
4151 .BADF => unreachable, // always a race condition
4152 .INVAL => return error.Unseekable,
4153 .OVERFLOW => return error.Unseekable,
4154 .SPIPE => return error.Unseekable,
4155 .NXIO => return error.Unseekable,
41534156 else => |err| return unexpectedErrno(err),
41544157 }
41554158}
......@@ -4159,12 +4162,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
41594162 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
41604163 var result: u64 = undefined;
41614164 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) {
4162 0 => return,
4163 EBADF => unreachable, // always a race condition
4164 EINVAL => return error.Unseekable,
4165 EOVERFLOW => return error.Unseekable,
4166 ESPIPE => return error.Unseekable,
4167 ENXIO => return error.Unseekable,
4165 .SUCCESS => return,
4166 .BADF => unreachable, // always a race condition
4167 .INVAL => return error.Unseekable,
4168 .OVERFLOW => return error.Unseekable,
4169 .SPIPE => return error.Unseekable,
4170 .NXIO => return error.Unseekable,
41684171 else => |err| return unexpectedErrno(err),
41694172 }
41704173 }
......@@ -4174,13 +4177,13 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
41744177 if (builtin.os.tag == .wasi and !builtin.link_libc) {
41754178 var new_offset: wasi.filesize_t = undefined;
41764179 switch (wasi.fd_seek(fd, offset, wasi.WHENCE_CUR, &new_offset)) {
4177 wasi.ESUCCESS => return,
4178 wasi.EBADF => unreachable, // always a race condition
4179 wasi.EINVAL => return error.Unseekable,
4180 wasi.EOVERFLOW => return error.Unseekable,
4181 wasi.ESPIPE => return error.Unseekable,
4182 wasi.ENXIO => return error.Unseekable,
4183 wasi.ENOTCAPABLE => return error.AccessDenied,
4180 .SUCCESS => return,
4181 .BADF => unreachable, // always a race condition
4182 .INVAL => return error.Unseekable,
4183 .OVERFLOW => return error.Unseekable,
4184 .SPIPE => return error.Unseekable,
4185 .NXIO => return error.Unseekable,
4186 .NOTCAPABLE => return error.AccessDenied,
41844187 else => |err| return unexpectedErrno(err),
41854188 }
41864189 }
......@@ -4191,12 +4194,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
41914194
41924195 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
41934196 switch (errno(lseek_sym(fd, ioffset, SEEK_CUR))) {
4194 0 => return,
4195 EBADF => unreachable, // always a race condition
4196 EINVAL => return error.Unseekable,
4197 EOVERFLOW => return error.Unseekable,
4198 ESPIPE => return error.Unseekable,
4199 ENXIO => return error.Unseekable,
4197 .SUCCESS => return,
4198 .BADF => unreachable, // always a race condition
4199 .INVAL => return error.Unseekable,
4200 .OVERFLOW => return error.Unseekable,
4201 .SPIPE => return error.Unseekable,
4202 .NXIO => return error.Unseekable,
42004203 else => |err| return unexpectedErrno(err),
42014204 }
42024205}
......@@ -4206,12 +4209,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
42064209 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
42074210 var result: u64 = undefined;
42084211 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) {
4209 0 => return,
4210 EBADF => unreachable, // always a race condition
4211 EINVAL => return error.Unseekable,
4212 EOVERFLOW => return error.Unseekable,
4213 ESPIPE => return error.Unseekable,
4214 ENXIO => return error.Unseekable,
4212 .SUCCESS => return,
4213 .BADF => unreachable, // always a race condition
4214 .INVAL => return error.Unseekable,
4215 .OVERFLOW => return error.Unseekable,
4216 .SPIPE => return error.Unseekable,
4217 .NXIO => return error.Unseekable,
42154218 else => |err| return unexpectedErrno(err),
42164219 }
42174220 }
......@@ -4221,13 +4224,13 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
42214224 if (builtin.os.tag == .wasi and !builtin.link_libc) {
42224225 var new_offset: wasi.filesize_t = undefined;
42234226 switch (wasi.fd_seek(fd, offset, wasi.WHENCE_END, &new_offset)) {
4224 wasi.ESUCCESS => return,
4225 wasi.EBADF => unreachable, // always a race condition
4226 wasi.EINVAL => return error.Unseekable,
4227 wasi.EOVERFLOW => return error.Unseekable,
4228 wasi.ESPIPE => return error.Unseekable,
4229 wasi.ENXIO => return error.Unseekable,
4230 wasi.ENOTCAPABLE => return error.AccessDenied,
4227 .SUCCESS => return,
4228 .BADF => unreachable, // always a race condition
4229 .INVAL => return error.Unseekable,
4230 .OVERFLOW => return error.Unseekable,
4231 .SPIPE => return error.Unseekable,
4232 .NXIO => return error.Unseekable,
4233 .NOTCAPABLE => return error.AccessDenied,
42314234 else => |err| return unexpectedErrno(err),
42324235 }
42334236 }
......@@ -4238,12 +4241,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
42384241
42394242 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
42404243 switch (errno(lseek_sym(fd, ioffset, SEEK_END))) {
4241 0 => return,
4242 EBADF => unreachable, // always a race condition
4243 EINVAL => return error.Unseekable,
4244 EOVERFLOW => return error.Unseekable,
4245 ESPIPE => return error.Unseekable,
4246 ENXIO => return error.Unseekable,
4244 .SUCCESS => return,
4245 .BADF => unreachable, // always a race condition
4246 .INVAL => return error.Unseekable,
4247 .OVERFLOW => return error.Unseekable,
4248 .SPIPE => return error.Unseekable,
4249 .NXIO => return error.Unseekable,
42474250 else => |err| return unexpectedErrno(err),
42484251 }
42494252}
......@@ -4253,12 +4256,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
42534256 if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
42544257 var result: u64 = undefined;
42554258 switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) {
4256 0 => return result,
4257 EBADF => unreachable, // always a race condition
4258 EINVAL => return error.Unseekable,
4259 EOVERFLOW => return error.Unseekable,
4260 ESPIPE => return error.Unseekable,
4261 ENXIO => return error.Unseekable,
4259 .SUCCESS => return result,
4260 .BADF => unreachable, // always a race condition
4261 .INVAL => return error.Unseekable,
4262 .OVERFLOW => return error.Unseekable,
4263 .SPIPE => return error.Unseekable,
4264 .NXIO => return error.Unseekable,
42624265 else => |err| return unexpectedErrno(err),
42634266 }
42644267 }
......@@ -4268,13 +4271,13 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
42684271 if (builtin.os.tag == .wasi and !builtin.link_libc) {
42694272 var new_offset: wasi.filesize_t = undefined;
42704273 switch (wasi.fd_seek(fd, 0, wasi.WHENCE_CUR, &new_offset)) {
4271 wasi.ESUCCESS => return new_offset,
4272 wasi.EBADF => unreachable, // always a race condition
4273 wasi.EINVAL => return error.Unseekable,
4274 wasi.EOVERFLOW => return error.Unseekable,
4275 wasi.ESPIPE => return error.Unseekable,
4276 wasi.ENXIO => return error.Unseekable,
4277 wasi.ENOTCAPABLE => return error.AccessDenied,
4274 .SUCCESS => return new_offset,
4275 .BADF => unreachable, // always a race condition
4276 .INVAL => return error.Unseekable,
4277 .OVERFLOW => return error.Unseekable,
4278 .SPIPE => return error.Unseekable,
4279 .NXIO => return error.Unseekable,
4280 .NOTCAPABLE => return error.AccessDenied,
42784281 else => |err| return unexpectedErrno(err),
42794282 }
42804283 }
......@@ -4285,12 +4288,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
42854288
42864289 const rc = lseek_sym(fd, 0, SEEK_CUR);
42874290 switch (errno(rc)) {
4288 0 => return @bitCast(u64, rc),
4289 EBADF => unreachable, // always a race condition
4290 EINVAL => return error.Unseekable,
4291 EOVERFLOW => return error.Unseekable,
4292 ESPIPE => return error.Unseekable,
4293 ENXIO => return error.Unseekable,
4291 .SUCCESS => return @bitCast(u64, rc),
4292 .BADF => unreachable, // always a race condition
4293 .INVAL => return error.Unseekable,
4294 .OVERFLOW => return error.Unseekable,
4295 .SPIPE => return error.Unseekable,
4296 .NXIO => return error.Unseekable,
42944297 else => |err| return unexpectedErrno(err),
42954298 }
42964299}
......@@ -4306,15 +4309,15 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
43064309 while (true) {
43074310 const rc = system.fcntl(fd, cmd, arg);
43084311 switch (errno(rc)) {
4309 0 => return @intCast(usize, rc),
4310 EINTR => continue,
4311 EACCES => return error.Locked,
4312 EBADF => unreachable,
4313 EBUSY => return error.FileBusy,
4314 EINVAL => unreachable, // invalid parameters
4315 EPERM => return error.PermissionDenied,
4316 EMFILE => return error.ProcessFdQuotaExceeded,
4317 ENOTDIR => unreachable, // invalid parameter
4312 .SUCCESS => return @intCast(usize, rc),
4313 .INTR => continue,
4314 .ACCES => return error.Locked,
4315 .BADF => unreachable,
4316 .BUSY => return error.FileBusy,
4317 .INVAL => unreachable, // invalid parameters
4318 .PERM => return error.PermissionDenied,
4319 .MFILE => return error.ProcessFdQuotaExceeded,
4320 .NOTDIR => unreachable, // invalid parameter
43184321 else => |err| return unexpectedErrno(err),
43194322 }
43204323 }
......@@ -4381,12 +4384,12 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void {
43814384 while (true) {
43824385 const rc = system.flock(fd, operation);
43834386 switch (errno(rc)) {
4384 0 => return,
4385 EBADF => unreachable,
4386 EINTR => continue,
4387 EINVAL => unreachable, // invalid parameters
4388 ENOLCK => return error.SystemResources,
4389 EWOULDBLOCK => return error.WouldBlock, // TODO: integrate with async instead of just returning an error
4387 .SUCCESS => return,
4388 .BADF => unreachable,
4389 .INTR => continue,
4390 .INVAL => unreachable, // invalid parameters
4391 .NOLCK => return error.SystemResources,
4392 .AGAIN => return error.WouldBlock, // TODO: integrate with async instead of just returning an error
43904393 else => |err| return unexpectedErrno(err),
43914394 }
43924395 }
......@@ -4456,17 +4459,18 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
44564459
44574460 return getFdPath(fd, out_buffer);
44584461 }
4459 const result_path = std.c.realpath(pathname, out_buffer) orelse switch (std.c._errno().*) {
4460 EINVAL => unreachable,
4461 EBADF => unreachable,
4462 EFAULT => unreachable,
4463 EACCES => return error.AccessDenied,
4464 ENOENT => return error.FileNotFound,
4465 ENOTSUP => return error.NotSupported,
4466 ENOTDIR => return error.NotDir,
4467 ENAMETOOLONG => return error.NameTooLong,
4468 ELOOP => return error.SymLinkLoop,
4469 EIO => return error.InputOutput,
4462 const result_path = std.c.realpath(pathname, out_buffer) orelse switch (@intToEnum(E, std.c._errno().*)) {
4463 .SUCCESS => unreachable,
4464 .INVAL => unreachable,
4465 .BADF => unreachable,
4466 .FAULT => unreachable,
4467 .ACCES => return error.AccessDenied,
4468 .NOENT => return error.FileNotFound,
4469 .OPNOTSUPP => return error.NotSupported,
4470 .NOTDIR => return error.NotDir,
4471 .NAMETOOLONG => return error.NameTooLong,
4472 .LOOP => return error.SymLinkLoop,
4473 .IO => return error.InputOutput,
44704474 else => |err| return unexpectedErrno(err),
44714475 };
44724476 return mem.spanZ(result_path);
......@@ -4528,8 +4532,8 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
45284532 // the path to the file descriptor.
45294533 @memset(out_buffer, 0, MAX_PATH_BYTES);
45304534 switch (errno(system.fcntl(fd, F_GETPATH, out_buffer))) {
4531 0 => {},
4532 EBADF => return error.FileNotFound,
4535 .SUCCESS => {},
4536 .BADF => return error.FileNotFound,
45334537 // TODO man pages for fcntl on macOS don't really tell you what
45344538 // errno values to expect when command is F_GETPATH...
45354539 else => |err| return unexpectedErrno(err),
......@@ -4562,13 +4566,13 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
45624566 var rem: timespec = undefined;
45634567 while (true) {
45644568 switch (errno(system.nanosleep(&req, &rem))) {
4565 EFAULT => unreachable,
4566 EINVAL => {
4569 .FAULT => unreachable,
4570 .INVAL => {
45674571 // Sometimes Darwin returns EINVAL for no reason.
45684572 // We treat it as a spurious wakeup.
45694573 return;
45704574 },
4571 EINTR => {
4575 .INTR => {
45724576 req = rem;
45734577 continue;
45744578 },
......@@ -4668,13 +4672,13 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
46684672 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
46694673 var ts: timestamp_t = undefined;
46704674 switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) {
4671 0 => {
4675 .SUCCESS => {
46724676 tp.* = .{
46734677 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),
46744678 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),
46754679 };
46764680 },
4677 EINVAL => return error.UnsupportedClock,
4681 .INVAL => return error.UnsupportedClock,
46784682 else => |err| return unexpectedErrno(err),
46794683 }
46804684 return;
......@@ -4698,9 +4702,9 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
46984702 }
46994703
47004704 switch (errno(system.clock_gettime(clk_id, tp))) {
4701 0 => return,
4702 EFAULT => unreachable,
4703 EINVAL => return error.UnsupportedClock,
4705 .SUCCESS => return,
4706 .FAULT => unreachable,
4707 .INVAL => return error.UnsupportedClock,
47044708 else => |err| return unexpectedErrno(err),
47054709 }
47064710}
......@@ -4709,20 +4713,20 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
47094713 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {
47104714 var ts: timestamp_t = undefined;
47114715 switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) {
4712 0 => res.* = .{
4716 .SUCCESS => res.* = .{
47134717 .tv_sec = @intCast(i64, ts / std.time.ns_per_s),
47144718 .tv_nsec = @intCast(isize, ts % std.time.ns_per_s),
47154719 },
4716 EINVAL => return error.UnsupportedClock,
4720 .INVAL => return error.UnsupportedClock,
47174721 else => |err| return unexpectedErrno(err),
47184722 }
47194723 return;
47204724 }
47214725
47224726 switch (errno(system.clock_getres(clk_id, res))) {
4723 0 => return,
4724 EFAULT => unreachable,
4725 EINVAL => return error.UnsupportedClock,
4727 .SUCCESS => return,
4728 .FAULT => unreachable,
4729 .INVAL => return error.UnsupportedClock,
47264730 else => |err| return unexpectedErrno(err),
47274731 }
47284732}
......@@ -4732,11 +4736,11 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
47324736pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
47334737 var set: cpu_set_t = undefined;
47344738 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
4735 0 => return set,
4736 EFAULT => unreachable,
4737 EINVAL => unreachable,
4738 ESRCH => unreachable,
4739 EPERM => return error.PermissionDenied,
4739 .SUCCESS => return set,
4740 .FAULT => unreachable,
4741 .INVAL => unreachable,
4742 .SRCH => unreachable,
4743 .PERM => return error.PermissionDenied,
47404744 else => |err| return unexpectedErrno(err),
47414745 }
47424746}
......@@ -4768,13 +4772,9 @@ pub const UnexpectedError = error{
47684772
47694773/// Call this when you made a syscall or something that sets errno
47704774/// and you get an unexpected error.
4771pub fn unexpectedErrno(err: anytype) UnexpectedError {
4772 if (@typeInfo(@TypeOf(err)) != .Int) {
4773 @compileError("err is expected to be an integer");
4774 }
4775
4775pub fn unexpectedErrno(err: E) UnexpectedError {
47764776 if (unexpected_error_tracing) {
4777 std.debug.warn("unexpected errno: {d}\n", .{err});
4777 std.debug.warn("unexpected errno: {d}\n", .{@enumToInt(err)});
47784778 std.debug.dumpCurrentStackTrace(null);
47794779 }
47804780 return error.Unexpected;
......@@ -4790,11 +4790,11 @@ pub const SigaltstackError = error{
47904790
47914791pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
47924792 switch (errno(system.sigaltstack(ss, old_ss))) {
4793 0 => return,
4794 EFAULT => unreachable,
4795 EINVAL => unreachable,
4796 ENOMEM => return error.SizeTooSmall,
4797 EPERM => return error.PermissionDenied,
4793 .SUCCESS => return,
4794 .FAULT => unreachable,
4795 .INVAL => unreachable,
4796 .NOMEM => return error.SizeTooSmall,
4797 .PERM => return error.PermissionDenied,
47984798 else => |err| return unexpectedErrno(err),
47994799 }
48004800}
......@@ -4802,9 +4802,9 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
48024802/// Examine and change a signal action.
48034803pub fn sigaction(sig: u6, act: ?*const Sigaction, oact: ?*Sigaction) void {
48044804 switch (errno(system.sigaction(sig, act, oact))) {
4805 0 => return,
4806 EFAULT => unreachable,
4807 EINVAL => unreachable,
4805 .SUCCESS => return,
4806 .FAULT => unreachable,
4807 .INVAL => unreachable,
48084808 else => unreachable,
48094809 }
48104810}
......@@ -4841,25 +4841,25 @@ pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void {
48414841 const atim = times[0].toTimestamp();
48424842 const mtim = times[1].toTimestamp();
48434843 switch (wasi.fd_filestat_set_times(fd, atim, mtim, wasi.FILESTAT_SET_ATIM | wasi.FILESTAT_SET_MTIM)) {
4844 wasi.ESUCCESS => return,
4845 wasi.EACCES => return error.AccessDenied,
4846 wasi.EPERM => return error.PermissionDenied,
4847 wasi.EBADF => unreachable, // always a race condition
4848 wasi.EFAULT => unreachable,
4849 wasi.EINVAL => unreachable,
4850 wasi.EROFS => return error.ReadOnlyFileSystem,
4844 .SUCCESS => return,
4845 .ACCES => return error.AccessDenied,
4846 .PERM => return error.PermissionDenied,
4847 .BADF => unreachable, // always a race condition
4848 .FAULT => unreachable,
4849 .INVAL => unreachable,
4850 .ROFS => return error.ReadOnlyFileSystem,
48514851 else => |err| return unexpectedErrno(err),
48524852 }
48534853 }
48544854
48554855 switch (errno(system.futimens(fd, times))) {
4856 0 => return,
4857 EACCES => return error.AccessDenied,
4858 EPERM => return error.PermissionDenied,
4859 EBADF => unreachable, // always a race condition
4860 EFAULT => unreachable,
4861 EINVAL => unreachable,
4862 EROFS => return error.ReadOnlyFileSystem,
4856 .SUCCESS => return,
4857 .ACCES => return error.AccessDenied,
4858 .PERM => return error.PermissionDenied,
4859 .BADF => unreachable, // always a race condition
4860 .FAULT => unreachable,
4861 .INVAL => unreachable,
4862 .ROFS => return error.ReadOnlyFileSystem,
48634863 else => |err| return unexpectedErrno(err),
48644864 }
48654865}
......@@ -4869,10 +4869,10 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;
48694869pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
48704870 if (builtin.link_libc) {
48714871 switch (errno(system.gethostname(name_buffer, name_buffer.len))) {
4872 0 => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)),
4873 EFAULT => unreachable,
4874 ENAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
4875 EPERM => return error.PermissionDenied,
4872 .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)),
4873 .FAULT => unreachable,
4874 .NAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
4875 .PERM => return error.PermissionDenied,
48764876 else => |err| return unexpectedErrno(err),
48774877 }
48784878 }
......@@ -4889,8 +4889,8 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
48894889pub fn uname() utsname {
48904890 var uts: utsname = undefined;
48914891 switch (errno(system.uname(&uts))) {
4892 0 => return uts,
4893 EFAULT => unreachable,
4892 .SUCCESS => return uts,
4893 .FAULT => unreachable,
48944894 else => unreachable,
48954895 }
48964896}
......@@ -5049,33 +5049,33 @@ pub fn sendmsg(
50495049 }
50505050 } else {
50515051 switch (errno(rc)) {
5052 0 => return @intCast(usize, rc),
5053
5054 EACCES => return error.AccessDenied,
5055 EAGAIN => return error.WouldBlock,
5056 EALREADY => return error.FastOpenAlreadyInProgress,
5057 EBADF => unreachable, // always a race condition
5058 ECONNRESET => return error.ConnectionResetByPeer,
5059 EDESTADDRREQ => 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.
5061 EINTR => continue,
5062 EINVAL => unreachable, // Invalid argument passed.
5063 EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
5064 EMSGSIZE => return error.MessageTooBig,
5065 ENOBUFS => return error.SystemResources,
5066 ENOMEM => return error.SystemResources,
5067 ENOTSOCK => 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.
5069 EPIPE => return error.BrokenPipe,
5070 EAFNOSUPPORT => return error.AddressFamilyNotSupported,
5071 ELOOP => return error.SymLinkLoop,
5072 ENAMETOOLONG => return error.NameTooLong,
5073 ENOENT => return error.FileNotFound,
5074 ENOTDIR => return error.NotDir,
5075 EHOSTUNREACH => return error.NetworkUnreachable,
5076 ENETUNREACH => return error.NetworkUnreachable,
5077 ENOTCONN => return error.SocketNotConnected,
5078 ENETDOWN => return error.NetworkSubsystemFailed,
5052 .SUCCESS => return @intCast(usize, rc),
5053
5054 .ACCES => return error.AccessDenied,
5055 .AGAIN => return error.WouldBlock,
5056 .ALREADY => return error.FastOpenAlreadyInProgress,
5057 .BADF => unreachable, // always a race condition
5058 .CONNRESET => return error.ConnectionResetByPeer,
5059 .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
5060 .FAULT => unreachable, // An invalid user space address was specified for an argument.
5061 .INTR => continue,
5062 .INVAL => unreachable, // Invalid argument passed.
5063 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
5064 .MSGSIZE => return error.MessageTooBig,
5065 .NOBUFS => return error.SystemResources,
5066 .NOMEM => return error.SystemResources,
5067 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
5068 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
5069 .PIPE => return error.BrokenPipe,
5070 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
5071 .LOOP => return error.SymLinkLoop,
5072 .NAMETOOLONG => return error.NameTooLong,
5073 .NOENT => return error.FileNotFound,
5074 .NOTDIR => return error.NotDir,
5075 .HOSTUNREACH => return error.NetworkUnreachable,
5076 .NETUNREACH => return error.NetworkUnreachable,
5077 .NOTCONN => return error.SocketNotConnected,
5078 .NETDOWN => return error.NetworkSubsystemFailed,
50795079 else => |err| return unexpectedErrno(err),
50805080 }
50815081 }
......@@ -5149,33 +5149,33 @@ pub fn sendto(
51495149 }
51505150 } else {
51515151 switch (errno(rc)) {
5152 0 => return @intCast(usize, rc),
5153
5154 EACCES => return error.AccessDenied,
5155 EAGAIN => return error.WouldBlock,
5156 EALREADY => return error.FastOpenAlreadyInProgress,
5157 EBADF => unreachable, // always a race condition
5158 ECONNRESET => return error.ConnectionResetByPeer,
5159 EDESTADDRREQ => 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.
5161 EINTR => continue,
5162 EINVAL => unreachable, // Invalid argument passed.
5163 EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
5164 EMSGSIZE => return error.MessageTooBig,
5165 ENOBUFS => return error.SystemResources,
5166 ENOMEM => return error.SystemResources,
5167 ENOTSOCK => 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.
5169 EPIPE => return error.BrokenPipe,
5170 EAFNOSUPPORT => return error.AddressFamilyNotSupported,
5171 ELOOP => return error.SymLinkLoop,
5172 ENAMETOOLONG => return error.NameTooLong,
5173 ENOENT => return error.FileNotFound,
5174 ENOTDIR => return error.NotDir,
5175 EHOSTUNREACH => return error.NetworkUnreachable,
5176 ENETUNREACH => return error.NetworkUnreachable,
5177 ENOTCONN => return error.SocketNotConnected,
5178 ENETDOWN => return error.NetworkSubsystemFailed,
5152 .SUCCESS => return @intCast(usize, rc),
5153
5154 .ACCES => return error.AccessDenied,
5155 .AGAIN => return error.WouldBlock,
5156 .ALREADY => return error.FastOpenAlreadyInProgress,
5157 .BADF => unreachable, // always a race condition
5158 .CONNRESET => return error.ConnectionResetByPeer,
5159 .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
5160 .FAULT => unreachable, // An invalid user space address was specified for an argument.
5161 .INTR => continue,
5162 .INVAL => unreachable, // Invalid argument passed.
5163 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
5164 .MSGSIZE => return error.MessageTooBig,
5165 .NOBUFS => return error.SystemResources,
5166 .NOMEM => return error.SystemResources,
5167 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
5168 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
5169 .PIPE => return error.BrokenPipe,
5170 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
5171 .LOOP => return error.SymLinkLoop,
5172 .NAMETOOLONG => return error.NameTooLong,
5173 .NOENT => return error.FileNotFound,
5174 .NOTDIR => return error.NotDir,
5175 .HOSTUNREACH => return error.NetworkUnreachable,
5176 .NETUNREACH => return error.NetworkUnreachable,
5177 .NOTCONN => return error.SocketNotConnected,
5178 .NETDOWN => return error.NetworkSubsystemFailed,
51795179 else => |err| return unexpectedErrno(err),
51805180 }
51815181 }
......@@ -5312,7 +5312,7 @@ pub fn sendfile(
53125312 var offset: off_t = @bitCast(off_t, in_offset);
53135313 const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count);
53145314 switch (errno(rc)) {
5315 0 => {
5315 .SUCCESS => {
53165316 const amt = @bitCast(usize, rc);
53175317 total_written += amt;
53185318 if (in_len == 0 and amt == 0) {
......@@ -5325,12 +5325,12 @@ pub fn sendfile(
53255325 }
53265326 },
53275327
5328 EBADF => unreachable, // Always a race condition.
5329 EFAULT => unreachable, // Segmentation fault.
5330 EOVERFLOW => unreachable, // We avoid passing too large of a `count`.
5331 ENOTCONN => unreachable, // `out_fd` is an unconnected socket.
5328 .BADF => unreachable, // Always a race condition.
5329 .FAULT => unreachable, // Segmentation fault.
5330 .OVERFLOW => unreachable, // We avoid passing too large of a `count`.
5331 .NOTCONN => unreachable, // `out_fd` is an unconnected socket.
53325332
5333 EINVAL, ENOSYS => {
5333 .INVAL, .NOSYS => {
53345334 // EINVAL could be any of the following situations:
53355335 // * Descriptor is not valid or locked
53365336 // * an mmap(2)-like operation is not available for in_fd
......@@ -5340,17 +5340,17 @@ pub fn sendfile(
53405340 // manually, the same as ENOSYS.
53415341 break :sf;
53425342 },
5343 EAGAIN => if (std.event.Loop.instance) |loop| {
5343 .AGAIN => if (std.event.Loop.instance) |loop| {
53445344 loop.waitUntilFdWritable(out_fd);
53455345 continue;
53465346 } else {
53475347 return error.WouldBlock;
53485348 },
5349 EIO => return error.InputOutput,
5350 EPIPE => return error.BrokenPipe,
5351 ENOMEM => return error.SystemResources,
5352 ENXIO => return error.Unseekable,
5353 ESPIPE => return error.Unseekable,
5349 .IO => return error.InputOutput,
5350 .PIPE => return error.BrokenPipe,
5351 .NOMEM => return error.SystemResources,
5352 .NXIO => return error.Unseekable,
5353 .SPIPE => return error.Unseekable,
53545354 else => |err| {
53555355 unexpectedErrno(err) catch {};
53565356 break :sf;
......@@ -5392,13 +5392,13 @@ pub fn sendfile(
53925392 const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags));
53935393 const amt = @bitCast(usize, sbytes);
53945394 switch (err) {
5395 0 => return amt,
5395 .SUCCESS => return amt,
53965396
5397 EBADF => unreachable, // Always a race condition.
5398 EFAULT => unreachable, // Segmentation fault.
5399 ENOTCONN => unreachable, // `out_fd` is an unconnected socket.
5397 .BADF => unreachable, // Always a race condition.
5398 .FAULT => unreachable, // Segmentation fault.
5399 .NOTCONN => unreachable, // `out_fd` is an unconnected socket.
54005400
5401 EINVAL, EOPNOTSUPP, ENOTSOCK, ENOSYS => {
5401 .INVAL, .OPNOTSUPP, .NOTSOCK, .NOSYS => {
54025402 // EINVAL could be any of the following situations:
54035403 // * The fd argument is not a regular file.
54045404 // * The s argument is not a SOCK_STREAM type socket.
......@@ -5408,9 +5408,9 @@ pub fn sendfile(
54085408 break :sf;
54095409 },
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) {
54145414 return amt;
54155415 } else if (std.event.Loop.instance) |loop| {
54165416 loop.waitUntilFdWritable(out_fd);
......@@ -5419,7 +5419,7 @@ pub fn sendfile(
54195419 return error.WouldBlock;
54205420 },
54215421
5422 EBUSY => if (amt != 0) {
5422 .BUSY => if (amt != 0) {
54235423 return amt;
54245424 } else if (std.event.Loop.instance) |loop| {
54255425 loop.waitUntilFdReadable(in_fd);
......@@ -5428,9 +5428,9 @@ pub fn sendfile(
54285428 return error.WouldBlock;
54295429 },
54305430
5431 EIO => return error.InputOutput,
5432 ENOBUFS => return error.SystemResources,
5433 EPIPE => return error.BrokenPipe,
5431 .IO => return error.InputOutput,
5432 .NOBUFS => return error.SystemResources,
5433 .PIPE => return error.BrokenPipe,
54345434
54355435 else => {
54365436 unexpectedErrno(err) catch {};
......@@ -5471,18 +5471,18 @@ pub fn sendfile(
54715471 const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags));
54725472 const amt = @bitCast(usize, sbytes);
54735473 switch (err) {
5474 0 => return amt,
5474 .SUCCESS => return amt,
54755475
5476 EBADF => unreachable, // Always a race condition.
5477 EFAULT => unreachable, // Segmentation fault.
5478 EINVAL => unreachable,
5479 ENOTCONN => unreachable, // `out_fd` is an unconnected socket.
5476 .BADF => unreachable, // Always a race condition.
5477 .FAULT => unreachable, // Segmentation fault.
5478 .INVAL => unreachable,
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) {
54865486 return amt;
54875487 } else if (std.event.Loop.instance) |loop| {
54885488 loop.waitUntilFdWritable(out_fd);
......@@ -5491,8 +5491,8 @@ pub fn sendfile(
54915491 return error.WouldBlock;
54925492 },
54935493
5494 EIO => return error.InputOutput,
5495 EPIPE => return error.BrokenPipe,
5494 .IO => return error.InputOutput,
5495 .PIPE => return error.BrokenPipe,
54965496
54975497 else => {
54985498 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
55955595
55965596 const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags);
55975597 switch (system.getErrno(rc)) {
5598 0 => return @intCast(usize, rc),
5599 EBADF => return error.FilesOpenedWithWrongFlags,
5600 EFBIG => return error.FileTooBig,
5601 EIO => return error.InputOutput,
5602 EISDIR => return error.IsDir,
5603 ENOMEM => return error.OutOfMemory,
5604 ENOSPC => return error.NoSpaceLeft,
5605 EOVERFLOW => return error.Unseekable,
5606 EPERM => return error.PermissionDenied,
5607 ETXTBSY => return error.FileBusy,
5598 .SUCCESS => return @intCast(usize, rc),
5599 .BADF => return error.FilesOpenedWithWrongFlags,
5600 .FBIG => return error.FileTooBig,
5601 .IO => return error.InputOutput,
5602 .ISDIR => return error.IsDir,
5603 .NOMEM => return error.OutOfMemory,
5604 .NOSPC => return error.NoSpaceLeft,
5605 .OVERFLOW => return error.Unseekable,
5606 .PERM => return error.PermissionDenied,
5607 .TXTBSY => return error.FileBusy,
56085608 // these may not be regular files, try fallback
5609 EINVAL => {},
5609 .INVAL => {},
56105610 // support for cross-filesystem copy added in Linux 5.3, use fallback
5611 EXDEV => {},
5611 .XDEV => {},
56125612 // syscall added in Linux 4.5, use fallback
5613 ENOSYS => {
5613 .NOSYS => {
56145614 has_copy_file_range_syscall.store(false, .Monotonic);
56155615 },
56165616 else => |err| return unexpectedErrno(err),
......@@ -5652,11 +5652,11 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {
56525652 }
56535653 } else {
56545654 switch (errno(rc)) {
5655 0 => return @intCast(usize, rc),
5656 EFAULT => unreachable,
5657 EINTR => continue,
5658 EINVAL => unreachable,
5659 ENOMEM => return error.SystemResources,
5655 .SUCCESS => return @intCast(usize, rc),
5656 .FAULT => unreachable,
5657 .INTR => continue,
5658 .INVAL => unreachable,
5659 .NOMEM => return error.SystemResources,
56605660 else => |err| return unexpectedErrno(err),
56615661 }
56625662 }
......@@ -5681,11 +5681,11 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P
56815681 }
56825682 const rc = system.ppoll(fds.ptr, fds.len, ts_ptr, mask);
56835683 switch (errno(rc)) {
5684 0 => return @intCast(usize, rc),
5685 EFAULT => unreachable,
5686 EINTR => return error.SignalInterrupt,
5687 EINVAL => unreachable,
5688 ENOMEM => return error.SystemResources,
5684 .SUCCESS => return @intCast(usize, rc),
5685 .FAULT => unreachable,
5686 .INTR => return error.SignalInterrupt,
5687 .INVAL => unreachable,
5688 .NOMEM => return error.SystemResources,
56895689 else => |err| return unexpectedErrno(err),
56905690 }
56915691}
......@@ -5750,17 +5750,17 @@ pub fn recvfrom(
57505750 }
57515751 } else {
57525752 switch (errno(rc)) {
5753 0 => return @intCast(usize, rc),
5754 EBADF => unreachable, // always a race condition
5755 EFAULT => unreachable,
5756 EINVAL => unreachable,
5757 ENOTCONN => unreachable,
5758 ENOTSOCK => unreachable,
5759 EINTR => continue,
5760 EAGAIN => return error.WouldBlock,
5761 ENOMEM => return error.SystemResources,
5762 ECONNREFUSED => return error.ConnectionRefused,
5763 ECONNRESET => return error.ConnectionResetByPeer,
5753 .SUCCESS => return @intCast(usize, rc),
5754 .BADF => unreachable, // always a race condition
5755 .FAULT => unreachable,
5756 .INVAL => unreachable,
5757 .NOTCONN => unreachable,
5758 .NOTSOCK => unreachable,
5759 .INTR => continue,
5760 .AGAIN => return error.WouldBlock,
5761 .NOMEM => return error.SystemResources,
5762 .CONNREFUSED => return error.ConnectionRefused,
5763 .CONNRESET => return error.ConnectionResetByPeer,
57645764 else => |err| return unexpectedErrno(err),
57655765 }
57665766 }
......@@ -5830,8 +5830,8 @@ pub fn sched_yield() SchedYieldError!void {
58305830 return;
58315831 }
58325832 switch (errno(system.sched_yield())) {
5833 0 => return,
5834 ENOSYS => return error.SystemCannotYield,
5833 .SUCCESS => return,
5834 .NOSYS => return error.SystemCannotYield,
58355835 else => return error.SystemCannotYield,
58365836 }
58375837}
......@@ -5874,17 +5874,17 @@ pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSo
58745874 return;
58755875 } else {
58765876 switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {
5877 0 => {},
5878 EBADF => unreachable, // always a race condition
5879 ENOTSOCK => unreachable, // always a race condition
5880 EINVAL => unreachable,
5881 EFAULT => unreachable,
5882 EDOM => return error.TimeoutTooBig,
5883 EISCONN => return error.AlreadyConnected,
5884 ENOPROTOOPT => return error.InvalidProtocolOption,
5885 ENOMEM => return error.SystemResources,
5886 ENOBUFS => return error.SystemResources,
5887 EPERM => return error.PermissionDenied,
5877 .SUCCESS => {},
5878 .BADF => unreachable, // always a race condition
5879 .NOTSOCK => unreachable, // always a race condition
5880 .INVAL => unreachable,
5881 .FAULT => unreachable,
5882 .DOM => return error.TimeoutTooBig,
5883 .ISCONN => return error.AlreadyConnected,
5884 .NOPROTOOPT => return error.InvalidProtocolOption,
5885 .NOMEM => return error.SystemResources,
5886 .NOBUFS => return error.SystemResources,
5887 .PERM => return error.PermissionDenied,
58885888 else => |err| return unexpectedErrno(err),
58895889 }
58905890 }
......@@ -5909,13 +5909,13 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
59095909 const getErrno = if (use_c) std.c.getErrno else linux.getErrno;
59105910 const rc = sys.memfd_create(name, flags);
59115911 switch (getErrno(rc)) {
5912 0 => return @intCast(fd_t, rc),
5913 EFAULT => unreachable, // name has invalid memory
5914 EINVAL => unreachable, // name/flags are faulty
5915 ENFILE => return error.SystemFdQuotaExceeded,
5916 EMFILE => return error.ProcessFdQuotaExceeded,
5917 ENOMEM => return error.OutOfMemory,
5918 ENOSYS => return error.SystemOutdated,
5912 .SUCCESS => return @intCast(fd_t, rc),
5913 .FAULT => unreachable, // name has invalid memory
5914 .INVAL => unreachable, // name/flags are faulty
5915 .NFILE => return error.SystemFdQuotaExceeded,
5916 .MFILE => return error.ProcessFdQuotaExceeded,
5917 .NOMEM => return error.OutOfMemory,
5918 .NOSYS => return error.SystemOutdated,
59195919 else => |err| return unexpectedErrno(err),
59205920 }
59215921}
......@@ -5940,9 +5940,9 @@ pub fn getrusage(who: i32) rusage {
59405940 var result: rusage = undefined;
59415941 const rc = system.getrusage(who, &result);
59425942 switch (errno(rc)) {
5943 0 => return result,
5944 EINVAL => unreachable,
5945 EFAULT => unreachable,
5943 .SUCCESS => return result,
5944 .INVAL => unreachable,
5945 .FAULT => unreachable,
59465946 else => unreachable,
59475947 }
59485948}
......@@ -5953,10 +5953,10 @@ pub fn tcgetattr(handle: fd_t) TermiosGetError!termios {
59535953 while (true) {
59545954 var term: termios = undefined;
59555955 switch (errno(system.tcgetattr(handle, &term))) {
5956 0 => return term,
5957 EINTR => continue,
5958 EBADF => unreachable,
5959 ENOTTY => return error.NotATerminal,
5956 .SUCCESS => return term,
5957 .INTR => continue,
5958 .BADF => unreachable,
5959 .NOTTY => return error.NotATerminal,
59605960 else => |err| return unexpectedErrno(err),
59615961 }
59625962 }
......@@ -5967,12 +5967,12 @@ pub const TermiosSetError = TermiosGetError || error{ProcessOrphaned};
59675967pub fn tcsetattr(handle: fd_t, optional_action: TCSA, termios_p: termios) TermiosSetError!void {
59685968 while (true) {
59695969 switch (errno(system.tcsetattr(handle, optional_action, &termios_p))) {
5970 0 => return,
5971 EBADF => unreachable,
5972 EINTR => continue,
5973 EINVAL => unreachable,
5974 ENOTTY => return error.NotATerminal,
5975 EIO => return error.ProcessOrphaned,
5970 .SUCCESS => return,
5971 .BADF => unreachable,
5972 .INTR => continue,
5973 .INVAL => unreachable,
5974 .NOTTY => return error.NotATerminal,
5975 .IO => return error.ProcessOrphaned,
59765976 else => |err| return unexpectedErrno(err),
59775977 }
59785978 }
......@@ -5986,15 +5986,15 @@ pub const IoCtl_SIOCGIFINDEX_Error = error{
59865986pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {
59875987 while (true) {
59885988 switch (errno(system.ioctl(fd, SIOCGIFINDEX, @ptrToInt(ifr)))) {
5989 0 => return,
5990 EINVAL => unreachable, // Bad parameters.
5991 ENOTTY => unreachable,
5992 ENXIO => unreachable,
5993 EBADF => unreachable, // Always a race condition.
5994 EFAULT => unreachable, // Bad pointer parameter.
5995 EINTR => continue,
5996 EIO => return error.FileSystem,
5997 ENODEV => return error.InterfaceNotFound,
5989 .SUCCESS => return,
5990 .INVAL => unreachable, // Bad parameters.
5991 .NOTTY => unreachable,
5992 .NXIO => unreachable,
5993 .BADF => unreachable, // Always a race condition.
5994 .FAULT => unreachable, // Bad pointer parameter.
5995 .INTR => continue,
5996 .IO => return error.FileSystem,
5997 .NODEV => return error.InterfaceNotFound,
59985998 else => |err| return unexpectedErrno(err),
59995999 }
60006000 }
......@@ -6003,13 +6003,13 @@ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void {
60036003pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
60046004 const rc = system.signalfd(fd, mask, flags);
60056005 switch (errno(rc)) {
6006 0 => return @intCast(fd_t, rc),
6007 EBADF, EINVAL => unreachable,
6008 ENFILE => return error.SystemFdQuotaExceeded,
6009 ENOMEM => return error.SystemResources,
6010 EMFILE => return error.ProcessResources,
6011 ENODEV => return error.InodeMountFail,
6012 ENOSYS => return error.SystemOutdated,
6006 .SUCCESS => return @intCast(fd_t, rc),
6007 .BADF, .INVAL => unreachable,
6008 .NFILE => return error.SystemFdQuotaExceeded,
6009 .NOMEM => return error.SystemResources,
6010 .MFILE => return error.ProcessResources,
6011 .NODEV => return error.InodeMountFail,
6012 .NOSYS => return error.SystemOutdated,
60136013 else => |err| return unexpectedErrno(err),
60146014 }
60156015}
......@@ -6030,11 +6030,11 @@ pub fn sync() void {
60306030pub fn syncfs(fd: fd_t) SyncError!void {
60316031 const rc = system.syncfs(fd);
60326032 switch (errno(rc)) {
6033 0 => return,
6034 EBADF, EINVAL, EROFS => unreachable,
6035 EIO => return error.InputOutput,
6036 ENOSPC => return error.NoSpaceLeft,
6037 EDQUOT => return error.DiskQuota,
6033 .SUCCESS => return,
6034 .BADF, .INVAL, .ROFS => unreachable,
6035 .IO => return error.InputOutput,
6036 .NOSPC => return error.NoSpaceLeft,
6037 .DQUOT => return error.DiskQuota,
60386038 else => |err| return unexpectedErrno(err),
60396039 }
60406040}
......@@ -6054,11 +6054,11 @@ pub fn fsync(fd: fd_t) SyncError!void {
60546054 }
60556055 const rc = system.fsync(fd);
60566056 switch (errno(rc)) {
6057 0 => return,
6058 EBADF, EINVAL, EROFS => unreachable,
6059 EIO => return error.InputOutput,
6060 ENOSPC => return error.NoSpaceLeft,
6061 EDQUOT => return error.DiskQuota,
6057 .SUCCESS => return,
6058 .BADF, .INVAL, .ROFS => unreachable,
6059 .IO => return error.InputOutput,
6060 .NOSPC => return error.NoSpaceLeft,
6061 .DQUOT => return error.DiskQuota,
60626062 else => |err| return unexpectedErrno(err),
60636063 }
60646064}
......@@ -6073,11 +6073,11 @@ pub fn fdatasync(fd: fd_t) SyncError!void {
60736073 }
60746074 const rc = system.fdatasync(fd);
60756075 switch (errno(rc)) {
6076 0 => return,
6077 EBADF, EINVAL, EROFS => unreachable,
6078 EIO => return error.InputOutput,
6079 ENOSPC => return error.NoSpaceLeft,
6080 EDQUOT => return error.DiskQuota,
6076 .SUCCESS => return,
6077 .BADF, .INVAL, .ROFS => unreachable,
6078 .IO => return error.InputOutput,
6079 .NOSPC => return error.NoSpaceLeft,
6080 .DQUOT => return error.DiskQuota,
60816081 else => |err| return unexpectedErrno(err),
60826082 }
60836083}
......@@ -6111,15 +6111,15 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {
61116111
61126112 const rc = system.prctl(@enumToInt(option), buf[0], buf[1], buf[2], buf[3]);
61136113 switch (errno(rc)) {
6114 0 => return @intCast(u31, rc),
6115 EACCES => return error.AccessDenied,
6116 EBADF => return error.InvalidFileDescriptor,
6117 EFAULT => return error.InvalidAddress,
6118 EINVAL => unreachable,
6119 ENODEV, ENXIO => return error.UnsupportedFeature,
6120 EOPNOTSUPP => return error.OperationNotSupported,
6121 EPERM, EBUSY => return error.PermissionDenied,
6122 ERANGE => unreachable,
6114 .SUCCESS => return @intCast(u31, rc),
6115 .ACCES => return error.AccessDenied,
6116 .BADF => return error.InvalidFileDescriptor,
6117 .FAULT => return error.InvalidAddress,
6118 .INVAL => unreachable,
6119 .NODEV, .NXIO => return error.UnsupportedFeature,
6120 .OPNOTSUPP => return error.OperationNotSupported,
6121 .PERM, .BUSY => return error.PermissionDenied,
6122 .RANGE => unreachable,
61236123 else => |err| return unexpectedErrno(err),
61246124 }
61256125}
......@@ -6134,9 +6134,9 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
61346134
61356135 var limits: rlimit = undefined;
61366136 switch (errno(getrlimit_sym(resource, &limits))) {
6137 0 => return limits,
6138 EFAULT => unreachable, // bogus pointer
6139 EINVAL => unreachable,
6137 .SUCCESS => return limits,
6138 .FAULT => unreachable, // bogus pointer
6139 .INVAL => unreachable,
61406140 else => |err| return unexpectedErrno(err),
61416141 }
61426142}
......@@ -6150,10 +6150,10 @@ pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void
61506150 system.setrlimit;
61516151
61526152 switch (errno(setrlimit_sym(resource, &limits))) {
6153 0 => return,
6154 EFAULT => unreachable, // bogus pointer
6155 EINVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable
6156 EPERM => return error.PermissionDenied,
6153 .SUCCESS => return,
6154 .FAULT => unreachable, // bogus pointer
6155 .INVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable
6156 .PERM => return error.PermissionDenied,
61576157 else => |err| return unexpectedErrno(err),
61586158 }
61596159}
......@@ -6194,14 +6194,14 @@ pub const MadviseError = error{
61946194/// This syscall is optional and is sometimes configured to be disabled.
61956195pub fn madvise(ptr: [*]align(mem.page_size) u8, length: usize, advice: u32) MadviseError!void {
61966196 switch (errno(system.madvise(ptr, length, advice))) {
6197 0 => return,
6198 EACCES => return error.AccessDenied,
6199 EAGAIN => return error.SystemResources,
6200 EBADF => unreachable, // The map exists, but the area maps something that isn't a file.
6201 EINVAL => return error.InvalidSyscall,
6202 EIO => return error.WouldExceedMaximumResidentSetSize,
6203 ENOMEM => return error.OutOfMemory,
6204 ENOSYS => return error.MadviseUnavailable,
6197 .SUCCESS => return,
6198 .ACCES => return error.AccessDenied,
6199 .AGAIN => return error.SystemResources,
6200 .BADF => unreachable, // The map exists, but the area maps something that isn't a file.
6201 .INVAL => return error.InvalidSyscall,
6202 .IO => return error.WouldExceedMaximumResidentSetSize,
6203 .NOMEM => return error.OutOfMemory,
6204 .NOSYS => return error.MadviseUnavailable,
62056205 else => |err| return unexpectedErrno(err),
62066206 }
62076207}
lib/std/os/bits/darwin.zig+229-224
......@@ -866,337 +866,342 @@ pub fn WIFSIGNALED(x: u32) bool {
866866 return wstatus(x) != wstopped and wstatus(x) != 0;
867867}
868868
869/// Operation not permitted
870pub const EPERM = 1;
869pub const E = enum(u16) {
870 /// No error occurred.
871 SUCCESS = 0,
871872
872/// No such file or directory
873pub const ENOENT = 2;
873 /// Operation not permitted
874 PERM = 1,
874875
875/// No such process
876pub const ESRCH = 3;
876 /// No such file or directory
877 NOENT = 2,
877878
878/// Interrupted system call
879pub const EINTR = 4;
879 /// No such process
880 SRCH = 3,
880881
881/// Input/output error
882pub const EIO = 5;
882 /// Interrupted system call
883 INTR = 4,
883884
884/// Device not configured
885pub const ENXIO = 6;
885 /// Input/output error
886 IO = 5,
886887
887/// Argument list too long
888pub const E2BIG = 7;
888 /// Device not configured
889 NXIO = 6,
889890
890/// Exec format error
891pub const ENOEXEC = 8;
891 /// Argument list too long
892 @"2BIG" = 7,
892893
893/// Bad file descriptor
894pub const EBADF = 9;
894 /// Exec format error
895 NOEXEC = 8,
895896
896/// No child processes
897pub const ECHILD = 10;
897 /// Bad file descriptor
898 BADF = 9,
898899
899/// Resource deadlock avoided
900pub const EDEADLK = 11;
900 /// No child processes
901 CHILD = 10,
901902
902/// Cannot allocate memory
903pub const ENOMEM = 12;
903 /// Resource deadlock avoided
904 DEADLK = 11,
904905
905/// Permission denied
906pub const EACCES = 13;
906 /// Cannot allocate memory
907 NOMEM = 12,
907908
908/// Bad address
909pub const EFAULT = 14;
909 /// Permission denied
910 ACCES = 13,
910911
911/// Block device required
912pub const ENOTBLK = 15;
912 /// Bad address
913 FAULT = 14,
913914
914/// Device / Resource busy
915pub const EBUSY = 16;
915 /// Block device required
916 NOTBLK = 15,
916917
917/// File exists
918pub const EEXIST = 17;
918 /// Device / Resource busy
919 BUSY = 16,
919920
920/// Cross-device link
921pub const EXDEV = 18;
921 /// File exists
922 EXIST = 17,
922923
923/// Operation not supported by device
924pub const ENODEV = 19;
924 /// Cross-device link
925 XDEV = 18,
925926
926/// Not a directory
927pub const ENOTDIR = 20;
927 /// Operation not supported by device
928 NODEV = 19,
928929
929/// Is a directory
930pub const EISDIR = 21;
930 /// Not a directory
931 NOTDIR = 20,
931932
932/// Invalid argument
933pub const EINVAL = 22;
933 /// Is a directory
934 ISDIR = 21,
934935
935/// Too many open files in system
936pub const ENFILE = 23;
936 /// Invalid argument
937 INVAL = 22,
937938
938/// Too many open files
939pub const EMFILE = 24;
939 /// Too many open files in system
940 NFILE = 23,
940941
941/// Inappropriate ioctl for device
942pub const ENOTTY = 25;
942 /// Too many open files
943 MFILE = 24,
943944
944/// Text file busy
945pub const ETXTBSY = 26;
945 /// Inappropriate ioctl for device
946 NOTTY = 25,
946947
947/// File too large
948pub const EFBIG = 27;
948 /// Text file busy
949 TXTBSY = 26,
949950
950/// No space left on device
951pub const ENOSPC = 28;
951 /// File too large
952 FBIG = 27,
952953
953/// Illegal seek
954pub const ESPIPE = 29;
954 /// No space left on device
955 NOSPC = 28,
955956
956/// Read-only file system
957pub const EROFS = 30;
957 /// Illegal seek
958 SPIPE = 29,
958959
959/// Too many links
960pub const EMLINK = 31;
961/// Broken pipe
960 /// Read-only file system
961 ROFS = 30,
962962
963// math software
964pub const EPIPE = 32;
963 /// Too many links
964 MLINK = 31,
965965
966/// Numerical argument out of domain
967pub const EDOM = 33;
968/// Result too large
966 /// Broken pipe
967 PIPE = 32,
969968
970// non-blocking and interrupt i/o
971pub const ERANGE = 34;
969 // math software
972970
973/// Resource temporarily unavailable
974pub const EAGAIN = 35;
971 /// Numerical argument out of domain
972 DOM = 33,
975973
976/// Operation would block
977pub const EWOULDBLOCK = EAGAIN;
974 /// Result too large
975 RANGE = 34,
978976
979/// Operation now in progress
980pub const EINPROGRESS = 36;
981/// Operation already in progress
977 // non-blocking and interrupt i/o
982978
983// ipc/network software -- argument errors
984pub const EALREADY = 37;
979 /// Resource temporarily unavailable
980 /// This is the same code used for `WOULDBLOCK`.
981 AGAIN = 35,
985982
986/// Socket operation on non-socket
987pub const ENOTSOCK = 38;
983 /// Operation now in progress
984 INPROGRESS = 36,
988985
989/// Destination address required
990pub const EDESTADDRREQ = 39;
986 /// Operation already in progress
987 ALREADY = 37,
991988
992/// Message too long
993pub const EMSGSIZE = 40;
989 // ipc/network software -- argument errors
994990
995/// Protocol wrong type for socket
996pub const EPROTOTYPE = 41;
991 /// Socket operation on non-socket
992 NOTSOCK = 38,
997993
998/// Protocol not available
999pub const ENOPROTOOPT = 42;
994 /// Destination address required
995 DESTADDRREQ = 39,
1000996
1001/// Protocol not supported
1002pub const EPROTONOSUPPORT = 43;
997 /// Message too long
998 MSGSIZE = 40,
1003999
1004/// Socket type not supported
1005pub const ESOCKTNOSUPPORT = 44;
1000 /// Protocol wrong type for socket
1001 PROTOTYPE = 41,
10061002
1007/// Operation not supported
1008pub const ENOTSUP = 45;
1003 /// Protocol not available
1004 NOPROTOOPT = 42,
10091005
1010/// Operation not supported. Alias of `ENOTSUP`.
1011pub const EOPNOTSUPP = ENOTSUP;
1006 /// Protocol not supported
1007 PROTONOSUPPORT = 43,
10121008
1013/// Protocol family not supported
1014pub const EPFNOSUPPORT = 46;
1009 /// Socket type not supported
1010 SOCKTNOSUPPORT = 44,
10151011
1016/// Address family not supported by protocol family
1017pub const EAFNOSUPPORT = 47;
1012 /// Operation not supported
1013 /// The same code is used for `NOTSUP`.
1014 OPNOTSUPP = 45,
10181015
1019/// Address already in use
1020pub const EADDRINUSE = 48;
1021/// Can't assign requested address
1016 /// Protocol family not supported
1017 PFNOSUPPORT = 46,
10221018
1023// ipc/network software -- operational errors
1024pub const EADDRNOTAVAIL = 49;
1019 /// Address family not supported by protocol family
1020 AFNOSUPPORT = 47,
10251021
1026/// Network is down
1027pub const ENETDOWN = 50;
1022 /// Address already in use
1023 ADDRINUSE = 48,
1024 /// Can't assign requested address
10281025
1029/// Network is unreachable
1030pub const ENETUNREACH = 51;
1026 // ipc/network software -- operational errors
1027 ADDRNOTAVAIL = 49,
10311028
1032/// Network dropped connection on reset
1033pub const ENETRESET = 52;
1029 /// Network is down
1030 NETDOWN = 50,
10341031
1035/// Software caused connection abort
1036pub const ECONNABORTED = 53;
1032 /// Network is unreachable
1033 NETUNREACH = 51,
10371034
1038/// Connection reset by peer
1039pub const ECONNRESET = 54;
1035 /// Network dropped connection on reset
1036 NETRESET = 52,
10401037
1041/// No buffer space available
1042pub const ENOBUFS = 55;
1038 /// Software caused connection abort
1039 CONNABORTED = 53,
10431040
1044/// Socket is already connected
1045pub const EISCONN = 56;
1041 /// Connection reset by peer
1042 CONNRESET = 54,
10461043
1047/// Socket is not connected
1048pub const ENOTCONN = 57;
1044 /// No buffer space available
1045 NOBUFS = 55,
10491046
1050/// Can't send after socket shutdown
1051pub const ESHUTDOWN = 58;
1047 /// Socket is already connected
1048 ISCONN = 56,
10521049
1053/// Too many references: can't splice
1054pub const ETOOMANYREFS = 59;
1050 /// Socket is not connected
1051 NOTCONN = 57,
10551052
1056/// Operation timed out
1057pub const ETIMEDOUT = 60;
1053 /// Can't send after socket shutdown
1054 SHUTDOWN = 58,
10581055
1059/// Connection refused
1060pub const ECONNREFUSED = 61;
1056 /// Too many references: can't splice
1057 TOOMANYREFS = 59,
10611058
1062/// Too many levels of symbolic links
1063pub const ELOOP = 62;
1059 /// Operation timed out
1060 TIMEDOUT = 60,
10641061
1065/// File name too long
1066pub const ENAMETOOLONG = 63;
1062 /// Connection refused
1063 CONNREFUSED = 61,
10671064
1068/// Host is down
1069pub const EHOSTDOWN = 64;
1065 /// Too many levels of symbolic links
1066 LOOP = 62,
10701067
1071/// No route to host
1072pub const EHOSTUNREACH = 65;
1073/// Directory not empty
1068 /// File name too long
1069 NAMETOOLONG = 63,
10741070
1075// quotas & mush
1076pub const ENOTEMPTY = 66;
1071 /// Host is down
1072 HOSTDOWN = 64,
10771073
1078/// Too many processes
1079pub const EPROCLIM = 67;
1074 /// No route to host
1075 HOSTUNREACH = 65,
1076 /// Directory not empty
10801077
1081/// Too many users
1082pub const EUSERS = 68;
1083/// Disc quota exceeded
1078 // quotas & mush
1079 NOTEMPTY = 66,
10841080
1085// Network File System
1086pub const EDQUOT = 69;
1081 /// Too many processes
1082 PROCLIM = 67,
10871083
1088/// Stale NFS file handle
1089pub const ESTALE = 70;
1084 /// Too many users
1085 USERS = 68,
1086 /// Disc quota exceeded
10901087
1091/// Too many levels of remote in path
1092pub const EREMOTE = 71;
1088 // Network File System
1089 DQUOT = 69,
10931090
1094/// RPC struct is bad
1095pub const EBADRPC = 72;
1091 /// Stale NFS file handle
1092 STALE = 70,
10961093
1097/// RPC version wrong
1098pub const ERPCMISMATCH = 73;
1094 /// Too many levels of remote in path
1095 REMOTE = 71,
10991096
1100/// RPC prog. not avail
1101pub const EPROGUNAVAIL = 74;
1097 /// RPC struct is bad
1098 BADRPC = 72,
11021099
1103/// Program version wrong
1104pub const EPROGMISMATCH = 75;
1100 /// RPC version wrong
1101 RPCMISMATCH = 73,
11051102
1106/// Bad procedure for program
1107pub const EPROCUNAVAIL = 76;
1103 /// RPC prog. not avail
1104 PROGUNAVAIL = 74,
11081105
1109/// No locks available
1110pub const ENOLCK = 77;
1106 /// Program version wrong
1107 PROGMISMATCH = 75,
11111108
1112/// Function not implemented
1113pub const ENOSYS = 78;
1109 /// Bad procedure for program
1110 PROCUNAVAIL = 76,
11141111
1115/// Inappropriate file type or format
1116pub const EFTYPE = 79;
1112 /// No locks available
1113 NOLCK = 77,
11171114
1118/// Authentication error
1119pub const EAUTH = 80;
1120/// Need authenticator
1115 /// Function not implemented
1116 NOSYS = 78,
11211117
1122// Intelligent device errors
1123pub const ENEEDAUTH = 81;
1118 /// Inappropriate file type or format
1119 FTYPE = 79,
11241120
1125/// Device power is off
1126pub const EPWROFF = 82;
1121 /// Authentication error
1122 AUTH = 80,
11271123
1128/// Device error, e.g. paper out
1129pub const EDEVERR = 83;
1130/// Value too large to be stored in data type
1124 /// Need authenticator
1125 NEEDAUTH = 81,
11311126
1132// Program loading errors
1133pub const EOVERFLOW = 84;
1127 // Intelligent device errors
11341128
1135/// Bad executable
1136pub const EBADEXEC = 85;
1129 /// Device power is off
1130 PWROFF = 82,
11371131
1138/// Bad CPU type in executable
1139pub const EBADARCH = 86;
1132 /// Device error, e.g. paper out
1133 DEVERR = 83,
11401134
1141/// Shared library version mismatch
1142pub const ESHLIBVERS = 87;
1135 /// Value too large to be stored in data type
1136 OVERFLOW = 84,
11431137
1144/// Malformed Macho file
1145pub const EBADMACHO = 88;
1138 // Program loading errors
11461139
1147/// Operation canceled
1148pub const ECANCELED = 89;
1140 /// Bad executable
1141 BADEXEC = 85,
11491142
1150/// Identifier removed
1151pub const EIDRM = 90;
1143 /// Bad CPU type in executable
1144 BADARCH = 86,
11521145
1153/// No message of desired type
1154pub const ENOMSG = 91;
1146 /// Shared library version mismatch
1147 SHLIBVERS = 87,
11551148
1156/// Illegal byte sequence
1157pub const EILSEQ = 92;
1149 /// Malformed Macho file
1150 BADMACHO = 88,
11581151
1159/// Attribute not found
1160pub const ENOATTR = 93;
1152 /// Operation canceled
1153 CANCELED = 89,
11611154
1162/// Bad message
1163pub const EBADMSG = 94;
1155 /// Identifier removed
1156 IDRM = 90,
11641157
1165/// Reserved
1166pub const EMULTIHOP = 95;
1158 /// No message of desired type
1159 NOMSG = 91,
11671160
1168/// No message available on STREAM
1169pub const ENODATA = 96;
1161 /// Illegal byte sequence
1162 ILSEQ = 92,
11701163
1171/// Reserved
1172pub const ENOLINK = 97;
1164 /// Attribute not found
1165 NOATTR = 93,
11731166
1174/// No STREAM resources
1175pub const ENOSR = 98;
1167 /// Bad message
1168 BADMSG = 94,
11761169
1177/// Not a STREAM
1178pub const ENOSTR = 99;
1170 /// Reserved
1171 MULTIHOP = 95,
11791172
1180/// Protocol error
1181pub const EPROTO = 100;
1173 /// No message available on STREAM
1174 NODATA = 96,
11821175
1183/// STREAM ioctl timeout
1184pub const ETIME = 101;
1176 /// Reserved
1177 NOLINK = 97,
11851178
1186/// No such policy registered
1187pub const ENOPOLICY = 103;
1179 /// No STREAM resources
1180 NOSR = 98,
11881181
1189/// State not recoverable
1190pub const ENOTRECOVERABLE = 104;
1182 /// Not a STREAM
1183 NOSTR = 99,
11911184
1192/// Previous owner died
1193pub const EOWNERDEAD = 105;
1185 /// Protocol error
1186 PROTO = 100,
11941187
1195/// Interface output queue is full
1196pub const EQFULL = 106;
1188 /// STREAM ioctl timeout
1189 TIME = 101,
11971190
1198/// Must be equal largest errno
1199pub const ELAST = 106;
1191 /// No such policy registered
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
12011206pub const SIGSTKSZ = 131072;
12021207pub const MINSIGSTKSZ = 32768;
lib/std/os/bits/dragonfly.zig+102-97
......@@ -25,103 +25,108 @@ pub const gid_t = u32;
2525pub const time_t = isize;
2626pub const suseconds_t = c_long;
2727
28pub const ENOTSUP = EOPNOTSUPP;
29pub const EWOULDBLOCK = EAGAIN;
30pub const EPERM = 1;
31pub const ENOENT = 2;
32pub const ESRCH = 3;
33pub const EINTR = 4;
34pub const EIO = 5;
35pub const ENXIO = 6;
36pub const E2BIG = 7;
37pub const ENOEXEC = 8;
38pub const EBADF = 9;
39pub const ECHILD = 10;
40pub const EDEADLK = 11;
41pub const ENOMEM = 12;
42pub const EACCES = 13;
43pub const EFAULT = 14;
44pub const ENOTBLK = 15;
45pub const EBUSY = 16;
46pub const EEXIST = 17;
47pub const EXDEV = 18;
48pub const ENODEV = 19;
49pub const ENOTDIR = 20;
50pub const EISDIR = 21;
51pub const EINVAL = 22;
52pub const ENFILE = 23;
53pub const EMFILE = 24;
54pub const ENOTTY = 25;
55pub const ETXTBSY = 26;
56pub const EFBIG = 27;
57pub const ENOSPC = 28;
58pub const ESPIPE = 29;
59pub const EROFS = 30;
60pub const EMLINK = 31;
61pub const EPIPE = 32;
62pub const EDOM = 33;
63pub const ERANGE = 34;
64pub const EAGAIN = 35;
65pub const EINPROGRESS = 36;
66pub const EALREADY = 37;
67pub const ENOTSOCK = 38;
68pub const EDESTADDRREQ = 39;
69pub const EMSGSIZE = 40;
70pub const EPROTOTYPE = 41;
71pub const ENOPROTOOPT = 42;
72pub const EPROTONOSUPPORT = 43;
73pub const ESOCKTNOSUPPORT = 44;
74pub const EOPNOTSUPP = 45;
75pub const EPFNOSUPPORT = 46;
76pub const EAFNOSUPPORT = 47;
77pub const EADDRINUSE = 48;
78pub const EADDRNOTAVAIL = 49;
79pub const ENETDOWN = 50;
80pub const ENETUNREACH = 51;
81pub const ENETRESET = 52;
82pub const ECONNABORTED = 53;
83pub const ECONNRESET = 54;
84pub const ENOBUFS = 55;
85pub const EISCONN = 56;
86pub const ENOTCONN = 57;
87pub const ESHUTDOWN = 58;
88pub const ETOOMANYREFS = 59;
89pub const ETIMEDOUT = 60;
90pub const ECONNREFUSED = 61;
91pub const ELOOP = 62;
92pub const ENAMETOOLONG = 63;
93pub const EHOSTDOWN = 64;
94pub const EHOSTUNREACH = 65;
95pub const ENOTEMPTY = 66;
96pub const EPROCLIM = 67;
97pub const EUSERS = 68;
98pub const EDQUOT = 69;
99pub const ESTALE = 70;
100pub const EREMOTE = 71;
101pub const EBADRPC = 72;
102pub const ERPCMISMATCH = 73;
103pub const EPROGUNAVAIL = 74;
104pub const EPROGMISMATCH = 75;
105pub const EPROCUNAVAIL = 76;
106pub const ENOLCK = 77;
107pub const ENOSYS = 78;
108pub const EFTYPE = 79;
109pub const EAUTH = 80;
110pub const ENEEDAUTH = 81;
111pub const EIDRM = 82;
112pub const ENOMSG = 83;
113pub const EOVERFLOW = 84;
114pub const ECANCELED = 85;
115pub const EILSEQ = 86;
116pub const ENOATTR = 87;
117pub const EDOOFUS = 88;
118pub const EBADMSG = 89;
119pub const EMULTIHOP = 90;
120pub const ENOLINK = 91;
121pub const EPROTO = 92;
122pub const ENOMEDIUM = 93;
123pub const ELAST = 99;
124pub const EASYNC = 99;
28pub const E = enum(u16) {
29 /// No error occurred.
30 SUCCESS = 0,
31
32 PERM = 1,
33 NOENT = 2,
34 SRCH = 3,
35 INTR = 4,
36 IO = 5,
37 NXIO = 6,
38 @"2BIG" = 7,
39 NOEXEC = 8,
40 BADF = 9,
41 CHILD = 10,
42 DEADLK = 11,
43 NOMEM = 12,
44 ACCES = 13,
45 FAULT = 14,
46 NOTBLK = 15,
47 BUSY = 16,
48 EXIST = 17,
49 XDEV = 18,
50 NODEV = 19,
51 NOTDIR = 20,
52 ISDIR = 21,
53 INVAL = 22,
54 NFILE = 23,
55 MFILE = 24,
56 NOTTY = 25,
57 TXTBSY = 26,
58 FBIG = 27,
59 NOSPC = 28,
60 SPIPE = 29,
61 ROFS = 30,
62 MLINK = 31,
63 PIPE = 32,
64 DOM = 33,
65 RANGE = 34,
66 /// This code is also used for `WOULDBLOCK`.
67 AGAIN = 35,
68 INPROGRESS = 36,
69 ALREADY = 37,
70 NOTSOCK = 38,
71 DESTADDRREQ = 39,
72 MSGSIZE = 40,
73 PROTOTYPE = 41,
74 NOPROTOOPT = 42,
75 PROTONOSUPPORT = 43,
76 SOCKTNOSUPPORT = 44,
77 /// This code is also used for `NOTSUP`.
78 OPNOTSUPP = 45,
79 PFNOSUPPORT = 46,
80 AFNOSUPPORT = 47,
81 ADDRINUSE = 48,
82 ADDRNOTAVAIL = 49,
83 NETDOWN = 50,
84 NETUNREACH = 51,
85 NETRESET = 52,
86 CONNABORTED = 53,
87 CONNRESET = 54,
88 NOBUFS = 55,
89 ISCONN = 56,
90 NOTCONN = 57,
91 SHUTDOWN = 58,
92 TOOMANYREFS = 59,
93 TIMEDOUT = 60,
94 CONNREFUSED = 61,
95 LOOP = 62,
96 NAMETOOLONG = 63,
97 HOSTDOWN = 64,
98 HOSTUNREACH = 65,
99 NOTEMPTY = 66,
100 PROCLIM = 67,
101 USERS = 68,
102 DQUOT = 69,
103 STALE = 70,
104 REMOTE = 71,
105 BADRPC = 72,
106 RPCMISMATCH = 73,
107 PROGUNAVAIL = 74,
108 PROGMISMATCH = 75,
109 PROCUNAVAIL = 76,
110 NOLCK = 77,
111 NOSYS = 78,
112 FTYPE = 79,
113 AUTH = 80,
114 NEEDAUTH = 81,
115 IDRM = 82,
116 NOMSG = 83,
117 OVERFLOW = 84,
118 CANCELED = 85,
119 ILSEQ = 86,
120 NOATTR = 87,
121 DOOFUS = 88,
122 BADMSG = 89,
123 MULTIHOP = 90,
124 NOLINK = 91,
125 PROTO = 92,
126 NOMEDIUM = 93,
127 ASYNC = 99,
128 _,
129};
125130
126131pub const STDIN_FILENO = 0;
127132pub const STDOUT_FILENO = 1;
lib/std/os/bits/freebsd.zig+128-121
......@@ -887,127 +887,134 @@ pub usingnamespace switch (builtin.target.cpu.arch) {
887887 else => struct {},
888888};
889889
890pub const EPERM = 1; // Operation not permitted
891pub const ENOENT = 2; // No such file or directory
892pub const ESRCH = 3; // No such process
893pub const EINTR = 4; // Interrupted system call
894pub const EIO = 5; // Input/output error
895pub const ENXIO = 6; // Device not configured
896pub const E2BIG = 7; // Argument list too long
897pub const ENOEXEC = 8; // Exec format error
898pub const EBADF = 9; // Bad file descriptor
899pub const ECHILD = 10; // No child processes
900pub const EDEADLK = 11; // Resource deadlock avoided
901// 11 was EAGAIN
902pub const ENOMEM = 12; // Cannot allocate memory
903pub const EACCES = 13; // Permission denied
904pub const EFAULT = 14; // Bad address
905pub const ENOTBLK = 15; // Block device required
906pub const EBUSY = 16; // Device busy
907pub const EEXIST = 17; // File exists
908pub const EXDEV = 18; // Cross-device link
909pub const ENODEV = 19; // Operation not supported by device
910pub const ENOTDIR = 20; // Not a directory
911pub const EISDIR = 21; // Is a directory
912pub const EINVAL = 22; // Invalid argument
913pub const ENFILE = 23; // Too many open files in system
914pub const EMFILE = 24; // Too many open files
915pub const ENOTTY = 25; // Inappropriate ioctl for device
916pub const ETXTBSY = 26; // Text file busy
917pub const EFBIG = 27; // File too large
918pub const ENOSPC = 28; // No space left on device
919pub const ESPIPE = 29; // Illegal seek
920pub const EROFS = 30; // Read-only filesystem
921pub const EMLINK = 31; // Too many links
922pub const EPIPE = 32; // Broken pipe
923
924// math software
925pub const EDOM = 33; // Numerical argument out of domain
926pub const ERANGE = 34; // Result too large
927
928// non-blocking and interrupt i/o
929pub const EAGAIN = 35; // Resource temporarily unavailable
930pub const EWOULDBLOCK = EAGAIN; // Operation would block
931pub const EINPROGRESS = 36; // Operation now in progress
932pub const EALREADY = 37; // Operation already in progress
933
934// ipc/network software -- argument errors
935pub const ENOTSOCK = 38; // Socket operation on non-socket
936pub const EDESTADDRREQ = 39; // Destination address required
937pub const EMSGSIZE = 40; // Message too long
938pub const EPROTOTYPE = 41; // Protocol wrong type for socket
939pub const ENOPROTOOPT = 42; // Protocol not available
940pub const EPROTONOSUPPORT = 43; // Protocol not supported
941pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
942pub const EOPNOTSUPP = 45; // Operation not supported
943pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
944pub const EPFNOSUPPORT = 46; // Protocol family not supported
945pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
946pub const EADDRINUSE = 48; // Address already in use
947pub const EADDRNOTAVAIL = 49; // Can't assign requested address
948
949// ipc/network software -- operational errors
950pub const ENETDOWN = 50; // Network is down
951pub const ENETUNREACH = 51; // Network is unreachable
952pub const ENETRESET = 52; // Network dropped connection on reset
953pub const ECONNABORTED = 53; // Software caused connection abort
954pub const ECONNRESET = 54; // Connection reset by peer
955pub const ENOBUFS = 55; // No buffer space available
956pub const EISCONN = 56; // Socket is already connected
957pub const ENOTCONN = 57; // Socket is not connected
958pub const ESHUTDOWN = 58; // Can't send after socket shutdown
959pub const ETOOMANYREFS = 59; // Too many references: can't splice
960pub const ETIMEDOUT = 60; // Operation timed out
961pub const ECONNREFUSED = 61; // Connection refused
962
963pub const ELOOP = 62; // Too many levels of symbolic links
964pub const ENAMETOOLONG = 63; // File name too long
965
966// should be rearranged
967pub const EHOSTDOWN = 64; // Host is down
968pub const EHOSTUNREACH = 65; // No route to host
969pub const ENOTEMPTY = 66; // Directory not empty
970
971// quotas & mush
972pub const EPROCLIM = 67; // Too many processes
973pub const EUSERS = 68; // Too many users
974pub const EDQUOT = 69; // Disc quota exceeded
975
976// Network File System
977pub const ESTALE = 70; // Stale NFS file handle
978pub const EREMOTE = 71; // Too many levels of remote in path
979pub const EBADRPC = 72; // RPC struct is bad
980pub const ERPCMISMATCH = 73; // RPC version wrong
981pub const EPROGUNAVAIL = 74; // RPC prog. not avail
982pub const EPROGMISMATCH = 75; // Program version wrong
983pub const EPROCUNAVAIL = 76; // Bad procedure for program
984
985pub const ENOLCK = 77; // No locks available
986pub const ENOSYS = 78; // Function not implemented
987
988pub const EFTYPE = 79; // Inappropriate file type or format
989pub const EAUTH = 80; // Authentication error
990pub const ENEEDAUTH = 81; // Need authenticator
991pub const EIDRM = 82; // Identifier removed
992pub const ENOMSG = 83; // No message of desired type
993pub const EOVERFLOW = 84; // Value too large to be stored in data type
994pub const ECANCELED = 85; // Operation canceled
995pub const EILSEQ = 86; // Illegal byte sequence
996pub const ENOATTR = 87; // Attribute not found
997
998pub const EDOOFUS = 88; // Programming error
999
1000pub const EBADMSG = 89; // Bad message
1001pub const EMULTIHOP = 90; // Multihop attempted
1002pub const ENOLINK = 91; // Link has been severed
1003pub const EPROTO = 92; // Protocol error
1004
1005pub const ENOTCAPABLE = 93; // Capabilities insufficient
1006pub const ECAPMODE = 94; // Not permitted in capability mode
1007pub const ENOTRECOVERABLE = 95; // State not recoverable
1008pub const EOWNERDEAD = 96; // Previous owner died
1009
1010pub const ELAST = 96; // Must be equal largest errno
890pub const E = enum(u16) {
891 /// No error occurred.
892 SUCCESS = 0,
893
894 PERM = 1, // Operation not permitted
895 NOENT = 2, // No such file or directory
896 SRCH = 3, // No such process
897 INTR = 4, // Interrupted system call
898 IO = 5, // Input/output error
899 NXIO = 6, // Device not configured
900 @"2BIG" = 7, // Argument list too long
901 NOEXEC = 8, // Exec format error
902 BADF = 9, // Bad file descriptor
903 CHILD = 10, // No child processes
904 DEADLK = 11, // Resource deadlock avoided
905 // 11 was AGAIN
906 NOMEM = 12, // Cannot allocate memory
907 ACCES = 13, // Permission denied
908 FAULT = 14, // Bad address
909 NOTBLK = 15, // Block device required
910 BUSY = 16, // Device busy
911 EXIST = 17, // File exists
912 XDEV = 18, // Cross-device link
913 NODEV = 19, // Operation not supported by device
914 NOTDIR = 20, // Not a directory
915 ISDIR = 21, // Is a directory
916 INVAL = 22, // Invalid argument
917 NFILE = 23, // Too many open files in system
918 MFILE = 24, // Too many open files
919 NOTTY = 25, // Inappropriate ioctl for device
920 TXTBSY = 26, // Text file busy
921 FBIG = 27, // File too large
922 NOSPC = 28, // No space left on device
923 SPIPE = 29, // Illegal seek
924 ROFS = 30, // Read-only filesystem
925 MLINK = 31, // Too many links
926 PIPE = 32, // Broken pipe
927
928 // math software
929 DOM = 33, // Numerical argument out of domain
930 RANGE = 34, // Result too large
931
932 // non-blocking and interrupt i/o
933
934 /// Resource temporarily unavailable
935 /// This code is also used for `WOULDBLOCK`: operation would block.
936 AGAIN = 35,
937 INPROGRESS = 36, // Operation now in progress
938 ALREADY = 37, // Operation already in progress
939
940 // ipc/network software -- argument errors
941 NOTSOCK = 38, // Socket operation on non-socket
942 DESTADDRREQ = 39, // Destination address required
943 MSGSIZE = 40, // Message too long
944 PROTOTYPE = 41, // Protocol wrong type for socket
945 NOPROTOOPT = 42, // Protocol not available
946 PROTONOSUPPORT = 43, // Protocol not supported
947 SOCKTNOSUPPORT = 44, // Socket type not supported
948 /// Operation not supported
949 /// This code is also used for `NOTSUP`.
950 OPNOTSUPP = 45,
951 PFNOSUPPORT = 46, // Protocol family not supported
952 AFNOSUPPORT = 47, // Address family not supported by protocol family
953 ADDRINUSE = 48, // Address already in use
954 ADDRNOTAVAIL = 49, // Can't assign requested address
955
956 // ipc/network software -- operational errors
957 NETDOWN = 50, // Network is down
958 NETUNREACH = 51, // Network is unreachable
959 NETRESET = 52, // Network dropped connection on reset
960 CONNABORTED = 53, // Software caused connection abort
961 CONNRESET = 54, // Connection reset by peer
962 NOBUFS = 55, // No buffer space available
963 ISCONN = 56, // Socket is already connected
964 NOTCONN = 57, // Socket is not connected
965 SHUTDOWN = 58, // Can't send after socket shutdown
966 TOOMANYREFS = 59, // Too many references: can't splice
967 TIMEDOUT = 60, // Operation timed out
968 CONNREFUSED = 61, // Connection refused
969
970 LOOP = 62, // Too many levels of symbolic links
971 NAMETOOLONG = 63, // File name too long
972
973 // should be rearranged
974 HOSTDOWN = 64, // Host is down
975 HOSTUNREACH = 65, // No route to host
976 NOTEMPTY = 66, // Directory not empty
977
978 // quotas & mush
979 PROCLIM = 67, // Too many processes
980 USERS = 68, // Too many users
981 DQUOT = 69, // Disc quota exceeded
982
983 // Network File System
984 STALE = 70, // Stale NFS file handle
985 REMOTE = 71, // Too many levels of remote in path
986 BADRPC = 72, // RPC struct is bad
987 RPCMISMATCH = 73, // RPC version wrong
988 PROGUNAVAIL = 74, // RPC prog. not avail
989 PROGMISMATCH = 75, // Program version wrong
990 PROCUNAVAIL = 76, // Bad procedure for program
991
992 NOLCK = 77, // No locks available
993 NOSYS = 78, // Function not implemented
994
995 FTYPE = 79, // Inappropriate file type or format
996 AUTH = 80, // Authentication error
997 NEEDAUTH = 81, // Need authenticator
998 IDRM = 82, // Identifier removed
999 NOMSG = 83, // No message of desired type
1000 OVERFLOW = 84, // Value too large to be stored in data type
1001 CANCELED = 85, // Operation canceled
1002 ILSEQ = 86, // Illegal byte sequence
1003 NOATTR = 87, // Attribute not found
1004
1005 DOOFUS = 88, // Programming error
1006
1007 BADMSG = 89, // Bad message
1008 MULTIHOP = 90, // Multihop attempted
1009 NOLINK = 91, // Link has been severed
1010 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
10121019pub const MINSIGSTKSZ = switch (builtin.target.cpu.arch) {
10131020 .i386, .x86_64 => 2048,
lib/std/os/bits/haiku.zig+124-119
......@@ -734,125 +734,130 @@ pub const sigset_t = extern struct {
734734 __bits: [_SIG_WORDS]u32,
735735};
736736
737pub const EPERM = -0x7ffffff1; // Operation not permitted
738pub const ENOENT = -0x7fff9ffd; // No such file or directory
739pub const ESRCH = -0x7fff8ff3; // No such process
740pub const EINTR = -0x7ffffff6; // Interrupted system call
741pub const EIO = -0x7fffffff; // Input/output error
742pub const ENXIO = -0x7fff8ff5; // Device not configured
743pub const E2BIG = -0x7fff8fff; // Argument list too long
744pub const ENOEXEC = -0x7fffecfe; // Exec format error
745pub const ECHILD = -0x7fff8ffe; // No child processes
746pub const EDEADLK = -0x7fff8ffd; // Resource deadlock avoided
747pub const ENOMEM = -0x80000000; // Cannot allocate memory
748pub const EACCES = -0x7ffffffe; // Permission denied
749pub const EFAULT = -0x7fffecff; // Bad address
750pub const EBUSY = -0x7ffffff2; // Device busy
751pub const EEXIST = -0x7fff9ffe; // File exists
752pub const EXDEV = -0x7fff9ff5; // Cross-device link
753pub const ENODEV = -0x7fff8ff9; // Operation not supported by device
754pub const ENOTDIR = -0x7fff9ffb; // Not a directory
755pub const EISDIR = -0x7fff9ff7; // Is a directory
756pub const EINVAL = -0x7ffffffb; // Invalid argument
757pub const ENFILE = -0x7fff8ffa; // Too many open files in system
758pub const EMFILE = -0x7fff9ff6; // Too many open files
759pub const ENOTTY = -0x7fff8ff6; // Inappropriate ioctl for device
760pub const ETXTBSY = -0x7fff8fc5; // Text file busy
761pub const EFBIG = -0x7fff8ffc; // File too large
762pub const ENOSPC = -0x7fff9ff9; // No space left on device
763pub const ESPIPE = -0x7fff8ff4; // Illegal seek
764pub const EROFS = -0x7fff9ff8; // Read-only filesystem
765pub const EMLINK = -0x7fff8ffb; // Too many links
766pub const EPIPE = -0x7fff9ff3; // Broken pipe
767pub const EBADF = -0x7fffa000; // Bad file descriptor
768
769// math software
770pub const EDOM = 33; // Numerical argument out of domain
771pub const ERANGE = 34; // Result too large
772
773// non-blocking and interrupt i/o
774pub const EAGAIN = -0x7ffffff5;
775pub const EWOULDBLOCK = -0x7ffffff5;
776pub const EINPROGRESS = -0x7fff8fdc;
777pub const EALREADY = -0x7fff8fdb;
778
779// ipc/network software -- argument errors
780pub const ENOTSOCK = 38; // Socket operation on non-socket
781pub const EDESTADDRREQ = 39; // Destination address required
782pub const EMSGSIZE = 40; // Message too long
783pub const EPROTOTYPE = 41; // Protocol wrong type for socket
784pub const ENOPROTOOPT = 42; // Protocol not available
785pub const EPROTONOSUPPORT = 43; // Protocol not supported
786pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
787pub const EOPNOTSUPP = 45; // Operation not supported
788pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
789pub const EPFNOSUPPORT = 46; // Protocol family not supported
790pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
791pub const EADDRINUSE = 48; // Address already in use
792pub const EADDRNOTAVAIL = 49; // Can't assign requested address
793
794// ipc/network software -- operational errors
795pub const ENETDOWN = 50; // Network is down
796pub const ENETUNREACH = 51; // Network is unreachable
797pub const ENETRESET = 52; // Network dropped connection on reset
798pub const ECONNABORTED = 53; // Software caused connection abort
799pub const ECONNRESET = 54; // Connection reset by peer
800pub const ENOBUFS = 55; // No buffer space available
801pub const EISCONN = 56; // Socket is already connected
802pub const ENOTCONN = 57; // Socket is not connected
803pub const ESHUTDOWN = 58; // Can't send after socket shutdown
804pub const ETOOMANYREFS = 59; // Too many references: can't splice
805pub const ETIMEDOUT = 60; // Operation timed out
806pub const ECONNREFUSED = 61; // Connection refused
807
808pub const ELOOP = 62; // Too many levels of symbolic links
809pub const ENAMETOOLONG = 63; // File name too long
810
811// should be rearranged
812pub const EHOSTDOWN = 64; // Host is down
813pub const EHOSTUNREACH = 65; // No route to host
814pub const ENOTEMPTY = 66; // Directory not empty
815
816// quotas & mush
817pub const EPROCLIM = 67; // Too many processes
818pub const EUSERS = 68; // Too many users
819pub const EDQUOT = 69; // Disc quota exceeded
820
821// Network File System
822pub const ESTALE = 70; // Stale NFS file handle
823pub const EREMOTE = 71; // Too many levels of remote in path
824pub const EBADRPC = 72; // RPC struct is bad
825pub const ERPCMISMATCH = 73; // RPC version wrong
826pub const EPROGUNAVAIL = 74; // RPC prog. not avail
827pub const EPROGMISMATCH = 75; // Program version wrong
828pub const EPROCUNAVAIL = 76; // Bad procedure for program
829
830pub const ENOLCK = 77; // No locks available
831pub const ENOSYS = 78; // Function not implemented
832
833pub const EFTYPE = 79; // Inappropriate file type or format
834pub const EAUTH = 80; // Authentication error
835pub const ENEEDAUTH = 81; // Need authenticator
836pub const EIDRM = 82; // Identifier removed
837pub const ENOMSG = 83; // No message of desired type
838pub const EOVERFLOW = 84; // Value too large to be stored in data type
839pub const ECANCELED = 85; // Operation canceled
840pub const EILSEQ = 86; // Illegal byte sequence
841pub const ENOATTR = 87; // Attribute not found
842
843pub const EDOOFUS = 88; // Programming error
844
845pub const EBADMSG = 89; // Bad message
846pub const EMULTIHOP = 90; // Multihop attempted
847pub const ENOLINK = 91; // Link has been severed
848pub const EPROTO = 92; // Protocol error
849
850pub const ENOTCAPABLE = 93; // Capabilities insufficient
851pub const ECAPMODE = 94; // Not permitted in capability mode
852pub const ENOTRECOVERABLE = 95; // State not recoverable
853pub const EOWNERDEAD = 96; // Previous owner died
854
855pub const ELAST = 96; // Must be equal largest errno
737pub const E = enum(i32) {
738 /// No error occurred.
739 SUCCESS = 0,
740 PERM = -0x7ffffff1, // Operation not permitted
741 NOENT = -0x7fff9ffd, // No such file or directory
742 SRCH = -0x7fff8ff3, // No such process
743 INTR = -0x7ffffff6, // Interrupted system call
744 IO = -0x7fffffff, // Input/output error
745 NXIO = -0x7fff8ff5, // Device not configured
746 @"2BIG" = -0x7fff8fff, // Argument list too long
747 NOEXEC = -0x7fffecfe, // Exec format error
748 CHILD = -0x7fff8ffe, // No child processes
749 DEADLK = -0x7fff8ffd, // Resource deadlock avoided
750 NOMEM = -0x80000000, // Cannot allocate memory
751 ACCES = -0x7ffffffe, // Permission denied
752 FAULT = -0x7fffecff, // Bad address
753 BUSY = -0x7ffffff2, // Device busy
754 EXIST = -0x7fff9ffe, // File exists
755 XDEV = -0x7fff9ff5, // Cross-device link
756 NODEV = -0x7fff8ff9, // Operation not supported by device
757 NOTDIR = -0x7fff9ffb, // Not a directory
758 ISDIR = -0x7fff9ff7, // Is a directory
759 INVAL = -0x7ffffffb, // Invalid argument
760 NFILE = -0x7fff8ffa, // Too many open files in system
761 MFILE = -0x7fff9ff6, // Too many open files
762 NOTTY = -0x7fff8ff6, // Inappropriate ioctl for device
763 TXTBSY = -0x7fff8fc5, // Text file busy
764 FBIG = -0x7fff8ffc, // File too large
765 NOSPC = -0x7fff9ff9, // No space left on device
766 SPIPE = -0x7fff8ff4, // Illegal seek
767 ROFS = -0x7fff9ff8, // Read-only filesystem
768 MLINK = -0x7fff8ffb, // Too many links
769 PIPE = -0x7fff9ff3, // Broken pipe
770 BADF = -0x7fffa000, // Bad file descriptor
771
772 // math software
773 DOM = 33, // Numerical argument out of domain
774 RANGE = 34, // Result too large
775
776 // non-blocking and interrupt i/o
777
778 /// Also used for `WOULDBLOCK`.
779 AGAIN = -0x7ffffff5,
780 INPROGRESS = -0x7fff8fdc,
781 ALREADY = -0x7fff8fdb,
782
783 // ipc/network software -- argument errors
784 NOTSOCK = 38, // Socket operation on non-socket
785 DESTADDRREQ = 39, // Destination address required
786 MSGSIZE = 40, // Message too long
787 PROTOTYPE = 41, // Protocol wrong type for socket
788 NOPROTOOPT = 42, // Protocol not available
789 PROTONOSUPPORT = 43, // Protocol not supported
790 SOCKTNOSUPPORT = 44, // Socket type not supported
791 /// Also used for `NOTSUP`.
792 OPNOTSUPP = 45, // Operation not supported
793 PFNOSUPPORT = 46, // Protocol family not supported
794 AFNOSUPPORT = 47, // Address family not supported by protocol family
795 ADDRINUSE = 48, // Address already in use
796 ADDRNOTAVAIL = 49, // Can't assign requested address
797
798 // ipc/network software -- operational errors
799 NETDOWN = 50, // Network is down
800 NETUNREACH = 51, // Network is unreachable
801 NETRESET = 52, // Network dropped connection on reset
802 CONNABORTED = 53, // Software caused connection abort
803 CONNRESET = 54, // Connection reset by peer
804 NOBUFS = 55, // No buffer space available
805 ISCONN = 56, // Socket is already connected
806 NOTCONN = 57, // Socket is not connected
807 SHUTDOWN = 58, // Can't send after socket shutdown
808 TOOMANYREFS = 59, // Too many references: can't splice
809 TIMEDOUT = 60, // Operation timed out
810 CONNREFUSED = 61, // Connection refused
811
812 LOOP = 62, // Too many levels of symbolic links
813 NAMETOOLONG = 63, // File name too long
814
815 // should be rearranged
816 HOSTDOWN = 64, // Host is down
817 HOSTUNREACH = 65, // No route to host
818 NOTEMPTY = 66, // Directory not empty
819
820 // quotas & mush
821 PROCLIM = 67, // Too many processes
822 USERS = 68, // Too many users
823 DQUOT = 69, // Disc quota exceeded
824
825 // Network File System
826 STALE = 70, // Stale NFS file handle
827 REMOTE = 71, // Too many levels of remote in path
828 BADRPC = 72, // RPC struct is bad
829 RPCMISMATCH = 73, // RPC version wrong
830 PROGUNAVAIL = 74, // RPC prog. not avail
831 PROGMISMATCH = 75, // Program version wrong
832 PROCUNAVAIL = 76, // Bad procedure for program
833
834 NOLCK = 77, // No locks available
835 NOSYS = 78, // Function not implemented
836
837 FTYPE = 79, // Inappropriate file type or format
838 AUTH = 80, // Authentication error
839 NEEDAUTH = 81, // Need authenticator
840 IDRM = 82, // Identifier removed
841 NOMSG = 83, // No message of desired type
842 OVERFLOW = 84, // Value too large to be stored in data type
843 CANCELED = 85, // Operation canceled
844 ILSEQ = 86, // Illegal byte sequence
845 NOATTR = 87, // Attribute not found
846
847 DOOFUS = 88, // Programming error
848
849 BADMSG = 89, // Bad message
850 MULTIHOP = 90, // Multihop attempted
851 NOLINK = 91, // Link has been severed
852 PROTO = 92, // Protocol error
853
854 NOTCAPABLE = 93, // Capabilities insufficient
855 CAPMODE = 94, // Not permitted in capability mode
856 NOTRECOVERABLE = 95, // State not recoverable
857 OWNERDEAD = 96, // Previous owner died
858
859 _,
860};
856861
857862pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
858863 .i386, .x86_64 => 2048,
lib/std/os/bits/linux.zig+11-4
......@@ -8,10 +8,10 @@ const maxInt = std.math.maxInt;
88const arch = @import("builtin").target.cpu.arch;
99pub usingnamespace @import("posix.zig");
1010
11pub usingnamespace switch (arch) {
12 .mips, .mipsel => @import("linux/errno-mips.zig"),
13 .sparc, .sparcel, .sparcv9 => @import("linux/errno-sparc.zig"),
14 else => @import("linux/errno-generic.zig"),
11pub const E = switch (arch) {
12 .mips, .mipsel => @import("linux/errno/mips.zig").E,
13 .sparc, .sparcel, .sparcv9 => @import("linux/errno/sparc.zig").E,
14 else => @import("linux/errno/generic.zig").E,
1515};
1616
1717pub usingnamespace switch (arch) {
......@@ -1665,6 +1665,13 @@ pub const io_uring_cqe = extern struct {
16651665 /// result code for this event
16661666 res: i32,
16671667 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 }
16681675};
16691676
16701677// 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 {
933933 ]u32,
934934};
935935
936pub const EPERM = 1; // Operation not permitted
937pub const ENOENT = 2; // No such file or directory
938pub const ESRCH = 3; // No such process
939pub const EINTR = 4; // Interrupted system call
940pub const EIO = 5; // Input/output error
941pub const ENXIO = 6; // Device not configured
942pub const E2BIG = 7; // Argument list too long
943pub const ENOEXEC = 8; // Exec format error
944pub const EBADF = 9; // Bad file descriptor
945pub const ECHILD = 10; // No child processes
946pub const EDEADLK = 11; // Resource deadlock avoided
947// 11 was EAGAIN
948pub const ENOMEM = 12; // Cannot allocate memory
949pub const EACCES = 13; // Permission denied
950pub const EFAULT = 14; // Bad address
951pub const ENOTBLK = 15; // Block device required
952pub const EBUSY = 16; // Device busy
953pub const EEXIST = 17; // File exists
954pub const EXDEV = 18; // Cross-device link
955pub const ENODEV = 19; // Operation not supported by device
956pub const ENOTDIR = 20; // Not a directory
957pub const EISDIR = 21; // Is a directory
958pub const EINVAL = 22; // Invalid argument
959pub const ENFILE = 23; // Too many open files in system
960pub const EMFILE = 24; // Too many open files
961pub const ENOTTY = 25; // Inappropriate ioctl for device
962pub const ETXTBSY = 26; // Text file busy
963pub const EFBIG = 27; // File too large
964pub const ENOSPC = 28; // No space left on device
965pub const ESPIPE = 29; // Illegal seek
966pub const EROFS = 30; // Read-only file system
967pub const EMLINK = 31; // Too many links
968pub const EPIPE = 32; // Broken pipe
969
970// math software
971pub const EDOM = 33; // Numerical argument out of domain
972pub const ERANGE = 34; // Result too large or too small
973
974// non-blocking and interrupt i/o
975pub const EAGAIN = 35; // Resource temporarily unavailable
976pub const EWOULDBLOCK = EAGAIN; // Operation would block
977pub const EINPROGRESS = 36; // Operation now in progress
978pub const EALREADY = 37; // Operation already in progress
979
980// ipc/network software -- argument errors
981pub const ENOTSOCK = 38; // Socket operation on non-socket
982pub const EDESTADDRREQ = 39; // Destination address required
983pub const EMSGSIZE = 40; // Message too long
984pub const EPROTOTYPE = 41; // Protocol wrong type for socket
985pub const ENOPROTOOPT = 42; // Protocol option not available
986pub const EPROTONOSUPPORT = 43; // Protocol not supported
987pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
988pub const EOPNOTSUPP = 45; // Operation not supported
989pub const EPFNOSUPPORT = 46; // Protocol family not supported
990pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
991pub const EADDRINUSE = 48; // Address already in use
992pub const EADDRNOTAVAIL = 49; // Can't assign requested address
993
994// ipc/network software -- operational errors
995pub const ENETDOWN = 50; // Network is down
996pub const ENETUNREACH = 51; // Network is unreachable
997pub const ENETRESET = 52; // Network dropped connection on reset
998pub const ECONNABORTED = 53; // Software caused connection abort
999pub const ECONNRESET = 54; // Connection reset by peer
1000pub const ENOBUFS = 55; // No buffer space available
1001pub const EISCONN = 56; // Socket is already connected
1002pub const ENOTCONN = 57; // Socket is not connected
1003pub const ESHUTDOWN = 58; // Can't send after socket shutdown
1004pub const ETOOMANYREFS = 59; // Too many references: can't splice
1005pub const ETIMEDOUT = 60; // Operation timed out
1006pub const ECONNREFUSED = 61; // Connection refused
1007
1008pub const ELOOP = 62; // Too many levels of symbolic links
1009pub const ENAMETOOLONG = 63; // File name too long
1010
1011// should be rearranged
1012pub const EHOSTDOWN = 64; // Host is down
1013pub const EHOSTUNREACH = 65; // No route to host
1014pub const ENOTEMPTY = 66; // Directory not empty
1015
1016// quotas & mush
1017pub const EPROCLIM = 67; // Too many processes
1018pub const EUSERS = 68; // Too many users
1019pub const EDQUOT = 69; // Disc quota exceeded
1020
1021// Network File System
1022pub const ESTALE = 70; // Stale NFS file handle
1023pub const EREMOTE = 71; // Too many levels of remote in path
1024pub const EBADRPC = 72; // RPC struct is bad
1025pub const ERPCMISMATCH = 73; // RPC version wrong
1026pub const EPROGUNAVAIL = 74; // RPC prog. not avail
1027pub const EPROGMISMATCH = 75; // Program version wrong
1028pub const EPROCUNAVAIL = 76; // Bad procedure for program
1029
1030pub const ENOLCK = 77; // No locks available
1031pub const ENOSYS = 78; // Function not implemented
1032
1033pub const EFTYPE = 79; // Inappropriate file type or format
1034pub const EAUTH = 80; // Authentication error
1035pub const ENEEDAUTH = 81; // Need authenticator
1036
1037// SystemV IPC
1038pub const EIDRM = 82; // Identifier removed
1039pub const ENOMSG = 83; // No message of desired type
1040pub const EOVERFLOW = 84; // Value too large to be stored in data type
1041
1042// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
1043pub const EILSEQ = 85; // Illegal byte sequence
1044
1045// From IEEE Std 1003.1-2001
1046// Base, Realtime, Threads or Thread Priority Scheduling option errors
1047pub const ENOTSUP = 86; // Not supported
1048
1049// Realtime option errors
1050pub const ECANCELED = 87; // Operation canceled
1051
1052// Realtime, XSI STREAMS option errors
1053pub const EBADMSG = 88; // Bad or Corrupt message
1054
1055// XSI STREAMS option errors
1056pub const ENODATA = 89; // No message available
1057pub const ENOSR = 90; // No STREAM resources
1058pub const ENOSTR = 91; // Not a STREAM
1059pub const ETIME = 92; // STREAM ioctl timeout
1060
1061// File system extended attribute errors
1062pub const ENOATTR = 93; // Attribute not found
1063
1064// Realtime, XSI STREAMS option errors
1065pub const EMULTIHOP = 94; // Multihop attempted
1066pub const ENOLINK = 95; // Link has been severed
1067pub const EPROTO = 96; // Protocol error
1068
1069pub const ELAST = 96; // Must equal largest errno
936pub const E = enum(u16) {
937 /// No error occurred.
938 SUCCESS = 0,
939 PERM = 1, // Operation not permitted
940 NOENT = 2, // No such file or directory
941 SRCH = 3, // No such process
942 INTR = 4, // Interrupted system call
943 IO = 5, // Input/output error
944 NXIO = 6, // Device not configured
945 @"2BIG" = 7, // Argument list too long
946 NOEXEC = 8, // Exec format error
947 BADF = 9, // Bad file descriptor
948 CHILD = 10, // No child processes
949 DEADLK = 11, // Resource deadlock avoided
950 // 11 was AGAIN
951 NOMEM = 12, // Cannot allocate memory
952 ACCES = 13, // Permission denied
953 FAULT = 14, // Bad address
954 NOTBLK = 15, // Block device required
955 BUSY = 16, // Device busy
956 EXIST = 17, // File exists
957 XDEV = 18, // Cross-device link
958 NODEV = 19, // Operation not supported by device
959 NOTDIR = 20, // Not a directory
960 ISDIR = 21, // Is a directory
961 INVAL = 22, // Invalid argument
962 NFILE = 23, // Too many open files in system
963 MFILE = 24, // Too many open files
964 NOTTY = 25, // Inappropriate ioctl for device
965 TXTBSY = 26, // Text file busy
966 FBIG = 27, // File too large
967 NOSPC = 28, // No space left on device
968 SPIPE = 29, // Illegal seek
969 ROFS = 30, // Read-only file system
970 MLINK = 31, // Too many links
971 PIPE = 32, // Broken pipe
972
973 // math software
974 DOM = 33, // Numerical argument out of domain
975 RANGE = 34, // Result too large or too small
976
977 // non-blocking and interrupt i/o
978 // also: WOULDBLOCK: operation would block
979 AGAIN = 35, // Resource temporarily unavailable
980 INPROGRESS = 36, // Operation now in progress
981 ALREADY = 37, // Operation already in progress
982
983 // ipc/network software -- argument errors
984 NOTSOCK = 38, // Socket operation on non-socket
985 DESTADDRREQ = 39, // Destination address required
986 MSGSIZE = 40, // Message too long
987 PROTOTYPE = 41, // Protocol wrong type for socket
988 NOPROTOOPT = 42, // Protocol option not available
989 PROTONOSUPPORT = 43, // Protocol not supported
990 SOCKTNOSUPPORT = 44, // Socket type not supported
991 OPNOTSUPP = 45, // Operation not supported
992 PFNOSUPPORT = 46, // Protocol family not supported
993 AFNOSUPPORT = 47, // Address family not supported by protocol family
994 ADDRINUSE = 48, // Address already in use
995 ADDRNOTAVAIL = 49, // Can't assign requested address
996
997 // ipc/network software -- operational errors
998 NETDOWN = 50, // Network is down
999 NETUNREACH = 51, // Network is unreachable
1000 NETRESET = 52, // Network dropped connection on reset
1001 CONNABORTED = 53, // Software caused connection abort
1002 CONNRESET = 54, // Connection reset by peer
1003 NOBUFS = 55, // No buffer space available
1004 ISCONN = 56, // Socket is already connected
1005 NOTCONN = 57, // Socket is not connected
1006 SHUTDOWN = 58, // Can't send after socket shutdown
1007 TOOMANYREFS = 59, // Too many references: can't splice
1008 TIMEDOUT = 60, // Operation timed out
1009 CONNREFUSED = 61, // Connection refused
1010
1011 LOOP = 62, // Too many levels of symbolic links
1012 NAMETOOLONG = 63, // File name too long
1013
1014 // should be rearranged
1015 HOSTDOWN = 64, // Host is down
1016 HOSTUNREACH = 65, // No route to host
1017 NOTEMPTY = 66, // Directory not empty
1018
1019 // quotas & mush
1020 PROCLIM = 67, // Too many processes
1021 USERS = 68, // Too many users
1022 DQUOT = 69, // Disc quota exceeded
1023
1024 // Network File System
1025 STALE = 70, // Stale NFS file handle
1026 REMOTE = 71, // Too many levels of remote in path
1027 BADRPC = 72, // RPC struct is bad
1028 RPCMISMATCH = 73, // RPC version wrong
1029 PROGUNAVAIL = 74, // RPC prog. not avail
1030 PROGMISMATCH = 75, // Program version wrong
1031 PROCUNAVAIL = 76, // Bad procedure for program
1032
1033 NOLCK = 77, // No locks available
1034 NOSYS = 78, // Function not implemented
1035
1036 FTYPE = 79, // Inappropriate file type or format
1037 AUTH = 80, // Authentication error
1038 NEEDAUTH = 81, // Need authenticator
1039
1040 // SystemV IPC
1041 IDRM = 82, // Identifier removed
1042 NOMSG = 83, // No message of desired type
1043 OVERFLOW = 84, // Value too large to be stored in data type
1044
1045 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
1046 ILSEQ = 85, // Illegal byte sequence
1047
1048 // From IEEE Std 1003.1-2001
1049 // Base, Realtime, Threads or Thread Priority Scheduling option errors
1050 NOTSUP = 86, // Not supported
1051
1052 // Realtime option errors
1053 CANCELED = 87, // Operation canceled
1054
1055 // Realtime, XSI STREAMS option errors
1056 BADMSG = 88, // Bad or Corrupt message
1057
1058 // XSI STREAMS option errors
1059 NODATA = 89, // No message available
1060 NOSR = 90, // No STREAM resources
1061 NOSTR = 91, // Not a STREAM
1062 TIME = 92, // STREAM ioctl timeout
1063
1064 // File system extended attribute errors
1065 NOATTR = 93, // Attribute not found
1066
1067 // Realtime, XSI STREAMS option errors
1068 MULTIHOP = 94, // Multihop attempted
1069 NOLINK = 95, // Link has been severed
1070 PROTO = 96, // Protocol error
1071
1072 _,
1073};
10701074
10711075pub const MINSIGSTKSZ = 8192;
10721076pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
lib/std/os/bits/openbsd.zig+124-119
......@@ -295,6 +295,7 @@ pub const AI_NUMERICSERV = 16;
295295pub const AI_ADDRCONFIG = 64;
296296
297297pub const PATH_MAX = 1024;
298pub const IOV_MAX = 1024;
298299
299300pub const STDIN_FILENO = 0;
300301pub const STDOUT_FILENO = 1;
......@@ -824,125 +825,129 @@ pub usingnamespace switch (builtin.target.cpu.arch) {
824825pub const sigset_t = c_uint;
825826pub const empty_sigset: sigset_t = 0;
826827
827pub const EPERM = 1; // Operation not permitted
828pub const ENOENT = 2; // No such file or directory
829pub const ESRCH = 3; // No such process
830pub const EINTR = 4; // Interrupted system call
831pub const EIO = 5; // Input/output error
832pub const ENXIO = 6; // Device not configured
833pub const E2BIG = 7; // Argument list too long
834pub const ENOEXEC = 8; // Exec format error
835pub const EBADF = 9; // Bad file descriptor
836pub const ECHILD = 10; // No child processes
837pub const EDEADLK = 11; // Resource deadlock avoided
838// 11 was EAGAIN
839pub const ENOMEM = 12; // Cannot allocate memory
840pub const EACCES = 13; // Permission denied
841pub const EFAULT = 14; // Bad address
842pub const ENOTBLK = 15; // Block device required
843pub const EBUSY = 16; // Device busy
844pub const EEXIST = 17; // File exists
845pub const EXDEV = 18; // Cross-device link
846pub const ENODEV = 19; // Operation not supported by device
847pub const ENOTDIR = 20; // Not a directory
848pub const EISDIR = 21; // Is a directory
849pub const EINVAL = 22; // Invalid argument
850pub const ENFILE = 23; // Too many open files in system
851pub const EMFILE = 24; // Too many open files
852pub const ENOTTY = 25; // Inappropriate ioctl for device
853pub const ETXTBSY = 26; // Text file busy
854pub const EFBIG = 27; // File too large
855pub const ENOSPC = 28; // No space left on device
856pub const ESPIPE = 29; // Illegal seek
857pub const EROFS = 30; // Read-only file system
858pub const EMLINK = 31; // Too many links
859pub const EPIPE = 32; // Broken pipe
860
861// math software
862pub const EDOM = 33; // Numerical argument out of domain
863pub const ERANGE = 34; // Result too large or too small
864
865// non-blocking and interrupt i/o
866pub const EAGAIN = 35; // Resource temporarily unavailable
867pub const EWOULDBLOCK = EAGAIN; // Operation would block
868pub const EINPROGRESS = 36; // Operation now in progress
869pub const EALREADY = 37; // Operation already in progress
870
871// ipc/network software -- argument errors
872pub const ENOTSOCK = 38; // Socket operation on non-socket
873pub const EDESTADDRREQ = 39; // Destination address required
874pub const EMSGSIZE = 40; // Message too long
875pub const EPROTOTYPE = 41; // Protocol wrong type for socket
876pub const ENOPROTOOPT = 42; // Protocol option not available
877pub const EPROTONOSUPPORT = 43; // Protocol not supported
878pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
879pub const EOPNOTSUPP = 45; // Operation not supported
880pub const EPFNOSUPPORT = 46; // Protocol family not supported
881pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
882pub const EADDRINUSE = 48; // Address already in use
883pub const EADDRNOTAVAIL = 49; // Can't assign requested address
884
885// ipc/network software -- operational errors
886pub const ENETDOWN = 50; // Network is down
887pub const ENETUNREACH = 51; // Network is unreachable
888pub const ENETRESET = 52; // Network dropped connection on reset
889pub const ECONNABORTED = 53; // Software caused connection abort
890pub const ECONNRESET = 54; // Connection reset by peer
891pub const ENOBUFS = 55; // No buffer space available
892pub const EISCONN = 56; // Socket is already connected
893pub const ENOTCONN = 57; // Socket is not connected
894pub const ESHUTDOWN = 58; // Can't send after socket shutdown
895pub const ETOOMANYREFS = 59; // Too many references: can't splice
896pub const ETIMEDOUT = 60; // Operation timed out
897pub const ECONNREFUSED = 61; // Connection refused
898
899pub const ELOOP = 62; // Too many levels of symbolic links
900pub const ENAMETOOLONG = 63; // File name too long
901
902// should be rearranged
903pub const EHOSTDOWN = 64; // Host is down
904pub const EHOSTUNREACH = 65; // No route to host
905pub const ENOTEMPTY = 66; // Directory not empty
906
907// quotas & mush
908pub const EPROCLIM = 67; // Too many processes
909pub const EUSERS = 68; // Too many users
910pub const EDQUOT = 69; // Disc quota exceeded
911
912// Network File System
913pub const ESTALE = 70; // Stale NFS file handle
914pub const EREMOTE = 71; // Too many levels of remote in path
915pub const EBADRPC = 72; // RPC struct is bad
916pub const ERPCMISMATCH = 73; // RPC version wrong
917pub const EPROGUNAVAIL = 74; // RPC prog. not avail
918pub const EPROGMISMATCH = 75; // Program version wrong
919pub const EPROCUNAVAIL = 76; // Bad procedure for program
920
921pub const ENOLCK = 77; // No locks available
922pub const ENOSYS = 78; // Function not implemented
923
924pub const EFTYPE = 79; // Inappropriate file type or format
925pub const EAUTH = 80; // Authentication error
926pub const ENEEDAUTH = 81; // Need authenticator
927pub const EIPSEC = 82; // IPsec processing failure
928pub const ENOATTR = 83; // Attribute not found
929
930// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
931pub const EILSEQ = 84; // Illegal byte sequence
932
933pub const ENOMEDIUM = 85; // No medium found
934pub const EMEDIUMTYPE = 86; // Wrong medium type
935pub const EOVERFLOW = 87; // Value too large to be stored in data type
936pub const ECANCELED = 88; // Operation canceled
937pub const EIDRM = 89; // Identifier removed
938pub const ENOMSG = 90; // No message of desired type
939pub const ENOTSUP = 91; // Not supported
940pub const EBADMSG = 92; // Bad or Corrupt message
941pub const ENOTRECOVERABLE = 93; // State not recoverable
942pub const EOWNERDEAD = 94; // Previous owner died
943pub const EPROTO = 95; // Protocol error
944
945pub const ELAST = 95; // Must equal largest errno
828pub const E = enum(u16) {
829 /// No error occurred.
830 SUCCESS = 0,
831 PERM = 1, // Operation not permitted
832 NOENT = 2, // No such file or directory
833 SRCH = 3, // No such process
834 INTR = 4, // Interrupted system call
835 IO = 5, // Input/output error
836 NXIO = 6, // Device not configured
837 @"2BIG" = 7, // Argument list too long
838 NOEXEC = 8, // Exec format error
839 BADF = 9, // Bad file descriptor
840 CHILD = 10, // No child processes
841 DEADLK = 11, // Resource deadlock avoided
842 // 11 was AGAIN
843 NOMEM = 12, // Cannot allocate memory
844 ACCES = 13, // Permission denied
845 FAULT = 14, // Bad address
846 NOTBLK = 15, // Block device required
847 BUSY = 16, // Device busy
848 EXIST = 17, // File exists
849 XDEV = 18, // Cross-device link
850 NODEV = 19, // Operation not supported by device
851 NOTDIR = 20, // Not a directory
852 ISDIR = 21, // Is a directory
853 INVAL = 22, // Invalid argument
854 NFILE = 23, // Too many open files in system
855 MFILE = 24, // Too many open files
856 NOTTY = 25, // Inappropriate ioctl for device
857 TXTBSY = 26, // Text file busy
858 FBIG = 27, // File too large
859 NOSPC = 28, // No space left on device
860 SPIPE = 29, // Illegal seek
861 ROFS = 30, // Read-only file system
862 MLINK = 31, // Too many links
863 PIPE = 32, // Broken pipe
864
865 // math software
866 DOM = 33, // Numerical argument out of domain
867 RANGE = 34, // Result too large or too small
868
869 // non-blocking and interrupt i/o
870 // also: WOULDBLOCK: operation would block
871 AGAIN = 35, // Resource temporarily unavailable
872 INPROGRESS = 36, // Operation now in progress
873 ALREADY = 37, // Operation already in progress
874
875 // ipc/network software -- argument errors
876 NOTSOCK = 38, // Socket operation on non-socket
877 DESTADDRREQ = 39, // Destination address required
878 MSGSIZE = 40, // Message too long
879 PROTOTYPE = 41, // Protocol wrong type for socket
880 NOPROTOOPT = 42, // Protocol option not available
881 PROTONOSUPPORT = 43, // Protocol not supported
882 SOCKTNOSUPPORT = 44, // Socket type not supported
883 OPNOTSUPP = 45, // Operation not supported
884 PFNOSUPPORT = 46, // Protocol family not supported
885 AFNOSUPPORT = 47, // Address family not supported by protocol family
886 ADDRINUSE = 48, // Address already in use
887 ADDRNOTAVAIL = 49, // Can't assign requested address
888
889 // ipc/network software -- operational errors
890 NETDOWN = 50, // Network is down
891 NETUNREACH = 51, // Network is unreachable
892 NETRESET = 52, // Network dropped connection on reset
893 CONNABORTED = 53, // Software caused connection abort
894 CONNRESET = 54, // Connection reset by peer
895 NOBUFS = 55, // No buffer space available
896 ISCONN = 56, // Socket is already connected
897 NOTCONN = 57, // Socket is not connected
898 SHUTDOWN = 58, // Can't send after socket shutdown
899 TOOMANYREFS = 59, // Too many references: can't splice
900 TIMEDOUT = 60, // Operation timed out
901 CONNREFUSED = 61, // Connection refused
902
903 LOOP = 62, // Too many levels of symbolic links
904 NAMETOOLONG = 63, // File name too long
905
906 // should be rearranged
907 HOSTDOWN = 64, // Host is down
908 HOSTUNREACH = 65, // No route to host
909 NOTEMPTY = 66, // Directory not empty
910
911 // quotas & mush
912 PROCLIM = 67, // Too many processes
913 USERS = 68, // Too many users
914 DQUOT = 69, // Disc quota exceeded
915
916 // Network File System
917 STALE = 70, // Stale NFS file handle
918 REMOTE = 71, // Too many levels of remote in path
919 BADRPC = 72, // RPC struct is bad
920 RPCMISMATCH = 73, // RPC version wrong
921 PROGUNAVAIL = 74, // RPC prog. not avail
922 PROGMISMATCH = 75, // Program version wrong
923 PROCUNAVAIL = 76, // Bad procedure for program
924
925 NOLCK = 77, // No locks available
926 NOSYS = 78, // Function not implemented
927
928 FTYPE = 79, // Inappropriate file type or format
929 AUTH = 80, // Authentication error
930 NEEDAUTH = 81, // Need authenticator
931 IPSEC = 82, // IPsec processing failure
932 NOATTR = 83, // Attribute not found
933
934 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
935 ILSEQ = 84, // Illegal byte sequence
936
937 NOMEDIUM = 85, // No medium found
938 MEDIUMTYPE = 86, // Wrong medium type
939 OVERFLOW = 87, // Value too large to be stored in data type
940 CANCELED = 88, // Operation canceled
941 IDRM = 89, // Identifier removed
942 NOMSG = 90, // No message of desired type
943 NOTSUP = 91, // Not supported
944 BADMSG = 92, // Bad or Corrupt message
945 NOTRECOVERABLE = 93, // State not recoverable
946 OWNERDEAD = 94, // Previous owner died
947 PROTO = 95, // Protocol error
948
949 _,
950};
946951
947952const _MAX_PAGE_SHIFT = switch (builtin.target.cpu.arch) {
948953 .i386 => 12,
lib/std/os/bits/wasi.zig+83-80
......@@ -111,86 +111,89 @@ pub const dirent_t = extern struct {
111111 d_type: filetype_t,
112112};
113113
114pub const errno_t = u16;
115pub const ESUCCESS: errno_t = 0;
116pub const E2BIG: errno_t = 1;
117pub const EACCES: errno_t = 2;
118pub const EADDRINUSE: errno_t = 3;
119pub const EADDRNOTAVAIL: errno_t = 4;
120pub const EAFNOSUPPORT: errno_t = 5;
121pub const EAGAIN: errno_t = 6;
122pub const EWOULDBLOCK = EAGAIN;
123pub const EALREADY: errno_t = 7;
124pub const EBADF: errno_t = 8;
125pub const EBADMSG: errno_t = 9;
126pub const EBUSY: errno_t = 10;
127pub const ECANCELED: errno_t = 11;
128pub const ECHILD: errno_t = 12;
129pub const ECONNABORTED: errno_t = 13;
130pub const ECONNREFUSED: errno_t = 14;
131pub const ECONNRESET: errno_t = 15;
132pub const EDEADLK: errno_t = 16;
133pub const EDESTADDRREQ: errno_t = 17;
134pub const EDOM: errno_t = 18;
135pub const EDQUOT: errno_t = 19;
136pub const EEXIST: errno_t = 20;
137pub const EFAULT: errno_t = 21;
138pub const EFBIG: errno_t = 22;
139pub const EHOSTUNREACH: errno_t = 23;
140pub const EIDRM: errno_t = 24;
141pub const EILSEQ: errno_t = 25;
142pub const EINPROGRESS: errno_t = 26;
143pub const EINTR: errno_t = 27;
144pub const EINVAL: errno_t = 28;
145pub const EIO: errno_t = 29;
146pub const EISCONN: errno_t = 30;
147pub const EISDIR: errno_t = 31;
148pub const ELOOP: errno_t = 32;
149pub const EMFILE: errno_t = 33;
150pub const EMLINK: errno_t = 34;
151pub const EMSGSIZE: errno_t = 35;
152pub const EMULTIHOP: errno_t = 36;
153pub const ENAMETOOLONG: errno_t = 37;
154pub const ENETDOWN: errno_t = 38;
155pub const ENETRESET: errno_t = 39;
156pub const ENETUNREACH: errno_t = 40;
157pub const ENFILE: errno_t = 41;
158pub const ENOBUFS: errno_t = 42;
159pub const ENODEV: errno_t = 43;
160pub const ENOENT: errno_t = 44;
161pub const ENOEXEC: errno_t = 45;
162pub const ENOLCK: errno_t = 46;
163pub const ENOLINK: errno_t = 47;
164pub const ENOMEM: errno_t = 48;
165pub const ENOMSG: errno_t = 49;
166pub const ENOPROTOOPT: errno_t = 50;
167pub const ENOSPC: errno_t = 51;
168pub const ENOSYS: errno_t = 52;
169pub const ENOTCONN: errno_t = 53;
170pub const ENOTDIR: errno_t = 54;
171pub const ENOTEMPTY: errno_t = 55;
172pub const ENOTRECOVERABLE: errno_t = 56;
173pub const ENOTSOCK: errno_t = 57;
174pub const ENOTSUP: errno_t = 58;
175pub const EOPNOTSUPP = ENOTSUP;
176pub const ENOTTY: errno_t = 59;
177pub const ENXIO: errno_t = 60;
178pub const EOVERFLOW: errno_t = 61;
179pub const EOWNERDEAD: errno_t = 62;
180pub const EPERM: errno_t = 63;
181pub const EPIPE: errno_t = 64;
182pub const EPROTO: errno_t = 65;
183pub const EPROTONOSUPPORT: errno_t = 66;
184pub const EPROTOTYPE: errno_t = 67;
185pub const ERANGE: errno_t = 68;
186pub const EROFS: errno_t = 69;
187pub const ESPIPE: errno_t = 70;
188pub const ESRCH: errno_t = 71;
189pub const ESTALE: errno_t = 72;
190pub const ETIMEDOUT: errno_t = 73;
191pub const ETXTBSY: errno_t = 74;
192pub const EXDEV: errno_t = 75;
193pub const ENOTCAPABLE: errno_t = 76;
114pub const errno_t = enum(u16) {
115 SUCCESS = 0,
116 @"2BIG" = 1,
117 ACCES = 2,
118 ADDRINUSE = 3,
119 ADDRNOTAVAIL = 4,
120 AFNOSUPPORT = 5,
121 /// This is also the error code used for `WOULDBLOCK`.
122 AGAIN = 6,
123 ALREADY = 7,
124 BADF = 8,
125 BADMSG = 9,
126 BUSY = 10,
127 CANCELED = 11,
128 CHILD = 12,
129 CONNABORTED = 13,
130 CONNREFUSED = 14,
131 CONNRESET = 15,
132 DEADLK = 16,
133 DESTADDRREQ = 17,
134 DOM = 18,
135 DQUOT = 19,
136 EXIST = 20,
137 FAULT = 21,
138 FBIG = 22,
139 HOSTUNREACH = 23,
140 IDRM = 24,
141 ILSEQ = 25,
142 INPROGRESS = 26,
143 INTR = 27,
144 INVAL = 28,
145 IO = 29,
146 ISCONN = 30,
147 ISDIR = 31,
148 LOOP = 32,
149 MFILE = 33,
150 MLINK = 34,
151 MSGSIZE = 35,
152 MULTIHOP = 36,
153 NAMETOOLONG = 37,
154 NETDOWN = 38,
155 NETRESET = 39,
156 NETUNREACH = 40,
157 NFILE = 41,
158 NOBUFS = 42,
159 NODEV = 43,
160 NOENT = 44,
161 NOEXEC = 45,
162 NOLCK = 46,
163 NOLINK = 47,
164 NOMEM = 48,
165 NOMSG = 49,
166 NOPROTOOPT = 50,
167 NOSPC = 51,
168 NOSYS = 52,
169 NOTCONN = 53,
170 NOTDIR = 54,
171 NOTEMPTY = 55,
172 NOTRECOVERABLE = 56,
173 NOTSOCK = 57,
174 /// This is also the code used for `NOTSUP`.
175 OPNOTSUPP = 58,
176 NOTTY = 59,
177 NXIO = 60,
178 OVERFLOW = 61,
179 OWNERDEAD = 62,
180 PERM = 63,
181 PIPE = 64,
182 PROTO = 65,
183 PROTONOSUPPORT = 66,
184 PROTOTYPE = 67,
185 RANGE = 68,
186 ROFS = 69,
187 SPIPE = 70,
188 SRCH = 71,
189 STALE = 72,
190 TIMEDOUT = 73,
191 TXTBSY = 74,
192 XDEV = 75,
193 NOTCAPABLE = 76,
194 _,
195};
196pub const E = errno_t;
194197
195198pub const event_t = extern struct {
196199 userdata: userdata_t,
lib/std/os/bits/windows.zig+90-86
......@@ -87,93 +87,97 @@ pub const SEEK_SET = 0;
8787pub const SEEK_CUR = 1;
8888pub const SEEK_END = 2;
8989
90pub const EPERM = 1;
91pub const ENOENT = 2;
92pub const ESRCH = 3;
93pub const EINTR = 4;
94pub const EIO = 5;
95pub const ENXIO = 6;
96pub const E2BIG = 7;
97pub const ENOEXEC = 8;
98pub const EBADF = 9;
99pub const ECHILD = 10;
100pub const EAGAIN = 11;
101pub const ENOMEM = 12;
102pub const EACCES = 13;
103pub const EFAULT = 14;
104pub const EBUSY = 16;
105pub const EEXIST = 17;
106pub const EXDEV = 18;
107pub const ENODEV = 19;
108pub const ENOTDIR = 20;
109pub const EISDIR = 21;
110pub const ENFILE = 23;
111pub const EMFILE = 24;
112pub const ENOTTY = 25;
113pub const EFBIG = 27;
114pub const ENOSPC = 28;
115pub const ESPIPE = 29;
116pub const EROFS = 30;
117pub const EMLINK = 31;
118pub const EPIPE = 32;
119pub const EDOM = 33;
120pub const EDEADLK = 36;
121pub const ENAMETOOLONG = 38;
122pub const ENOLCK = 39;
123pub const ENOSYS = 40;
124pub const ENOTEMPTY = 41;
125
126pub const EINVAL = 22;
127pub const ERANGE = 34;
128pub const EILSEQ = 42;
129pub const STRUNCATE = 80;
90pub const E = enum(u16) {
91 /// No error occurred.
92 SUCCESS = 0,
93 PERM = 1,
94 NOENT = 2,
95 SRCH = 3,
96 INTR = 4,
97 IO = 5,
98 NXIO = 6,
99 @"2BIG" = 7,
100 NOEXEC = 8,
101 BADF = 9,
102 CHILD = 10,
103 AGAIN = 11,
104 NOMEM = 12,
105 ACCES = 13,
106 FAULT = 14,
107 BUSY = 16,
108 EXIST = 17,
109 XDEV = 18,
110 NODEV = 19,
111 NOTDIR = 20,
112 ISDIR = 21,
113 NFILE = 23,
114 MFILE = 24,
115 NOTTY = 25,
116 FBIG = 27,
117 NOSPC = 28,
118 SPIPE = 29,
119 ROFS = 30,
120 MLINK = 31,
121 PIPE = 32,
122 DOM = 33,
123 /// Also means `DEADLOCK`.
124 DEADLK = 36,
125 NAMETOOLONG = 38,
126 NOLCK = 39,
127 NOSYS = 40,
128 NOTEMPTY = 41,
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 versions
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;
180pub const STRUNCATE = 80;
177181
178182pub const F_OK = 0;
179183
lib/std/os/linux.zig+8-7
......@@ -91,9 +91,10 @@ fn splitValue64(val: i64) [2]u32 {
9191}
9292
9393/// 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 {
9595 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);
9798}
9899
99100pub fn dup(old: i32) usize {
......@@ -281,7 +282,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
281282 if (@hasField(SYS, "mmap2")) {
282283 // Make sure the offset is also specified in multiples of page size
283284 if ((offset & (MMAP2_UNIT - 1)) != 0)
284 return @bitCast(usize, @as(isize, -EINVAL));
285 return @bitCast(usize, -@as(isize, @enumToInt(E.INVAL)));
285286
286287 return syscall6(
287288 .mmap2,
......@@ -746,7 +747,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
746747 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
747748 const rc = f(clk_id, tp);
748749 switch (rc) {
749 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc,
750 0, @bitCast(usize, -@as(isize, @enumToInt(E.INVAL))) => return rc,
750751 else => {},
751752 }
752753 }
......@@ -764,7 +765,7 @@ fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
764765 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
765766 return f(clk, ts);
766767 }
767 return @bitCast(usize, @as(isize, -ENOSYS));
768 return @bitCast(usize, -@as(isize, @enumToInt(E.NOSYS)));
768769}
769770
770771pub 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
961962 .sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),
962963 else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),
963964 };
964 if (getErrno(result) != 0) return result;
965 if (getErrno(result) != .SUCCESS) return result;
965966
966967 if (oact) |old| {
967968 old.handler.handler = oldksa.handler;
......@@ -1202,7 +1203,7 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
12021203 @ptrToInt(statx_buf),
12031204 );
12041205 }
1205 return @bitCast(usize, @as(isize, -ENOSYS));
1206 return @bitCast(usize, -@as(isize, @enumToInt(E.NOSYS)));
12061207}
12071208
12081209pub 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
15081508 attr.map_create.max_entries = max_entries;
15091509
15101510 const rc = bpf(.map_create, &attr, @sizeOf(MapCreateAttr));
1511 return switch (errno(rc)) {
1512 0 => @intCast(fd_t, rc),
1513 EINVAL => error.MapTypeOrAttrInvalid,
1514 ENOMEM => error.SystemResources,
1515 EPERM => error.AccessDenied,
1516 else => |err| unexpectedErrno(err),
1517 };
1511 switch (errno(rc)) {
1512 .SUCCESS => return @intCast(fd_t, rc),
1513 .INVAL => return error.MapTypeOrAttrInvalid,
1514 .NOMEM => return error.SystemResources,
1515 .PERM => return error.AccessDenied,
1516 else => |err| return unexpectedErrno(err),
1517 }
15181518}
15191519
15201520test "map_create" {
......@@ -1533,12 +1533,12 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void {
15331533
15341534 const rc = bpf(.map_lookup_elem, &attr, @sizeOf(MapElemAttr));
15351535 switch (errno(rc)) {
1536 0 => return,
1537 EBADF => return error.BadFd,
1538 EFAULT => unreachable,
1539 EINVAL => return error.FieldInAttrNeedsZeroing,
1540 ENOENT => return error.NotFound,
1541 EPERM => return error.AccessDenied,
1536 .SUCCESS => return,
1537 .BADF => return error.BadFd,
1538 .FAULT => unreachable,
1539 .INVAL => return error.FieldInAttrNeedsZeroing,
1540 .NOENT => return error.NotFound,
1541 .PERM => return error.AccessDenied,
15421542 else => |err| return unexpectedErrno(err),
15431543 }
15441544}
......@@ -1555,13 +1555,13 @@ pub fn map_update_elem(fd: fd_t, key: []const u8, value: []const u8, flags: u64)
15551555
15561556 const rc = bpf(.map_update_elem, &attr, @sizeOf(MapElemAttr));
15571557 switch (errno(rc)) {
1558 0 => return,
1559 E2BIG => return error.ReachedMaxEntries,
1560 EBADF => return error.BadFd,
1561 EFAULT => unreachable,
1562 EINVAL => return error.FieldInAttrNeedsZeroing,
1563 ENOMEM => return error.SystemResources,
1564 EPERM => return error.AccessDenied,
1558 .SUCCESS => return,
1559 .@"2BIG" => return error.ReachedMaxEntries,
1560 .BADF => return error.BadFd,
1561 .FAULT => unreachable,
1562 .INVAL => return error.FieldInAttrNeedsZeroing,
1563 .NOMEM => return error.SystemResources,
1564 .PERM => return error.AccessDenied,
15651565 else => |err| return unexpectedErrno(err),
15661566 }
15671567}
......@@ -1576,12 +1576,12 @@ pub fn map_delete_elem(fd: fd_t, key: []const u8) !void {
15761576
15771577 const rc = bpf(.map_delete_elem, &attr, @sizeOf(MapElemAttr));
15781578 switch (errno(rc)) {
1579 0 => return,
1580 EBADF => return error.BadFd,
1581 EFAULT => unreachable,
1582 EINVAL => return error.FieldInAttrNeedsZeroing,
1583 ENOENT => return error.NotFound,
1584 EPERM => return error.AccessDenied,
1579 .SUCCESS => return,
1580 .BADF => return error.BadFd,
1581 .FAULT => unreachable,
1582 .INVAL => return error.FieldInAttrNeedsZeroing,
1583 .NOENT => return error.NotFound,
1584 .PERM => return error.AccessDenied,
15851585 else => |err| return unexpectedErrno(err),
15861586 }
15871587}
......@@ -1639,11 +1639,11 @@ pub fn prog_load(
16391639
16401640 const rc = bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));
16411641 return switch (errno(rc)) {
1642 0 => @intCast(fd_t, rc),
1643 EACCES => error.UnsafeProgram,
1644 EFAULT => unreachable,
1645 EINVAL => error.InvalidProgram,
1646 EPERM => error.AccessDenied,
1642 .SUCCESS => @intCast(fd_t, rc),
1643 .ACCES => error.UnsafeProgram,
1644 .FAULT => unreachable,
1645 .INVAL => error.InvalidProgram,
1646 .PERM => error.AccessDenied,
16471647 else => |err| unexpectedErrno(err),
16481648 };
16491649}
lib/std/os/linux/io_uring.zig+44-44
......@@ -54,19 +54,19 @@ pub const IO_Uring = struct {
5454
5555 const res = linux.io_uring_setup(entries, p);
5656 switch (linux.getErrno(res)) {
57 0 => {},
58 linux.EFAULT => return error.ParamsOutsideAccessibleAddressSpace,
57 .SUCCESS => {},
58 .FAULT => return error.ParamsOutsideAccessibleAddressSpace,
5959 // The resv array contains non-zero data, p.flags contains an unsupported flag,
6060 // entries out of bounds, IORING_SETUP_SQ_AFF was specified without IORING_SETUP_SQPOLL,
6161 // or IORING_SETUP_CQSIZE was specified but io_uring_params.cq_entries was invalid:
62 linux.EINVAL => return error.ArgumentsInvalid,
63 linux.EMFILE => return error.ProcessFdQuotaExceeded,
64 linux.ENFILE => return error.SystemFdQuotaExceeded,
65 linux.ENOMEM => return error.SystemResources,
62 .INVAL => return error.ArgumentsInvalid,
63 .MFILE => return error.ProcessFdQuotaExceeded,
64 .NFILE => return error.SystemFdQuotaExceeded,
65 .NOMEM => return error.SystemResources,
6666 // IORING_SETUP_SQPOLL was specified but effective user ID lacks sufficient privileges,
6767 // or a container seccomp policy prohibits io_uring syscalls:
68 linux.EPERM => return error.PermissionDenied,
69 linux.ENOSYS => return error.SystemOutdated,
68 .PERM => return error.PermissionDenied,
69 .NOSYS => return error.SystemOutdated,
7070 else => |errno| return os.unexpectedErrno(errno),
7171 }
7272 const fd = @intCast(os.fd_t, res);
......@@ -180,31 +180,31 @@ pub const IO_Uring = struct {
180180 assert(self.fd >= 0);
181181 const res = linux.io_uring_enter(self.fd, to_submit, min_complete, flags, null);
182182 switch (linux.getErrno(res)) {
183 0 => {},
183 .SUCCESS => {},
184184 // The kernel was unable to allocate memory or ran out of resources for the request.
185185 // The application should wait for some completions and try again:
186 linux.EAGAIN => return error.SystemResources,
186 .AGAIN => return error.SystemResources,
187187 // 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,
189189 // The file descriptor is valid, but the ring is not in the right state.
190190 // See io_uring_register(2) for how to enable the ring.
191 linux.EBADFD => return error.FileDescriptorInBadState,
191 .BADFD => return error.FileDescriptorInBadState,
192192 // The application attempted to overcommit the number of requests it can have pending.
193193 // The application should wait for some completions and try again:
194 linux.EBUSY => return error.CompletionQueueOvercommitted,
194 .BUSY => return error.CompletionQueueOvercommitted,
195195 // 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,
197197 // The buffer is outside the process' accessible address space, or IORING_OP_READ_FIXED
198198 // or IORING_OP_WRITE_FIXED was specified but no buffers were registered, or the range
199199 // described by `addr` and `len` is not within the buffer registered at `buf_index`:
200 linux.EFAULT => return error.BufferInvalid,
201 linux.ENXIO => return error.RingShuttingDown,
200 .FAULT => return error.BufferInvalid,
201 .NXIO => return error.RingShuttingDown,
202202 // The kernel believes our `self.fd` does not refer to an io_uring instance,
203203 // or the opcode is valid but not supported by this kernel (more likely):
204 linux.EOPNOTSUPP => return error.OpcodeNotSupported,
204 .OPNOTSUPP => return error.OpcodeNotSupported,
205205 // The operation was interrupted by a delivery of a signal before it could complete.
206206 // This can happen while waiting for events with IORING_ENTER_GETEVENTS:
207 linux.EINTR => return error.SignalInterrupt,
207 .INTR => return error.SignalInterrupt,
208208 else => |errno| return os.unexpectedErrno(errno),
209209 }
210210 return @intCast(u32, res);
......@@ -681,22 +681,22 @@ pub const IO_Uring = struct {
681681
682682 fn handle_registration_result(res: usize) !void {
683683 switch (linux.getErrno(res)) {
684 0 => {},
684 .SUCCESS => {},
685685 // One or more fds in the array are invalid, or the kernel does not support sparse sets:
686 linux.EBADF => return error.FileDescriptorInvalid,
687 linux.EBUSY => return error.FilesAlreadyRegistered,
688 linux.EINVAL => return error.FilesEmpty,
686 .BADF => return error.FileDescriptorInvalid,
687 .BUSY => return error.FilesAlreadyRegistered,
688 .INVAL => return error.FilesEmpty,
689689 // Adding `nr_args` file references would exceed the maximum allowed number of files the
690690 // user is allowed to have according to the per-user RLIMIT_NOFILE resource limit and
691691 // the CAP_SYS_RESOURCE capability is not set, or `nr_args` exceeds the maximum allowed
692692 // 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,
694694 // Insufficient kernel resources, or the caller had a non-zero RLIMIT_MEMLOCK soft
695695 // resource limit but tried to lock more memory than the limit permitted (not enforced
696696 // when the process is privileged with CAP_IPC_LOCK):
697 linux.ENOMEM => return error.SystemResources,
697 .NOMEM => return error.SystemResources,
698698 // 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,
700700 else => |errno| return os.unexpectedErrno(errno),
701701 }
702702 }
......@@ -706,8 +706,8 @@ pub const IO_Uring = struct {
706706 assert(self.fd >= 0);
707707 const res = linux.io_uring_register(self.fd, .UNREGISTER_FILES, null, 0);
708708 switch (linux.getErrno(res)) {
709 0 => {},
710 linux.ENXIO => return error.FilesNotRegistered,
709 .SUCCESS => {},
710 .NXIO => return error.FilesNotRegistered,
711711 else => |errno| return os.unexpectedErrno(errno),
712712 }
713713 }
......@@ -1272,8 +1272,8 @@ test "write/read" {
12721272 const cqe_read = try ring.copy_cqe();
12731273 // Prior to Linux Kernel 5.6 this is the only way to test for read/write support:
12741274 // https://lwn.net/Articles/809820/
1275 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
1276 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
1275 if (cqe_write.err() == .INVAL) return error.SkipZigTest;
1276 if (cqe_read.err() == .INVAL) return error.SkipZigTest;
12771277 try testing.expectEqual(linux.io_uring_cqe{
12781278 .user_data = 0x11111111,
12791279 .res = buffer_write.len,
......@@ -1322,11 +1322,11 @@ test "openat" {
13221322
13231323 const cqe_openat = try ring.copy_cqe();
13241324 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;
13261326 // AT_FDCWD is not fully supported before kernel 5.6:
13271327 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
13281328 // 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) {
13301330 return error.SkipZigTest;
13311331 }
13321332 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
......@@ -1357,7 +1357,7 @@ test "close" {
13571357 try testing.expectEqual(@as(u32, 1), try ring.submit());
13581358
13591359 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;
13611361 try testing.expectEqual(linux.io_uring_cqe{
13621362 .user_data = 0x44444444,
13631363 .res = 0,
......@@ -1397,9 +1397,9 @@ test "accept/connect/send/recv" {
13971397 try testing.expectEqual(@as(u32, 1), try ring.submit());
13981398
13991399 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;
14011401 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
14041404 // The accept/connect CQEs may arrive in any order, the connect CQE will sometimes come first:
14051405 if (cqe_accept.user_data == 0xcccccccc and cqe_connect.user_data == 0xaaaaaaaa) {
......@@ -1425,7 +1425,7 @@ test "accept/connect/send/recv" {
14251425 try testing.expectEqual(@as(u32, 2), try ring.submit());
14261426
14271427 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;
14291429 try testing.expectEqual(linux.io_uring_cqe{
14301430 .user_data = 0xeeeeeeee,
14311431 .res = buffer_send.len,
......@@ -1433,7 +1433,7 @@ test "accept/connect/send/recv" {
14331433 }, cqe_send);
14341434
14351435 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;
14371437 try testing.expectEqual(linux.io_uring_cqe{
14381438 .user_data = 0xffffffff,
14391439 .res = buffer_recv.len,
......@@ -1466,7 +1466,7 @@ test "timeout (after a relative time)" {
14661466
14671467 try testing.expectEqual(linux.io_uring_cqe{
14681468 .user_data = 0x55555555,
1469 .res = -linux.ETIME,
1469 .res = -@as(i32, @enumToInt(linux.E.TIME)),
14701470 .flags = 0,
14711471 }, cqe);
14721472
......@@ -1535,14 +1535,14 @@ test "timeout_remove" {
15351535 // We use IORING_FEAT_RW_CUR_POS as a safety check here to make sure we are at least pre-5.6.
15361536 // We don't want to skip this test for newer kernels.
15371537 if (cqe_timeout.user_data == 0x99999999 and
1538 cqe_timeout.res == -linux.EBADF and
1538 cqe_timeout.err() == .BADF and
15391539 (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0)
15401540 {
15411541 return error.SkipZigTest;
15421542 }
15431543 try testing.expectEqual(linux.io_uring_cqe{
15441544 .user_data = 0x88888888,
1545 .res = -linux.ECANCELED,
1545 .res = -@as(i32, @enumToInt(linux.E.CANCELED)),
15461546 .flags = 0,
15471547 }, cqe_timeout);
15481548
......@@ -1578,15 +1578,15 @@ test "fallocate" {
15781578 try testing.expectEqual(@as(u32, 1), try ring.submit());
15791579
15801580 const cqe = try ring.copy_cqe();
1581 switch (-cqe.res) {
1582 0 => {},
1581 switch (cqe.err()) {
1582 .SUCCESS => {},
15831583 // This kernel's io_uring does not yet implement fallocate():
1584 linux.EINVAL => return error.SkipZigTest,
1584 .INVAL => return error.SkipZigTest,
15851585 // This kernel does not implement fallocate():
1586 linux.ENOSYS => return error.SkipZigTest,
1586 .NOSYS => return error.SkipZigTest,
15871587 // The filesystem containing the file referred to by fd does not support this operation;
15881588 // 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,
15901590 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
15911591 }
15921592 try testing.expectEqual(linux.io_uring_cqe{
lib/std/os/linux/test.zig+15-15
......@@ -22,9 +22,9 @@ test "fallocate" {
2222
2323 const len: i64 = 65536;
2424 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
25 0 => {},
26 linux.ENOSYS => return error.SkipZigTest,
27 linux.EOPNOTSUPP => return error.SkipZigTest,
25 .SUCCESS => {},
26 .NOSYS => return error.SkipZigTest,
27 .OPNOTSUPP => return error.SkipZigTest,
2828 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
2929 }
3030
......@@ -37,11 +37,11 @@ test "getpid" {
3737
3838test "timer" {
3939 const epoll_fd = linux.epoll_create();
40 var err: usize = linux.getErrno(epoll_fd);
41 try expect(err == 0);
40 var err: linux.E = linux.getErrno(epoll_fd);
41 try expect(err == .SUCCESS);
4242
4343 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
4646 const time_interval = linux.timespec{
4747 .tv_sec = 0,
......@@ -53,22 +53,22 @@ test "timer" {
5353 .it_value = time_interval,
5454 };
5555
56 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
57 try expect(err == 0);
56 err = linux.getErrno(linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null));
57 try expect(err == .SUCCESS);
5858
5959 var event = linux.epoll_event{
6060 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
6161 .data = linux.epoll_data{ .ptr = 0 },
6262 };
6363
64 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
65 try expect(err == 0);
64 err = linux.getErrno(linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event));
65 try expect(err == .SUCCESS);
6666
6767 const events_one: linux.epoll_event = undefined;
6868 var events = [_]linux.epoll_event{events_one} ** 8;
6969
70 // TODO implicit cast from *[N]T to [*]T
71 err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
70 err = linux.getErrno(linux.epoll_wait(@intCast(i32, epoll_fd), &events, 8, -1));
71 try expect(err == .SUCCESS);
7272}
7373
7474test "statx" {
......@@ -81,15 +81,15 @@ test "statx" {
8181
8282 var statx_buf: linux.Statx = undefined;
8383 switch (linux.getErrno(linux.statx(file.handle, "", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
84 0 => {},
84 .SUCCESS => {},
8585 // The statx syscall was only introduced in linux 4.11
86 linux.ENOSYS => return error.SkipZigTest,
86 .NOSYS => return error.SkipZigTest,
8787 else => unreachable,
8888 }
8989
9090 var stat_buf: linux.kernel_stat = undefined;
9191 switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
92 0 => {},
92 .SUCCESS => {},
9393 else => unreachable,
9494 }
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
8383pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t;
8484
8585/// 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 {
8787 return r;
8888}
lib/std/process.zig+4-4
......@@ -93,7 +93,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
9393 var environ_buf_size: usize = undefined;
9494
9595 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) {
9797 return os.unexpectedErrno(environ_sizes_get_ret);
9898 }
9999
......@@ -103,7 +103,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
103103 defer allocator.free(environ_buf);
104104
105105 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) {
107107 return os.unexpectedErrno(environ_get_ret);
108108 }
109109
......@@ -255,7 +255,7 @@ pub const ArgIteratorWasi = struct {
255255 var buf_size: usize = undefined;
256256
257257 switch (w.args_sizes_get(&count, &buf_size)) {
258 w.ESUCCESS => {},
258 .SUCCESS => {},
259259 else => |err| return os.unexpectedErrno(err),
260260 }
261261
......@@ -265,7 +265,7 @@ pub const ArgIteratorWasi = struct {
265265 var argv_buf = try allocator.alloc(u8, buf_size);
266266
267267 switch (w.args_get(argv.ptr, argv_buf.ptr)) {
268 w.ESUCCESS => {},
268 .SUCCESS => {},
269269 else => |err| return os.unexpectedErrno(err),
270270 }
271271
lib/std/special/compiler_rt/emutls.zig+3-3
......@@ -201,7 +201,7 @@ const current_thread_storage = struct {
201201
202202 /// Initialize pthread_key_t.
203203 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) {
205205 abort();
206206 }
207207 }
......@@ -248,14 +248,14 @@ const emutls_control = extern struct {
248248
249249 /// Simple wrapper for global lock.
250250 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) {
252252 abort();
253253 }
254254 }
255255
256256 /// Simple wrapper for global unlock.
257257 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) {
259259 abort();
260260 }
261261 }
lib/std/time.zig+1-1
......@@ -92,7 +92,7 @@ pub fn nanoTimestamp() i128 {
9292 if (builtin.os.tag == .wasi and !builtin.link_libc) {
9393 var ns: os.wasi.timestamp_t = undefined;
9494 const err = os.wasi.clock_time_get(os.wasi.CLOCK_REALTIME, 1, &ns);
95 assert(err == os.wasi.ESUCCESS);
95 assert(err == .SUCCESS);
9696 return ns;
9797 }
9898 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 {
8282 while (true) {
8383 const rc = os.system.sendmsg(self.fd, &msg, @intCast(c_int, flags));
8484 return switch (os.errno(rc)) {
85 0 => return @intCast(usize, rc),
86 os.EACCES => error.AccessDenied,
87 os.EAGAIN => error.WouldBlock,
88 os.EALREADY => error.FastOpenAlreadyInProgress,
89 os.EBADF => unreachable, // always a race condition
90 os.ECONNRESET => error.ConnectionResetByPeer,
91 os.EDESTADDRREQ => 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.
93 os.EINTR => continue,
94 os.EINVAL => unreachable, // Invalid argument passed.
95 os.EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
96 os.EMSGSIZE => error.MessageTooBig,
97 os.ENOBUFS => error.SystemResources,
98 os.ENOMEM => error.SystemResources,
99 os.ENOTSOCK => 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.
101 os.EPIPE => error.BrokenPipe,
102 os.EAFNOSUPPORT => error.AddressFamilyNotSupported,
103 os.ELOOP => error.SymLinkLoop,
104 os.ENAMETOOLONG => error.NameTooLong,
105 os.ENOENT => error.FileNotFound,
106 os.ENOTDIR => error.NotDir,
107 os.EHOSTUNREACH => error.NetworkUnreachable,
108 os.ENETUNREACH => error.NetworkUnreachable,
109 os.ENOTCONN => error.SocketNotConnected,
110 os.ENETDOWN => error.NetworkSubsystemFailed,
85 .SUCCESS => return @intCast(usize, rc),
86 .ACCES => error.AccessDenied,
87 .AGAIN => error.WouldBlock,
88 .ALREADY => error.FastOpenAlreadyInProgress,
89 .BADF => unreachable, // always a race condition
90 .CONNRESET => error.ConnectionResetByPeer,
91 .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set.
92 .FAULT => unreachable, // An invalid user space address was specified for an argument.
93 .INTR => continue,
94 .INVAL => unreachable, // Invalid argument passed.
95 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
96 .MSGSIZE => error.MessageTooBig,
97 .NOBUFS => error.SystemResources,
98 .NOMEM => error.SystemResources,
99 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
100 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
101 .PIPE => error.BrokenPipe,
102 .AFNOSUPPORT => error.AddressFamilyNotSupported,
103 .LOOP => error.SymLinkLoop,
104 .NAMETOOLONG => error.NameTooLong,
105 .NOENT => error.FileNotFound,
106 .NOTDIR => error.NotDir,
107 .HOSTUNREACH => error.NetworkUnreachable,
108 .NETUNREACH => error.NetworkUnreachable,
109 .NOTCONN => error.SocketNotConnected,
110 .NETDOWN => error.NetworkSubsystemFailed,
111111 else => |err| os.unexpectedErrno(err),
112112 };
113113 }
......@@ -120,17 +120,17 @@ pub fn Mixin(comptime Socket: type) type {
120120 while (true) {
121121 const rc = os.system.recvmsg(self.fd, msg, @intCast(c_int, flags));
122122 return switch (os.errno(rc)) {
123 0 => @intCast(usize, rc),
124 os.EBADF => unreachable, // always a race condition
125 os.EFAULT => unreachable,
126 os.EINVAL => unreachable,
127 os.ENOTCONN => unreachable,
128 os.ENOTSOCK => unreachable,
129 os.EINTR => continue,
130 os.EAGAIN => error.WouldBlock,
131 os.ENOMEM => error.SystemResources,
132 os.ECONNREFUSED => error.ConnectionRefused,
133 os.ECONNRESET => error.ConnectionResetByPeer,
123 .SUCCESS => @intCast(usize, rc),
124 .BADF => unreachable, // always a race condition
125 .FAULT => unreachable,
126 .INVAL => unreachable,
127 .NOTCONN => unreachable,
128 .NOTSOCK => unreachable,
129 .INTR => continue,
130 .AGAIN => error.WouldBlock,
131 .NOMEM => error.SystemResources,
132 .CONNREFUSED => error.ConnectionRefused,
133 .CONNRESET => error.ConnectionResetByPeer,
134134 else => |err| os.unexpectedErrno(err),
135135 };
136136 }
......@@ -164,12 +164,12 @@ pub fn Mixin(comptime Socket: type) type {
164164
165165 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&value), &value_len);
166166 return switch (os.errno(rc)) {
167 0 => value,
168 os.EBADF => error.BadFileDescriptor,
169 os.EFAULT => error.InvalidAddressSpace,
170 os.EINVAL => error.InvalidSocketOption,
171 os.ENOPROTOOPT => error.UnknownSocketOption,
172 os.ENOTSOCK => error.NotASocket,
167 .SUCCESS => value,
168 .BADF => error.BadFileDescriptor,
169 .FAULT => error.InvalidAddressSpace,
170 .INVAL => error.InvalidSocketOption,
171 .NOPROTOOPT => error.UnknownSocketOption,
172 .NOTSOCK => error.NotASocket,
173173 else => |err| os.unexpectedErrno(err),
174174 };
175175 }
......@@ -181,12 +181,12 @@ pub fn Mixin(comptime Socket: type) type {
181181
182182 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&value), &value_len);
183183 return switch (os.errno(rc)) {
184 0 => value,
185 os.EBADF => error.BadFileDescriptor,
186 os.EFAULT => error.InvalidAddressSpace,
187 os.EINVAL => error.InvalidSocketOption,
188 os.ENOPROTOOPT => error.UnknownSocketOption,
189 os.ENOTSOCK => error.NotASocket,
184 .SUCCESS => value,
185 .BADF => error.BadFileDescriptor,
186 .FAULT => error.InvalidAddressSpace,
187 .INVAL => error.InvalidSocketOption,
188 .NOPROTOOPT => error.UnknownSocketOption,
189 .NOTSOCK => error.NotASocket,
190190 else => |err| os.unexpectedErrno(err),
191191 };
192192 }