diff --git a/CMakeLists.txt b/CMakeLists.txt index 20d19fa167..0e4d5cfb43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -426,7 +426,7 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/lib/std/os.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig" - "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno-generic.zig" + "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno/generic.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig" "${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig" diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index cd742cc955..9d3b0cb1fc 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -9,9 +9,10 @@ //! both evented I/O and async I/O, see the respective names in the top level std namespace. const std = @import("std.zig"); +const builtin = @import("builtin"); const os = std.os; const assert = std.debug.assert; -const target = std.Target.current; +const target = builtin.target; const Atomic = std.atomic.Atomic; pub const AutoResetEvent = @import("Thread/AutoResetEvent.zig"); @@ -24,7 +25,8 @@ pub const Condition = @import("Thread/Condition.zig"); pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint"); -pub const use_pthreads = target.os.tag != .windows and std.Target.current.os.tag != .wasi and std.builtin.link_libc; +pub const use_pthreads = target.os.tag != .windows and target.os.tag != .wasi and builtin.link_libc; +const is_gnu = target.abi.isGnu(); const Thread = @This(); const Impl = if (target.os.tag == .windows) @@ -38,7 +40,7 @@ else impl: Impl, -pub const max_name_len = switch (std.Target.current.os.tag) { +pub const max_name_len = switch (target.os.tag) { .linux => 15, .windows => 31, .macos, .ios, .watchos, .tvos => 63, @@ -64,20 +66,21 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { break :blk name_buf[0..name.len :0]; }; - switch (std.Target.current.os.tag) { + switch (target.os.tag) { .linux => if (use_pthreads) { const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); - return switch (err) { - 0 => {}, - os.ERANGE => unreachable, - else => return os.unexpectedErrno(err), - }; + switch (err) { + .SUCCESS => return, + .RANGE => unreachable, + else => |e| return os.unexpectedErrno(e), + } } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) { + // TODO: this is dead code. what did the author of this code intend to happen here? const err = try os.prctl(.SET_NAME, .{@ptrToInt(name_with_terminator.ptr)}); - return switch (err) { - 0 => {}, - else => return os.unexpectedErrno(err), - }; + switch (@intToEnum(os.E, err)) { + .SUCCESS => return, + else => |e| return os.unexpectedErrno(e), + } } else { var buf: [32]u8 = undefined; 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 { try file.writer().writeAll(name); }, - .windows => if (std.Target.current.os.isAtLeast(.windows, .win10_rs1)) |res| { + .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| { // SetThreadDescription is only available since version 1607, which is 10.0.14393.795 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK if (!res) { @@ -110,24 +113,25 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { if (self.getHandle() != std.c.pthread_self()) return error.Unsupported; const err = std.c.pthread_setname_np(name_with_terminator.ptr); - return switch (err) { - 0 => {}, - else => return os.unexpectedErrno(err), - }; + switch (err) { + .SUCCESS => return, + else => |e| return os.unexpectedErrno(e), + } }, .netbsd => if (use_pthreads) { const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null); - return switch (err) { - 0 => {}, - os.EINVAL => unreachable, - os.ESRCH => unreachable, - os.ENOMEM => unreachable, - else => return os.unexpectedErrno(err), - }; + switch (err) { + .SUCCESS => return, + .INVAL => unreachable, + .SRCH => unreachable, + .NOMEM => unreachable, + else => |e| return os.unexpectedErrno(e), + } }, .freebsd, .openbsd => if (use_pthreads) { // Use pthread_set_name_np for FreeBSD because pthread_setname_np is FreeBSD 12.2+ only. - // TODO maybe revisit this if depending on FreeBSD 12.2+ is acceptable because pthread_setname_np can return an error. + // TODO maybe revisit this if depending on FreeBSD 12.2+ is acceptable because + // pthread_setname_np can return an error. std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr); }, @@ -151,20 +155,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co buffer_ptr[max_name_len] = 0; var buffer = std.mem.span(buffer_ptr); - switch (std.Target.current.os.tag) { - .linux => if (use_pthreads and comptime std.Target.current.abi.isGnu()) { + switch (target.os.tag) { + .linux => if (use_pthreads and is_gnu) { const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); - return switch (err) { - 0 => std.mem.sliceTo(buffer, 0), - os.ERANGE => unreachable, - else => return os.unexpectedErrno(err), - }; + switch (err) { + .SUCCESS => return std.mem.sliceTo(buffer, 0), + .RANGE => unreachable, + else => |e| return os.unexpectedErrno(e), + } } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) { const err = try os.prctl(.GET_NAME, .{@ptrToInt(buffer.ptr)}); - return switch (err) { - 0 => std.mem.sliceTo(buffer, 0), - else => return os.unexpectedErrno(err), - }; + switch (@intToEnum(os.E, err)) { + .SUCCESS => return std.mem.sliceTo(buffer, 0), + else => |e| return os.unexpectedErrno(e), + } } else if (!use_pthreads) { var buf: [32]u8 = undefined; 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 // musl doesn't provide pthread_getname_np and there's no way to retrieve the thread id of an arbitrary thread. return error.Unsupported; }, - .windows => if (std.Target.current.os.isAtLeast(.windows, .win10_rs1)) |res| { + .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| { // GetThreadDescription is only available since version 1607, which is 10.0.14393.795 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK if (!res) { @@ -198,20 +202,20 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co }, .macos, .ios, .watchos, .tvos => if (use_pthreads) { const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); - return switch (err) { - 0 => std.mem.sliceTo(buffer, 0), - os.ESRCH => unreachable, - else => return os.unexpectedErrno(err), - }; + switch (err) { + .SUCCESS => return std.mem.sliceTo(buffer, 0), + .SRCH => unreachable, + else => |e| return os.unexpectedErrno(e), + } }, .netbsd => if (use_pthreads) { const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); - return switch (err) { - 0 => std.mem.sliceTo(buffer, 0), - os.EINVAL => unreachable, - os.ESRCH => unreachable, - else => return os.unexpectedErrno(err), - }; + switch (err) { + .SUCCESS => return std.mem.sliceTo(buffer, 0), + .INVAL => unreachable, + .SRCH => unreachable, + else => |e| return os.unexpectedErrno(e), + } }, .freebsd, .openbsd => if (use_pthreads) { // Use pthread_get_name_np for FreeBSD because pthread_getname_np is FreeBSD 12.2+ only. @@ -288,7 +292,7 @@ pub const SpawnError = error{ /// The caller must eventually either call `join()` to wait for the thread to finish and free its resources /// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`. pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread { - if (std.builtin.single_threaded) { + if (builtin.single_threaded) { @compileError("Cannot spawn thread when building in single-threaded mode"); } @@ -611,13 +615,13 @@ const PosixThreadImpl = struct { errdefer allocator.destroy(args_ptr); var attr: c.pthread_attr_t = undefined; - if (c.pthread_attr_init(&attr) != 0) return error.SystemResources; - defer assert(c.pthread_attr_destroy(&attr) == 0); + if (c.pthread_attr_init(&attr) != .SUCCESS) return error.SystemResources; + defer assert(c.pthread_attr_destroy(&attr) == .SUCCESS); // Use the same set of parameters used by the libc-less impl. const stack_size = std.math.max(config.stack_size, 16 * 1024); - assert(c.pthread_attr_setstacksize(&attr, stack_size) == 0); - assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == 0); + assert(c.pthread_attr_setstacksize(&attr, stack_size) == .SUCCESS); + assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == .SUCCESS); var handle: c.pthread_t = undefined; switch (c.pthread_create( @@ -626,10 +630,10 @@ const PosixThreadImpl = struct { Instance.entryFn, if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined, )) { - 0 => return Impl{ .handle = handle }, - os.EAGAIN => return error.SystemResources, - os.EPERM => unreachable, - os.EINVAL => unreachable, + .SUCCESS => return Impl{ .handle = handle }, + .AGAIN => return error.SystemResources, + .PERM => unreachable, + .INVAL => unreachable, else => |err| return os.unexpectedErrno(err), } } @@ -640,19 +644,19 @@ const PosixThreadImpl = struct { fn detach(self: Impl) void { switch (c.pthread_detach(self.handle)) { - 0 => {}, - os.EINVAL => unreachable, // thread handle is not joinable - os.ESRCH => unreachable, // thread handle is invalid + .SUCCESS => {}, + .INVAL => unreachable, // thread handle is not joinable + .SRCH => unreachable, // thread handle is invalid else => unreachable, } } fn join(self: Impl) void { switch (c.pthread_join(self.handle, null)) { - 0 => {}, - os.EINVAL => unreachable, // thread handle is not joinable (or another thread is already joining in) - os.ESRCH => unreachable, // thread handle is invalid - os.EDEADLK => unreachable, // two threads tried to join each other + .SUCCESS => {}, + .INVAL => unreachable, // thread handle is not joinable (or another thread is already joining in) + .SRCH => unreachable, // thread handle is invalid + .DEADLK => unreachable, // two threads tried to join each other else => unreachable, } } @@ -937,13 +941,13 @@ const LinuxThreadImpl = struct { tls_ptr, &instance.thread.child_tid.value, ))) { - 0 => return Impl{ .thread = &instance.thread }, - os.EAGAIN => return error.ThreadQuotaExceeded, - os.EINVAL => unreachable, - os.ENOMEM => return error.SystemResources, - os.ENOSPC => unreachable, - os.EPERM => unreachable, - os.EUSERS => unreachable, + .SUCCESS => return Impl{ .thread = &instance.thread }, + .AGAIN => return error.ThreadQuotaExceeded, + .INVAL => unreachable, + .NOMEM => return error.SystemResources, + .NOSPC => unreachable, + .PERM => unreachable, + .USERS => unreachable, else => |err| return os.unexpectedErrno(err), } } @@ -982,9 +986,9 @@ const LinuxThreadImpl = struct { tid, null, ))) { - 0 => continue, - os.EINTR => continue, - os.EAGAIN => continue, + .SUCCESS => continue, + .INTR => continue, + .AGAIN => continue, else => unreachable, } } @@ -1011,7 +1015,7 @@ fn testThreadName(thread: *Thread) !void { } test "setName, getName" { - if (std.builtin.single_threaded) return error.SkipZigTest; + if (builtin.single_threaded) return error.SkipZigTest; const Context = struct { start_wait_event: ResetEvent = undefined, @@ -1029,7 +1033,7 @@ test "setName, getName" { // Wait for the main thread to have set the thread field in the context. ctx.start_wait_event.wait(); - switch (std.Target.current.os.tag) { + switch (target.os.tag) { .windows => testThreadName(&ctx.thread) catch |err| switch (err) { error.Unsupported => return error.SkipZigTest, else => return err, @@ -1054,7 +1058,7 @@ test "setName, getName" { context.start_wait_event.set(); context.test_done_event.wait(); - switch (std.Target.current.os.tag) { + switch (target.os.tag) { .macos, .ios, .watchos, .tvos => { const res = thread.setName("foobar"); try std.testing.expectError(error.Unsupported, res); @@ -1063,7 +1067,7 @@ test "setName, getName" { error.Unsupported => return error.SkipZigTest, else => return err, }, - else => |tag| if (tag == .linux and use_pthreads and comptime std.Target.current.abi.isMusl()) { + else => |tag| if (tag == .linux and use_pthreads and comptime target.abi.isMusl()) { try thread.setName("foobar"); var name_buffer: [max_name_len:0]u8 = undefined; @@ -1096,7 +1100,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void { } test "Thread.join" { - if (std.builtin.single_threaded) return error.SkipZigTest; + if (builtin.single_threaded) return error.SkipZigTest; var value: usize = 0; var event: ResetEvent = undefined; @@ -1110,7 +1114,7 @@ test "Thread.join" { } test "Thread.detach" { - if (std.builtin.single_threaded) return error.SkipZigTest; + if (builtin.single_threaded) return error.SkipZigTest; var value: usize = 0; var event: ResetEvent = undefined; diff --git a/lib/std/Thread/Condition.zig b/lib/std/Thread/Condition.zig index 8485f84aa4..9513e794ed 100644 --- a/lib/std/Thread/Condition.zig +++ b/lib/std/Thread/Condition.zig @@ -81,17 +81,17 @@ pub const PthreadCondition = struct { pub fn wait(cond: *PthreadCondition, mutex: *Mutex) void { const rc = std.c.pthread_cond_wait(&cond.cond, &mutex.impl.pthread_mutex); - assert(rc == 0); + assert(rc == .SUCCESS); } pub fn signal(cond: *PthreadCondition) void { const rc = std.c.pthread_cond_signal(&cond.cond); - assert(rc == 0); + assert(rc == .SUCCESS); } pub fn broadcast(cond: *PthreadCondition) void { const rc = std.c.pthread_cond_broadcast(&cond.cond); - assert(rc == 0); + assert(rc == .SUCCESS); } }; @@ -115,9 +115,9 @@ pub const AtomicCondition = struct { 0, null, ))) { - 0 => {}, - std.os.EINTR => {}, - std.os.EAGAIN => {}, + .SUCCESS => {}, + .INTR => {}, + .AGAIN => {}, else => unreachable, } }, @@ -136,8 +136,8 @@ pub const AtomicCondition = struct { linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE, 1, ))) { - 0 => {}, - std.os.EFAULT => {}, + .SUCCESS => {}, + .FAULT => {}, else => unreachable, } }, diff --git a/lib/std/Thread/Futex.zig b/lib/std/Thread/Futex.zig index 81dba07996..a896942d6e 100644 --- a/lib/std/Thread/Futex.zig +++ b/lib/std/Thread/Futex.zig @@ -152,12 +152,12 @@ const LinuxFutex = struct { @bitCast(i32, expect), ts_ptr, ))) { - 0 => {}, // notified by `wake()` - std.os.EINTR => {}, // spurious wakeup - std.os.EAGAIN => {}, // ptr.* != expect - std.os.ETIMEDOUT => return error.TimedOut, - std.os.EINVAL => {}, // possibly timeout overflow - std.os.EFAULT => unreachable, + .SUCCESS => {}, // notified by `wake()` + .INTR => {}, // spurious wakeup + .AGAIN => {}, // ptr.* != expect + .TIMEDOUT => return error.TimedOut, + .INVAL => {}, // possibly timeout overflow + .FAULT => unreachable, else => unreachable, } } @@ -168,9 +168,9 @@ const LinuxFutex = struct { linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE, std.math.cast(i32, num_waiters) catch std.math.maxInt(i32), ))) { - 0 => {}, // successful wake up - std.os.EINVAL => {}, // invalid futex_wait() on ptr done elsewhere - std.os.EFAULT => {}, // pointer became invalid while doing the wake + .SUCCESS => {}, // successful wake up + .INVAL => {}, // invalid futex_wait() on ptr done elsewhere + .FAULT => {}, // pointer became invalid while doing the wake else => unreachable, } } @@ -215,13 +215,13 @@ const DarwinFutex = struct { }; if (status >= 0) return; - switch (-status) { - darwin.EINTR => {}, + switch (@intToEnum(std.os.E, -status)) { + .INTR => {}, // Address of the futex is paged out. This is unlikely, but possible in theory, and // pthread/libdispatch on darwin bother to handle it. In this case we'll return // without waiting, but the caller should retry anyway. - darwin.EFAULT => {}, - darwin.ETIMEDOUT => if (!timeout_overflowed) return error.TimedOut, + .FAULT => {}, + .TIMEDOUT => if (!timeout_overflowed) return error.TimedOut, else => unreachable, } } @@ -237,11 +237,11 @@ const DarwinFutex = struct { const status = darwin.__ulock_wake(flags, addr, 0); if (status >= 0) return; - switch (-status) { - darwin.EINTR => continue, // spurious wake() - darwin.EFAULT => continue, // address of the lock was paged out - darwin.ENOENT => return, // nothing was woken up - darwin.EALREADY => unreachable, // only for ULF_WAKE_THREAD + switch (@intToEnum(std.os.E, -status)) { + .INTR => continue, // spurious wake() + .FAULT => continue, // address of the lock was paged out + .NOENT => return, // nothing was woken up + .ALREADY => unreachable, // only for ULF_WAKE_THREAD else => unreachable, } } @@ -255,8 +255,8 @@ const PosixFutex = struct { var waiter: List.Node = undefined; { - assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0); - defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0); + assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS); + defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS); if (ptr.load(.SeqCst) != expect) { return; @@ -272,8 +272,8 @@ const PosixFutex = struct { waiter.data.wait(null) catch unreachable; }; - assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0); - defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0); + assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS); + defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS); if (waiter.data.address == address) { timed_out = true; @@ -297,8 +297,8 @@ const PosixFutex = struct { waiter.data.notify(); }; - assert(std.c.pthread_mutex_lock(&bucket.mutex) == 0); - defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == 0); + assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS); + defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS); var waiters = bucket.list.first; while (waiters) |waiter| { @@ -340,16 +340,13 @@ const PosixFutex = struct { }; fn deinit(self: *Self) void { - const rc = std.c.pthread_cond_destroy(&self.cond); - assert(rc == 0 or rc == std.os.EINVAL); - - const rm = std.c.pthread_mutex_destroy(&self.mutex); - assert(rm == 0 or rm == std.os.EINVAL); + _ = std.c.pthread_cond_destroy(&self.cond); + _ = std.c.pthread_mutex_destroy(&self.mutex); } fn wait(self: *Self, timeout: ?u64) error{TimedOut}!void { - assert(std.c.pthread_mutex_lock(&self.mutex) == 0); - defer assert(std.c.pthread_mutex_unlock(&self.mutex) == 0); + assert(std.c.pthread_mutex_lock(&self.mutex) == .SUCCESS); + defer assert(std.c.pthread_mutex_unlock(&self.mutex) == .SUCCESS); switch (self.state) { .empty => self.state = .waiting, @@ -378,28 +375,31 @@ const PosixFutex = struct { } const ts_ref = ts_ptr orelse { - assert(std.c.pthread_cond_wait(&self.cond, &self.mutex) == 0); + assert(std.c.pthread_cond_wait(&self.cond, &self.mutex) == .SUCCESS); continue; }; const rc = std.c.pthread_cond_timedwait(&self.cond, &self.mutex, ts_ref); - assert(rc == 0 or rc == std.os.ETIMEDOUT); - if (rc == std.os.ETIMEDOUT) { - self.state = .empty; - return error.TimedOut; + switch (rc) { + .SUCCESS => {}, + .TIMEDOUT => { + self.state = .empty; + return error.TimedOut; + }, + else => unreachable, } } } fn notify(self: *Self) void { - assert(std.c.pthread_mutex_lock(&self.mutex) == 0); - defer assert(std.c.pthread_mutex_unlock(&self.mutex) == 0); + assert(std.c.pthread_mutex_lock(&self.mutex) == .SUCCESS); + defer assert(std.c.pthread_mutex_unlock(&self.mutex) == .SUCCESS); switch (self.state) { .empty => self.state = .notified, .waiting => { self.state = .notified; - assert(std.c.pthread_cond_signal(&self.cond) == 0); + assert(std.c.pthread_cond_signal(&self.cond) == .SUCCESS); }, .notified => unreachable, } diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig index 35095b2a3c..522d1fe418 100644 --- a/lib/std/Thread/Mutex.zig +++ b/lib/std/Thread/Mutex.zig @@ -143,9 +143,9 @@ pub const AtomicMutex = struct { @enumToInt(new_state), null, ))) { - 0 => {}, - std.os.EINTR => {}, - std.os.EAGAIN => {}, + .SUCCESS => {}, + .INTR => {}, + .AGAIN => {}, else => unreachable, } }, @@ -164,8 +164,8 @@ pub const AtomicMutex = struct { linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE, 1, ))) { - 0 => {}, - std.os.EFAULT => {}, + .SUCCESS => {}, + .FAULT => unreachable, // invalid pointer passed to futex_wake else => unreachable, } }, @@ -182,10 +182,10 @@ pub const PthreadMutex = struct { pub fn release(held: Held) void { switch (std.c.pthread_mutex_unlock(&held.mutex.pthread_mutex)) { - 0 => return, - std.c.EINVAL => unreachable, - std.c.EAGAIN => unreachable, - std.c.EPERM => unreachable, + .SUCCESS => return, + .INVAL => unreachable, + .AGAIN => unreachable, + .PERM => unreachable, else => unreachable, } } @@ -195,7 +195,7 @@ pub const PthreadMutex = struct { /// the mutex is unavailable. Otherwise returns Held. Call /// release on Held. pub fn tryAcquire(m: *PthreadMutex) ?Held { - if (std.c.pthread_mutex_trylock(&m.pthread_mutex) == 0) { + if (std.c.pthread_mutex_trylock(&m.pthread_mutex) == .SUCCESS) { return Held{ .mutex = m }; } else { return null; @@ -206,12 +206,12 @@ pub const PthreadMutex = struct { /// held by the calling thread. pub fn acquire(m: *PthreadMutex) Held { switch (std.c.pthread_mutex_lock(&m.pthread_mutex)) { - 0 => return Held{ .mutex = m }, - std.c.EINVAL => unreachable, - std.c.EBUSY => unreachable, - std.c.EAGAIN => unreachable, - std.c.EDEADLK => unreachable, - std.c.EPERM => unreachable, + .SUCCESS => return Held{ .mutex = m }, + .INVAL => unreachable, + .BUSY => unreachable, + .AGAIN => unreachable, + .DEADLK => unreachable, + .PERM => unreachable, else => unreachable, } } diff --git a/lib/std/Thread/ResetEvent.zig b/lib/std/Thread/ResetEvent.zig index 356b8eb78d..bbf9e7263a 100644 --- a/lib/std/Thread/ResetEvent.zig +++ b/lib/std/Thread/ResetEvent.zig @@ -130,7 +130,7 @@ pub const PosixEvent = struct { pub fn init(ev: *PosixEvent) !void { switch (c.getErrno(c.sem_init(&ev.sem, 0, 0))) { - 0 => return, + .SUCCESS => return, else => return error.SystemResources, } } @@ -147,9 +147,9 @@ pub const PosixEvent = struct { pub fn wait(ev: *PosixEvent) void { while (true) { switch (c.getErrno(c.sem_wait(&ev.sem))) { - 0 => return, - c.EINTR => continue, - c.EINVAL => unreachable, + .SUCCESS => return, + .INTR => continue, + .INVAL => unreachable, else => unreachable, } } @@ -165,10 +165,10 @@ pub const PosixEvent = struct { ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.ns_per_s)); while (true) { switch (c.getErrno(c.sem_timedwait(&ev.sem, &ts))) { - 0 => return .event_set, - c.EINTR => continue, - c.EINVAL => unreachable, - c.ETIMEDOUT => return .timed_out, + .SUCCESS => return .event_set, + .INTR => continue, + .INVAL => unreachable, + .TIMEDOUT => return .timed_out, else => unreachable, } } @@ -177,10 +177,10 @@ pub const PosixEvent = struct { pub fn reset(ev: *PosixEvent) void { while (true) { switch (c.getErrno(c.sem_trywait(&ev.sem))) { - 0 => continue, // Need to make it go to zero. - c.EINTR => continue, - c.EINVAL => unreachable, - c.EAGAIN => return, // The semaphore currently has the value zero. + .SUCCESS => continue, // Need to make it go to zero. + .INTR => continue, + .INVAL => unreachable, + .AGAIN => return, // The semaphore currently has the value zero. else => unreachable, } } diff --git a/lib/std/Thread/RwLock.zig b/lib/std/Thread/RwLock.zig index 1d606a9cf1..0721aad3f7 100644 --- a/lib/std/Thread/RwLock.zig +++ b/lib/std/Thread/RwLock.zig @@ -13,7 +13,7 @@ impl: Impl, const RwLock = @This(); const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const assert = std.debug.assert; const Mutex = std.Thread.Mutex; const Semaphore = std.Semaphore; @@ -165,43 +165,41 @@ pub const PthreadRwLock = struct { } pub fn deinit(rwl: *PthreadRwLock) void { - const safe_rc = switch (std.builtin.os.tag) { - .dragonfly, .netbsd => std.os.EAGAIN, - else => 0, + const safe_rc: std.os.E = switch (builtin.os.tag) { + .dragonfly, .netbsd => .AGAIN, + else => .SUCCESS, }; - const rc = std.c.pthread_rwlock_destroy(&rwl.rwlock); - assert(rc == 0 or rc == safe_rc); - + assert(rc == .SUCCESS or rc == safe_rc); rwl.* = undefined; } pub fn tryLock(rwl: *PthreadRwLock) bool { - return pthread_rwlock_trywrlock(&rwl.rwlock) == 0; + return pthread_rwlock_trywrlock(&rwl.rwlock) == .SUCCESS; } pub fn lock(rwl: *PthreadRwLock) void { const rc = pthread_rwlock_wrlock(&rwl.rwlock); - assert(rc == 0); + assert(rc == .SUCCESS); } pub fn unlock(rwl: *PthreadRwLock) void { const rc = pthread_rwlock_unlock(&rwl.rwlock); - assert(rc == 0); + assert(rc == .SUCCESS); } pub fn tryLockShared(rwl: *PthreadRwLock) bool { - return pthread_rwlock_tryrdlock(&rwl.rwlock) == 0; + return pthread_rwlock_tryrdlock(&rwl.rwlock) == .SUCCESS; } pub fn lockShared(rwl: *PthreadRwLock) void { const rc = pthread_rwlock_rdlock(&rwl.rwlock); - assert(rc == 0); + assert(rc == .SUCCESS); } pub fn unlockShared(rwl: *PthreadRwLock) void { const rc = pthread_rwlock_unlock(&rwl.rwlock); - assert(rc == 0); + assert(rc == .SUCCESS); } }; diff --git a/lib/std/Thread/StaticResetEvent.zig b/lib/std/Thread/StaticResetEvent.zig index 40974938d0..e15a6a0a54 100644 --- a/lib/std/Thread/StaticResetEvent.zig +++ b/lib/std/Thread/StaticResetEvent.zig @@ -201,7 +201,7 @@ pub const AtomicEvent = struct { const waiting = std.math.maxInt(i32); // wake_count const ptr = @ptrCast(*const i32, waiters); const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting); - assert(linux.getErrno(rc) == 0); + assert(linux.getErrno(rc) == .SUCCESS); } fn wait(waiters: *u32, timeout: ?u64) !void { @@ -221,10 +221,10 @@ pub const AtomicEvent = struct { const ptr = @ptrCast(*const i32, waiters); const rc = linux.futex_wait(ptr, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, expected, ts_ptr); switch (linux.getErrno(rc)) { - 0 => continue, - os.ETIMEDOUT => return error.TimedOut, - os.EINTR => continue, - os.EAGAIN => return, + .SUCCESS => continue, + .TIMEDOUT => return error.TimedOut, + .INTR => continue, + .AGAIN => return, else => unreachable, } } diff --git a/lib/std/c.zig b/lib/std/c.zig index c8b3020dc7..700a1dc250 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -35,11 +35,11 @@ pub usingnamespace switch (std.Target.current.os.tag) { else => struct {}, }; -pub fn getErrno(rc: anytype) c_int { +pub fn getErrno(rc: anytype) E { if (rc == -1) { - return _errno().*; + return @intToEnum(E, _errno().*); } else { - return 0; + return .SUCCESS; } } @@ -270,22 +270,22 @@ pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int; pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int; pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int; -pub 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; -pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int; -pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int; -pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) c_int; -pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int; -pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int; +pub 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; +pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E; +pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) E; +pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) E; +pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) E; +pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) E; pub extern "c" fn pthread_self() pthread_t; -pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int; -pub extern "c" fn pthread_detach(thread: pthread_t) c_int; +pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) E; +pub extern "c" fn pthread_detach(thread: pthread_t) E; pub extern "c" fn pthread_atfork( prepare: ?fn () callconv(.C) void, parent: ?fn () callconv(.C) void, child: ?fn () callconv(.C) void, ) c_int; -pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) c_int; -pub extern "c" fn pthread_key_delete(key: pthread_key_t) c_int; +pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) E; +pub extern "c" fn pthread_key_delete(key: pthread_key_t) E; pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*c_void; pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*c_void) c_int; pub 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( ) c_int; pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{}; -pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int; -pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int; -pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c_int; -pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c_int; +pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) E; +pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) E; +pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) E; +pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) E; pub const PTHREAD_COND_INITIALIZER = pthread_cond_t{}; -pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c_int; -pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) c_int; -pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c_int; -pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int; -pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c_int; +pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) E; +pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) E; +pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E; +pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E; +pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E; -pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) c_int; -pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) c_int; -pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) c_int; -pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) c_int; -pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) c_int; -pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) c_int; +pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E; +pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E; +pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E; +pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E; +pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E; +pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E; pub const pthread_t = *opaque {}; pub const FILE = opaque {}; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 22473a3899..117172fc7b 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -193,8 +193,8 @@ pub const pthread_attr_t = extern struct { const pthread_t = std.c.pthread_t; pub extern "c" fn pthread_threadid_np(thread: ?pthread_t, thread_id: *u64) c_int; -pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int; -pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int; +pub extern "c" fn pthread_setname_np(name: [*:0]const u8) E; +pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; diff --git a/lib/std/c/linux.zig b/lib/std/c/linux.zig index 694af28904..2ce98e2246 100644 --- a/lib/std/c/linux.zig +++ b/lib/std/c/linux.zig @@ -186,8 +186,8 @@ const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) { }; const __SIZEOF_SEM_T = 4 * @sizeOf(usize); -pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int; -pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int; +pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E; +pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; pub const RTLD_LAZY = 1; pub const RTLD_NOW = 2; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index 32b7cc69e3..07af1dc689 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -95,5 +95,5 @@ pub const pthread_attr_t = extern struct { pub const sem_t = ?*opaque {}; -pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) c_int; -pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int; +pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) E; +pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 494d871974..cb33464dd2 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -339,10 +339,10 @@ pub const Dir = struct { if (rc == 0) return null; if (rc < 0) { switch (os.errno(rc)) { - os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability - os.EFAULT => unreachable, - os.ENOTDIR => unreachable, - os.EINVAL => unreachable, + .BADF => unreachable, // Dir is invalid or was opened without iteration ability + .FAULT => unreachable, + .NOTDIR => unreachable, + .INVAL => unreachable, else => |err| return os.unexpectedErrno(err), } } @@ -385,11 +385,11 @@ pub const Dir = struct { else os.system.getdents(self.dir.fd, &self.buf, self.buf.len); switch (os.errno(rc)) { - 0 => {}, - os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability - os.EFAULT => unreachable, - os.ENOTDIR => unreachable, - os.EINVAL => unreachable, + .SUCCESS => {}, + .BADF => unreachable, // Dir is invalid or was opened without iteration ability + .FAULT => unreachable, + .NOTDIR => unreachable, + .INVAL => unreachable, else => |err| return os.unexpectedErrno(err), } if (rc == 0) return null; @@ -457,10 +457,10 @@ pub const Dir = struct { if (rc == 0) return null; if (rc < 0) { switch (os.errno(rc)) { - os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability - os.EFAULT => unreachable, - os.ENOTDIR => unreachable, - os.EINVAL => unreachable, + .BADF => unreachable, // Dir is invalid or was opened without iteration ability + .FAULT => unreachable, + .NOTDIR => unreachable, + .INVAL => unreachable, else => |err| return os.unexpectedErrno(err), } } @@ -522,11 +522,11 @@ pub const Dir = struct { if (self.index >= self.end_index) { const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len); switch (os.linux.getErrno(rc)) { - 0 => {}, - os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability - os.EFAULT => unreachable, - os.ENOTDIR => unreachable, - os.EINVAL => unreachable, + .SUCCESS => {}, + .BADF => unreachable, // Dir is invalid or was opened without iteration ability + .FAULT => unreachable, + .NOTDIR => unreachable, + .INVAL => unreachable, else => |err| return os.unexpectedErrno(err), } if (rc == 0) return null; @@ -655,12 +655,12 @@ pub const Dir = struct { if (self.index >= self.end_index) { var bufused: usize = undefined; switch (w.fd_readdir(self.dir.fd, &self.buf, self.buf.len, self.cookie, &bufused)) { - w.ESUCCESS => {}, - w.EBADF => unreachable, // Dir is invalid or was opened without iteration ability - w.EFAULT => unreachable, - w.ENOTDIR => unreachable, - w.EINVAL => unreachable, - w.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => {}, + .BADF => unreachable, // Dir is invalid or was opened without iteration ability + .FAULT => unreachable, + .NOTDIR => unreachable, + .INVAL => unreachable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return os.unexpectedErrno(err), } if (bufused == 0) return null; @@ -2557,12 +2557,12 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void { if (comptime std.Target.current.isDarwin()) { const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA); switch (os.errno(rc)) { - 0 => return, - os.EINVAL => unreachable, - os.ENOMEM => return error.SystemResources, + .SUCCESS => return, + .INVAL => unreachable, + .NOMEM => return error.SystemResources, // The source file is not a directory, symbolic link, or regular file. // Try with the fallback path before giving up. - os.ENOTSUP => {}, + .OPNOTSUPP => {}, else => |err| return os.unexpectedErrno(err), } } diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig index 378e4a7bac..2bfc384773 100644 --- a/lib/std/fs/wasi.zig +++ b/lib/std/fs/wasi.zig @@ -121,13 +121,13 @@ pub const PreopenList = struct { while (true) { var buf: prestat_t = undefined; switch (fd_prestat_get(fd, &buf)) { - ESUCCESS => {}, - ENOTSUP => { + .SUCCESS => {}, + .OPNOTSUPP => { // not a preopen, so keep going fd = try math.add(fd_t, fd, 1); continue; }, - EBADF => { + .BADF => { // OK, no more fds available break; }, @@ -137,7 +137,7 @@ pub const PreopenList = struct { const path_buf = try self.buffer.allocator.alloc(u8, preopen_len); mem.set(u8, path_buf, 0); switch (fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) { - ESUCCESS => {}, + .SUCCESS => {}, else => |err| return os.unexpectedErrno(err), } const preopen = Preopen.new(fd, PreopenType{ .Dir = path_buf }); diff --git a/lib/std/io/c_writer.zig b/lib/std/io/c_writer.zig index 9f551b08fc..bbb7f1daf3 100644 --- a/lib/std/io/c_writer.zig +++ b/lib/std/io/c_writer.zig @@ -17,19 +17,19 @@ pub fn cWriter(c_file: *std.c.FILE) CWriter { fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize { const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file); if (amt_written >= 0) return amt_written; - switch (std.c._errno().*) { - 0 => unreachable, - os.EINVAL => unreachable, - os.EFAULT => unreachable, - os.EAGAIN => unreachable, // this is a blocking API - os.EBADF => unreachable, // always a race condition - os.EDESTADDRREQ => unreachable, // connect was never called - os.EDQUOT => return error.DiskQuota, - os.EFBIG => return error.FileTooBig, - os.EIO => return error.InputOutput, - os.ENOSPC => return error.NoSpaceLeft, - os.EPERM => return error.AccessDenied, - os.EPIPE => return error.BrokenPipe, + switch (@intToEnum(os.E, std.c._errno().*)) { + .SUCCESS => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, // this is a blocking API + .BADF => unreachable, // always a race condition + .DESTADDRREQ => unreachable, // connect was never called + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, else => |err| return os.unexpectedErrno(err), } } diff --git a/lib/std/os.zig b/lib/std/os.zig index e85a6fe42f..7781233a49 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -116,13 +116,13 @@ pub fn close(fd: fd_t) void { if (comptime std.Target.current.isDarwin()) { // This avoids the EINTR problem. switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) { - EBADF => unreachable, // Always a race condition. + .BADF => unreachable, // Always a race condition. else => return, } } switch (errno(system.close(fd))) { - EBADF => unreachable, // Always a race condition. - EINTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425 + .BADF => unreachable, // Always a race condition. + .INTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425 else => return, } } @@ -159,11 +159,11 @@ pub fn getrandom(buffer: []u8) GetRandomError!void { }; switch (res.err) { - 0 => buf = buf[res.num_read..], - EINVAL => unreachable, - EFAULT => unreachable, - EINTR => continue, - ENOSYS => return getRandomBytesDevURandom(buf), + .SUCCESS => buf = buf[res.num_read..], + .INVAL => unreachable, + .FAULT => unreachable, + .INTR => continue, + .NOSYS => return getRandomBytesDevURandom(buf), else => return unexpectedErrno(res.err), } } @@ -175,7 +175,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void { return; }, .wasi => switch (wasi.random_get(buffer.ptr, buffer.len)) { - 0 => return, + .SUCCESS => return, else => |err| return unexpectedErrno(err), }, else => return getRandomBytesDevURandom(buffer), @@ -238,7 +238,7 @@ pub const RaiseError = UnexpectedError; pub fn raise(sig: u8) RaiseError!void { if (builtin.link_libc) { switch (errno(system.raise(sig))) { - 0 => return, + .SUCCESS => return, else => |err| return unexpectedErrno(err), } } @@ -255,7 +255,7 @@ pub fn raise(sig: u8) RaiseError!void { _ = linux.sigprocmask(SIG_SETMASK, &set, null); switch (errno(rc)) { - 0 => return, + .SUCCESS => return, else => |err| return unexpectedErrno(err), } } @@ -267,10 +267,10 @@ pub const KillError = error{PermissionDenied} || UnexpectedError; pub fn kill(pid: pid_t, sig: u8) KillError!void { switch (errno(system.kill(pid, sig))) { - 0 => return, - EINVAL => unreachable, // invalid signal - EPERM => return error.PermissionDenied, - ESRCH => unreachable, // always a race condition + .SUCCESS => return, + .INVAL => unreachable, // invalid signal + .PERM => return error.PermissionDenied, + .SRCH => unreachable, // always a race condition else => |err| return unexpectedErrno(err), } } @@ -342,19 +342,19 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { var nread: usize = undefined; switch (wasi.fd_read(fd, &iovs, iovs.len, &nread)) { - wasi.ESUCCESS => return nread, - wasi.EINTR => unreachable, - wasi.EINVAL => unreachable, - wasi.EFAULT => unreachable, - wasi.EAGAIN => unreachable, - wasi.EBADF => return error.NotOpenForReading, // Can be a race condition. - wasi.EIO => return error.InputOutput, - wasi.EISDIR => return error.IsDir, - wasi.ENOBUFS => return error.SystemResources, - wasi.ENOMEM => return error.SystemResources, - wasi.ECONNRESET => return error.ConnectionResetByPeer, - wasi.ETIMEDOUT => return error.ConnectionTimedOut, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return nread, + .INTR => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, + .BADF => return error.NotOpenForReading, // Can be a race condition. + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .CONNRESET => return error.ConnectionResetByPeer, + .TIMEDOUT => return error.ConnectionTimedOut, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -370,18 +370,18 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { while (true) { const rc = system.read(fd, buf.ptr, adjusted_len); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EINVAL => unreachable, - EFAULT => unreachable, - EAGAIN => return error.WouldBlock, - EBADF => return error.NotOpenForReading, // Can be a race condition. - EIO => return error.InputOutput, - EISDIR => return error.IsDir, - ENOBUFS => return error.SystemResources, - ENOMEM => return error.SystemResources, - ECONNRESET => return error.ConnectionResetByPeer, - ETIMEDOUT => return error.ConnectionTimedOut, + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => return error.WouldBlock, + .BADF => return error.NotOpenForReading, // Can be a race condition. + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .CONNRESET => return error.ConnectionResetByPeer, + .TIMEDOUT => return error.ConnectionTimedOut, else => |err| return unexpectedErrno(err), } } @@ -407,17 +407,17 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize { if (builtin.os.tag == .wasi and !builtin.link_libc) { var nread: usize = undefined; switch (wasi.fd_read(fd, iov.ptr, iov.len, &nread)) { - wasi.ESUCCESS => return nread, - wasi.EINTR => unreachable, - wasi.EINVAL => unreachable, - wasi.EFAULT => unreachable, - wasi.EAGAIN => unreachable, // currently not support in WASI - wasi.EBADF => return error.NotOpenForReading, // can be a race condition - wasi.EIO => return error.InputOutput, - wasi.EISDIR => return error.IsDir, - wasi.ENOBUFS => return error.SystemResources, - wasi.ENOMEM => return error.SystemResources, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return nread, + .INTR => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, // currently not support in WASI + .BADF => return error.NotOpenForReading, // can be a race condition + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -426,16 +426,16 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize { // TODO handle the case when iov_len is too large and get rid of this @intCast const rc = system.readv(fd, iov.ptr, iov_count); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EINVAL => unreachable, - EFAULT => unreachable, - EAGAIN => return error.WouldBlock, - EBADF => return error.NotOpenForReading, // can be a race condition - EIO => return error.InputOutput, - EISDIR => return error.IsDir, - ENOBUFS => return error.SystemResources, - ENOMEM => return error.SystemResources, + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => return error.WouldBlock, + .BADF => return error.NotOpenForReading, // can be a race condition + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, else => |err| return unexpectedErrno(err), } } @@ -469,21 +469,21 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { var nread: usize = undefined; switch (wasi.fd_pread(fd, &iovs, iovs.len, offset, &nread)) { - wasi.ESUCCESS => return nread, - wasi.EINTR => unreachable, - wasi.EINVAL => unreachable, - wasi.EFAULT => unreachable, - wasi.EAGAIN => unreachable, - wasi.EBADF => return error.NotOpenForReading, // Can be a race condition. - wasi.EIO => return error.InputOutput, - wasi.EISDIR => return error.IsDir, - wasi.ENOBUFS => return error.SystemResources, - wasi.ENOMEM => return error.SystemResources, - wasi.ECONNRESET => return error.ConnectionResetByPeer, - wasi.ENXIO => return error.Unseekable, - wasi.ESPIPE => return error.Unseekable, - wasi.EOVERFLOW => return error.Unseekable, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return nread, + .INTR => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, + .BADF => return error.NotOpenForReading, // Can be a race condition. + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .CONNRESET => return error.ConnectionResetByPeer, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -505,20 +505,20 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { while (true) { const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EINVAL => unreachable, - EFAULT => unreachable, - EAGAIN => return error.WouldBlock, - EBADF => return error.NotOpenForReading, // Can be a race condition. - EIO => return error.InputOutput, - EISDIR => return error.IsDir, - ENOBUFS => return error.SystemResources, - ENOMEM => return error.SystemResources, - ECONNRESET => return error.ConnectionResetByPeer, - ENXIO => return error.Unseekable, - ESPIPE => return error.Unseekable, - EOVERFLOW => return error.Unseekable, + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => return error.WouldBlock, + .BADF => return error.NotOpenForReading, // Can be a race condition. + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .CONNRESET => return error.ConnectionResetByPeer, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, + .OVERFLOW => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -558,15 +558,15 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { } if (std.Target.current.os.tag == .wasi and !builtin.link_libc) { switch (wasi.fd_filestat_set_size(fd, length)) { - wasi.ESUCCESS => return, - wasi.EINTR => unreachable, - wasi.EFBIG => return error.FileTooBig, - wasi.EIO => return error.InputOutput, - wasi.EPERM => return error.AccessDenied, - wasi.ETXTBSY => return error.FileBusy, - wasi.EBADF => unreachable, // Handle not open for writing - wasi.EINVAL => unreachable, // Handle not open for writing - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return, + .INTR => unreachable, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .PERM => return error.AccessDenied, + .TXTBSY => return error.FileBusy, + .BADF => unreachable, // Handle not open for writing + .INVAL => unreachable, // Handle not open for writing + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -579,14 +579,14 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { const ilen = @bitCast(i64, length); // the OS treats this as unsigned switch (errno(ftruncate_sym(fd, ilen))) { - 0 => return, - EINTR => continue, - EFBIG => return error.FileTooBig, - EIO => return error.InputOutput, - EPERM => return error.AccessDenied, - ETXTBSY => return error.FileBusy, - EBADF => unreachable, // Handle not open for writing - EINVAL => unreachable, // Handle not open for writing + .SUCCESS => return, + .INTR => continue, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .PERM => return error.AccessDenied, + .TXTBSY => return error.FileBusy, + .BADF => unreachable, // Handle not open for writing + .INVAL => unreachable, // Handle not open for writing else => |err| return unexpectedErrno(err), } } @@ -620,20 +620,20 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { if (builtin.os.tag == .wasi and !builtin.link_libc) { var nread: usize = undefined; switch (wasi.fd_pread(fd, iov.ptr, iov.len, offset, &nread)) { - wasi.ESUCCESS => return nread, - wasi.EINTR => unreachable, - wasi.EINVAL => unreachable, - wasi.EFAULT => unreachable, - wasi.EAGAIN => unreachable, - wasi.EBADF => return error.NotOpenForReading, // can be a race condition - wasi.EIO => return error.InputOutput, - wasi.EISDIR => return error.IsDir, - wasi.ENOBUFS => return error.SystemResources, - wasi.ENOMEM => return error.SystemResources, - wasi.ENXIO => return error.Unseekable, - wasi.ESPIPE => return error.Unseekable, - wasi.EOVERFLOW => return error.Unseekable, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return nread, + .INTR => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, + .BADF => return error.NotOpenForReading, // can be a race condition + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -649,19 +649,19 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { while (true) { const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset); switch (errno(rc)) { - 0 => return @bitCast(usize, rc), - EINTR => continue, - EINVAL => unreachable, - EFAULT => unreachable, - EAGAIN => return error.WouldBlock, - EBADF => return error.NotOpenForReading, // can be a race condition - EIO => return error.InputOutput, - EISDIR => return error.IsDir, - ENOBUFS => return error.SystemResources, - ENOMEM => return error.SystemResources, - ENXIO => return error.Unseekable, - ESPIPE => return error.Unseekable, - EOVERFLOW => return error.Unseekable, + .SUCCESS => return @bitCast(usize, rc), + .INTR => continue, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => return error.WouldBlock, + .BADF => return error.NotOpenForReading, // can be a race condition + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, + .OVERFLOW => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -723,20 +723,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { }}; var nwritten: usize = undefined; switch (wasi.fd_write(fd, &ciovs, ciovs.len, &nwritten)) { - wasi.ESUCCESS => return nwritten, - wasi.EINTR => unreachable, - wasi.EINVAL => unreachable, - wasi.EFAULT => unreachable, - wasi.EAGAIN => unreachable, - wasi.EBADF => return error.NotOpenForWriting, // can be a race condition. - wasi.EDESTADDRREQ => unreachable, // `connect` was never called. - wasi.EDQUOT => return error.DiskQuota, - wasi.EFBIG => return error.FileTooBig, - wasi.EIO => return error.InputOutput, - wasi.ENOSPC => return error.NoSpaceLeft, - wasi.EPERM => return error.AccessDenied, - wasi.EPIPE => return error.BrokenPipe, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return nwritten, + .INTR => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, + .BADF => return error.NotOpenForWriting, // can be a race condition. + .DESTADDRREQ => unreachable, // `connect` was never called. + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -751,20 +751,20 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { while (true) { const rc = system.write(fd, bytes.ptr, adjusted_len); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EINVAL => unreachable, - EFAULT => unreachable, - EAGAIN => return error.WouldBlock, - EBADF => return error.NotOpenForWriting, // can be a race condition. - EDESTADDRREQ => unreachable, // `connect` was never called. - EDQUOT => return error.DiskQuota, - EFBIG => return error.FileTooBig, - EIO => return error.InputOutput, - ENOSPC => return error.NoSpaceLeft, - EPERM => return error.AccessDenied, - EPIPE => return error.BrokenPipe, - ECONNRESET => return error.ConnectionResetByPeer, + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => return error.WouldBlock, + .BADF => return error.NotOpenForWriting, // can be a race condition. + .DESTADDRREQ => unreachable, // `connect` was never called. + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, + .CONNRESET => return error.ConnectionResetByPeer, else => |err| return unexpectedErrno(err), } } @@ -798,20 +798,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { if (builtin.os.tag == .wasi and !builtin.link_libc) { var nwritten: usize = undefined; switch (wasi.fd_write(fd, iov.ptr, iov.len, &nwritten)) { - wasi.ESUCCESS => return nwritten, - wasi.EINTR => unreachable, - wasi.EINVAL => unreachable, - wasi.EFAULT => unreachable, - wasi.EAGAIN => unreachable, - wasi.EBADF => return error.NotOpenForWriting, // can be a race condition. - wasi.EDESTADDRREQ => unreachable, // `connect` was never called. - wasi.EDQUOT => return error.DiskQuota, - wasi.EFBIG => return error.FileTooBig, - wasi.EIO => return error.InputOutput, - wasi.ENOSPC => return error.NoSpaceLeft, - wasi.EPERM => return error.AccessDenied, - wasi.EPIPE => return error.BrokenPipe, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return nwritten, + .INTR => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, + .BADF => return error.NotOpenForWriting, // can be a race condition. + .DESTADDRREQ => unreachable, // `connect` was never called. + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -820,20 +820,20 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { while (true) { const rc = system.writev(fd, iov.ptr, iov_count); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EINVAL => unreachable, - EFAULT => unreachable, - EAGAIN => return error.WouldBlock, - EBADF => return error.NotOpenForWriting, // Can be a race condition. - EDESTADDRREQ => unreachable, // `connect` was never called. - EDQUOT => return error.DiskQuota, - EFBIG => return error.FileTooBig, - EIO => return error.InputOutput, - ENOSPC => return error.NoSpaceLeft, - EPERM => return error.AccessDenied, - EPIPE => return error.BrokenPipe, - ECONNRESET => return error.ConnectionResetByPeer, + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => return error.WouldBlock, + .BADF => return error.NotOpenForWriting, // Can be a race condition. + .DESTADDRREQ => unreachable, // `connect` was never called. + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, + .CONNRESET => return error.ConnectionResetByPeer, else => |err| return unexpectedErrno(err), } } @@ -875,23 +875,23 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { var nwritten: usize = undefined; switch (wasi.fd_pwrite(fd, &ciovs, ciovs.len, offset, &nwritten)) { - wasi.ESUCCESS => return nwritten, - wasi.EINTR => unreachable, - wasi.EINVAL => unreachable, - wasi.EFAULT => unreachable, - wasi.EAGAIN => unreachable, - wasi.EBADF => return error.NotOpenForWriting, // can be a race condition. - wasi.EDESTADDRREQ => unreachable, // `connect` was never called. - wasi.EDQUOT => return error.DiskQuota, - wasi.EFBIG => return error.FileTooBig, - wasi.EIO => return error.InputOutput, - wasi.ENOSPC => return error.NoSpaceLeft, - wasi.EPERM => return error.AccessDenied, - wasi.EPIPE => return error.BrokenPipe, - wasi.ENXIO => return error.Unseekable, - wasi.ESPIPE => return error.Unseekable, - wasi.EOVERFLOW => return error.Unseekable, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return nwritten, + .INTR => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, + .BADF => return error.NotOpenForWriting, // can be a race condition. + .DESTADDRREQ => unreachable, // `connect` was never called. + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -913,22 +913,22 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { while (true) { const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EINVAL => unreachable, - EFAULT => unreachable, - EAGAIN => return error.WouldBlock, - EBADF => return error.NotOpenForWriting, // Can be a race condition. - EDESTADDRREQ => unreachable, // `connect` was never called. - EDQUOT => return error.DiskQuota, - EFBIG => return error.FileTooBig, - EIO => return error.InputOutput, - ENOSPC => return error.NoSpaceLeft, - EPERM => return error.AccessDenied, - EPIPE => return error.BrokenPipe, - ENXIO => return error.Unseekable, - ESPIPE => return error.Unseekable, - EOVERFLOW => return error.Unseekable, + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => return error.WouldBlock, + .BADF => return error.NotOpenForWriting, // Can be a race condition. + .DESTADDRREQ => unreachable, // `connect` was never called. + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, + .OVERFLOW => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -971,23 +971,23 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz if (builtin.os.tag == .wasi and !builtin.link_libc) { var nwritten: usize = undefined; switch (wasi.fd_pwrite(fd, iov.ptr, iov.len, offset, &nwritten)) { - wasi.ESUCCESS => return nwritten, - wasi.EINTR => unreachable, - wasi.EINVAL => unreachable, - wasi.EFAULT => unreachable, - wasi.EAGAIN => unreachable, - wasi.EBADF => return error.NotOpenForWriting, // Can be a race condition. - wasi.EDESTADDRREQ => unreachable, // `connect` was never called. - wasi.EDQUOT => return error.DiskQuota, - wasi.EFBIG => return error.FileTooBig, - wasi.EIO => return error.InputOutput, - wasi.ENOSPC => return error.NoSpaceLeft, - wasi.EPERM => return error.AccessDenied, - wasi.EPIPE => return error.BrokenPipe, - wasi.ENXIO => return error.Unseekable, - wasi.ESPIPE => return error.Unseekable, - wasi.EOVERFLOW => return error.Unseekable, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return nwritten, + .INTR => unreachable, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => unreachable, + .BADF => return error.NotOpenForWriting, // Can be a race condition. + .DESTADDRREQ => unreachable, // `connect` was never called. + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -1002,22 +1002,22 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz while (true) { const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EINVAL => unreachable, - EFAULT => unreachable, - EAGAIN => return error.WouldBlock, - EBADF => return error.NotOpenForWriting, // Can be a race condition. - EDESTADDRREQ => unreachable, // `connect` was never called. - EDQUOT => return error.DiskQuota, - EFBIG => return error.FileTooBig, - EIO => return error.InputOutput, - ENOSPC => return error.NoSpaceLeft, - EPERM => return error.AccessDenied, - EPIPE => return error.BrokenPipe, - ENXIO => return error.Unseekable, - ESPIPE => return error.Unseekable, - EOVERFLOW => return error.Unseekable, + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .INVAL => unreachable, + .FAULT => unreachable, + .AGAIN => return error.WouldBlock, + .BADF => return error.NotOpenForWriting, // Can be a race condition. + .DESTADDRREQ => unreachable, // `connect` was never called. + .DQUOT => return error.DiskQuota, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .PIPE => return error.BrokenPipe, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, + .OVERFLOW => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -1098,27 +1098,27 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t while (true) { const rc = open_sym(file_path, flags, perm); switch (errno(rc)) { - 0 => return @intCast(fd_t, rc), - EINTR => continue, + .SUCCESS => return @intCast(fd_t, rc), + .INTR => continue, - EFAULT => unreachable, - EINVAL => unreachable, - EACCES => return error.AccessDenied, - EFBIG => return error.FileTooBig, - EOVERFLOW => return error.FileTooBig, - EISDIR => return error.IsDir, - ELOOP => return error.SymLinkLoop, - EMFILE => return error.ProcessFdQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENFILE => return error.SystemFdQuotaExceeded, - ENODEV => return error.NoDevice, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - ENOTDIR => return error.NotDir, - EPERM => return error.AccessDenied, - EEXIST => return error.PathAlreadyExists, - EBUSY => return error.DeviceBusy, + .FAULT => unreachable, + .INVAL => unreachable, + .ACCES => return error.AccessDenied, + .FBIG => return error.FileTooBig, + .OVERFLOW => return error.FileTooBig, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .MFILE => return error.ProcessFdQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NFILE => return error.SystemFdQuotaExceeded, + .NODEV => return error.NoDevice, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .NOTDIR => return error.NotDir, + .PERM => return error.AccessDenied, + .EXIST => return error.PathAlreadyExists, + .BUSY => return error.DeviceBusy, else => |err| return unexpectedErrno(err), } } @@ -1193,28 +1193,28 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, lookup_flags: lookupflags while (true) { var fd: fd_t = undefined; switch (wasi.path_open(dir_fd, lookup_flags, file_path.ptr, file_path.len, oflags, base, inheriting, fdflags, &fd)) { - wasi.ESUCCESS => return fd, - wasi.EINTR => continue, + .SUCCESS => return fd, + .INTR => continue, - wasi.EFAULT => unreachable, - wasi.EINVAL => unreachable, - wasi.EACCES => return error.AccessDenied, - wasi.EFBIG => return error.FileTooBig, - wasi.EOVERFLOW => return error.FileTooBig, - wasi.EISDIR => return error.IsDir, - wasi.ELOOP => return error.SymLinkLoop, - wasi.EMFILE => return error.ProcessFdQuotaExceeded, - wasi.ENAMETOOLONG => return error.NameTooLong, - wasi.ENFILE => return error.SystemFdQuotaExceeded, - wasi.ENODEV => return error.NoDevice, - wasi.ENOENT => return error.FileNotFound, - wasi.ENOMEM => return error.SystemResources, - wasi.ENOSPC => return error.NoSpaceLeft, - wasi.ENOTDIR => return error.NotDir, - wasi.EPERM => return error.AccessDenied, - wasi.EEXIST => return error.PathAlreadyExists, - wasi.EBUSY => return error.DeviceBusy, - wasi.ENOTCAPABLE => return error.AccessDenied, + .FAULT => unreachable, + .INVAL => unreachable, + .ACCES => return error.AccessDenied, + .FBIG => return error.FileTooBig, + .OVERFLOW => return error.FileTooBig, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .MFILE => return error.ProcessFdQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NFILE => return error.SystemFdQuotaExceeded, + .NODEV => return error.NoDevice, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .NOTDIR => return error.NotDir, + .PERM => return error.AccessDenied, + .EXIST => return error.PathAlreadyExists, + .BUSY => return error.DeviceBusy, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -1239,30 +1239,30 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) while (true) { const rc = openat_sym(dir_fd, file_path, flags, mode); switch (errno(rc)) { - 0 => return @intCast(fd_t, rc), - EINTR => continue, + .SUCCESS => return @intCast(fd_t, rc), + .INTR => continue, - EFAULT => unreachable, - EINVAL => unreachable, - EBADF => unreachable, - EACCES => return error.AccessDenied, - EFBIG => return error.FileTooBig, - EOVERFLOW => return error.FileTooBig, - EISDIR => return error.IsDir, - ELOOP => return error.SymLinkLoop, - EMFILE => return error.ProcessFdQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENFILE => return error.SystemFdQuotaExceeded, - ENODEV => return error.NoDevice, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - ENOTDIR => return error.NotDir, - EPERM => return error.AccessDenied, - EEXIST => return error.PathAlreadyExists, - EBUSY => return error.DeviceBusy, - EOPNOTSUPP => return error.FileLocksNotSupported, - EWOULDBLOCK => return error.WouldBlock, + .FAULT => unreachable, + .INVAL => unreachable, + .BADF => unreachable, + .ACCES => return error.AccessDenied, + .FBIG => return error.FileTooBig, + .OVERFLOW => return error.FileTooBig, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .MFILE => return error.ProcessFdQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NFILE => return error.SystemFdQuotaExceeded, + .NODEV => return error.NoDevice, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .NOTDIR => return error.NotDir, + .PERM => return error.AccessDenied, + .EXIST => return error.PathAlreadyExists, + .BUSY => return error.DeviceBusy, + .OPNOTSUPP => return error.FileLocksNotSupported, + .AGAIN => return error.WouldBlock, else => |err| return unexpectedErrno(err), } } @@ -1286,9 +1286,9 @@ pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t) pub fn dup(old_fd: fd_t) !fd_t { const rc = system.dup(old_fd); return switch (errno(rc)) { - 0 => return @intCast(fd_t, rc), - EMFILE => error.ProcessFdQuotaExceeded, - EBADF => unreachable, // invalid file descriptor + .SUCCESS => return @intCast(fd_t, rc), + .MFILE => error.ProcessFdQuotaExceeded, + .BADF => unreachable, // invalid file descriptor else => |err| return unexpectedErrno(err), }; } @@ -1296,11 +1296,11 @@ pub fn dup(old_fd: fd_t) !fd_t { pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void { while (true) { switch (errno(system.dup2(old_fd, new_fd))) { - 0 => return, - EBUSY, EINTR => continue, - EMFILE => return error.ProcessFdQuotaExceeded, - EINVAL => unreachable, // invalid parameters passed to dup2 - EBADF => unreachable, // invalid file descriptor + .SUCCESS => return, + .BUSY, .INTR => continue, + .MFILE => return error.ProcessFdQuotaExceeded, + .INVAL => unreachable, // invalid parameters passed to dup2 + .BADF => unreachable, // invalid file descriptor else => |err| return unexpectedErrno(err), } } @@ -1331,23 +1331,23 @@ pub fn execveZ( envp: [*:null]const ?[*:0]const u8, ) ExecveError { switch (errno(system.execve(path, child_argv, envp))) { - 0 => unreachable, - EFAULT => unreachable, - E2BIG => return error.SystemResources, - EMFILE => return error.ProcessFdQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENFILE => return error.SystemFdQuotaExceeded, - ENOMEM => return error.SystemResources, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EINVAL => return error.InvalidExe, - ENOEXEC => return error.InvalidExe, - EIO => return error.FileSystem, - ELOOP => return error.FileSystem, - EISDIR => return error.IsDir, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - ETXTBSY => return error.FileBusy, + .SUCCESS => unreachable, + .FAULT => unreachable, + .@"2BIG" => return error.SystemResources, + .MFILE => return error.ProcessFdQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NFILE => return error.SystemFdQuotaExceeded, + .NOMEM => return error.SystemResources, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .INVAL => return error.InvalidExe, + .NOEXEC => return error.InvalidExe, + .IO => return error.FileSystem, + .LOOP => return error.FileSystem, + .ISDIR => return error.IsDir, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .TXTBSY => return error.FileBusy, else => |err| return unexpectedErrno(err), } } @@ -1543,16 +1543,17 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { } const err = if (builtin.link_libc) blk: { - break :blk if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*; + const c_err = if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*; + break :blk @intToEnum(E, c_err); } else blk: { break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len)); }; switch (err) { - 0 => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)), - EFAULT => unreachable, - EINVAL => unreachable, - ENOENT => return error.CurrentWorkingDirectoryUnlinked, - ERANGE => return error.NameTooLong, + .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)), + .FAULT => unreachable, + .INVAL => unreachable, + .NOENT => return error.CurrentWorkingDirectoryUnlinked, + .RANGE => return error.NameTooLong, else => return unexpectedErrno(err), } } @@ -1601,21 +1602,21 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin @compileError("symlink is not supported on Windows; use std.os.windows.CreateSymbolicLink instead"); } switch (errno(system.symlink(target_path, sym_link_path))) { - 0 => return, - EFAULT => unreachable, - EINVAL => unreachable, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EDQUOT => return error.DiskQuota, - EEXIST => return error.PathAlreadyExists, - EIO => return error.FileSystem, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .FAULT => unreachable, + .INVAL => unreachable, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .DQUOT => return error.DiskQuota, + .EXIST => return error.PathAlreadyExists, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } @@ -1644,22 +1645,22 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ"); /// See also `symlinkat`. pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void { switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) { - wasi.ESUCCESS => {}, - wasi.EFAULT => unreachable, - wasi.EINVAL => unreachable, - wasi.EACCES => return error.AccessDenied, - wasi.EPERM => return error.AccessDenied, - wasi.EDQUOT => return error.DiskQuota, - wasi.EEXIST => return error.PathAlreadyExists, - wasi.EIO => return error.FileSystem, - wasi.ELOOP => return error.SymLinkLoop, - wasi.ENAMETOOLONG => return error.NameTooLong, - wasi.ENOENT => return error.FileNotFound, - wasi.ENOTDIR => return error.NotDir, - wasi.ENOMEM => return error.SystemResources, - wasi.ENOSPC => return error.NoSpaceLeft, - wasi.EROFS => return error.ReadOnlyFileSystem, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => {}, + .FAULT => unreachable, + .INVAL => unreachable, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .DQUOT => return error.DiskQuota, + .EXIST => return error.PathAlreadyExists, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .ROFS => return error.ReadOnlyFileSystem, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -1671,21 +1672,21 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*: @compileError("symlinkat is not supported on Windows; use std.os.windows.CreateSymbolicLink instead"); } switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) { - 0 => return, - EFAULT => unreachable, - EINVAL => unreachable, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EDQUOT => return error.DiskQuota, - EEXIST => return error.PathAlreadyExists, - EIO => return error.FileSystem, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .FAULT => unreachable, + .INVAL => unreachable, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .DQUOT => return error.DiskQuota, + .EXIST => return error.PathAlreadyExists, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } @@ -1707,22 +1708,22 @@ pub const LinkError = UnexpectedError || error{ pub fn linkZ(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) LinkError!void { switch (errno(system.link(oldpath, newpath, flags))) { - 0 => return, - EACCES => return error.AccessDenied, - EDQUOT => return error.DiskQuota, - EEXIST => return error.PathAlreadyExists, - EFAULT => unreachable, - EIO => return error.FileSystem, - ELOOP => return error.SymLinkLoop, - EMLINK => return error.LinkQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - EPERM => return error.AccessDenied, - EROFS => return error.ReadOnlyFileSystem, - EXDEV => return error.NotSameFileSystem, - EINVAL => unreachable, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .DQUOT => return error.DiskQuota, + .EXIST => return error.PathAlreadyExists, + .FAULT => unreachable, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .MLINK => return error.LinkQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .PERM => return error.AccessDenied, + .ROFS => return error.ReadOnlyFileSystem, + .XDEV => return error.NotSameFileSystem, + .INVAL => unreachable, else => |err| return unexpectedErrno(err), } } @@ -1743,23 +1744,23 @@ pub fn linkatZ( flags: i32, ) LinkatError!void { switch (errno(system.linkat(olddir, oldpath, newdir, newpath, flags))) { - 0 => return, - EACCES => return error.AccessDenied, - EDQUOT => return error.DiskQuota, - EEXIST => return error.PathAlreadyExists, - EFAULT => unreachable, - EIO => return error.FileSystem, - ELOOP => return error.SymLinkLoop, - EMLINK => return error.LinkQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - ENOTDIR => return error.NotDir, - EPERM => return error.AccessDenied, - EROFS => return error.ReadOnlyFileSystem, - EXDEV => return error.NotSameFileSystem, - EINVAL => unreachable, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .DQUOT => return error.DiskQuota, + .EXIST => return error.PathAlreadyExists, + .FAULT => unreachable, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .MLINK => return error.LinkQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .NOTDIR => return error.NotDir, + .PERM => return error.AccessDenied, + .ROFS => return error.ReadOnlyFileSystem, + .XDEV => return error.NotSameFileSystem, + .INVAL => unreachable, else => |err| return unexpectedErrno(err), } } @@ -1822,20 +1823,20 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void { return unlinkW(file_path_w.span()); } switch (errno(system.unlink(file_path))) { - 0 => return, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EBUSY => return error.FileBusy, - EFAULT => unreachable, - EINVAL => unreachable, - EIO => return error.FileSystem, - EISDIR => return error.IsDir, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - ENOMEM => return error.SystemResources, - EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .BUSY => return error.FileBusy, + .FAULT => unreachable, + .INVAL => unreachable, + .IO => return error.FileSystem, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } @@ -1875,24 +1876,24 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro else wasi.path_unlink_file(dirfd, file_path.ptr, file_path.len); switch (res) { - wasi.ESUCCESS => return, - wasi.EACCES => return error.AccessDenied, - wasi.EPERM => return error.AccessDenied, - wasi.EBUSY => return error.FileBusy, - wasi.EFAULT => unreachable, - wasi.EIO => return error.FileSystem, - wasi.EISDIR => return error.IsDir, - wasi.ELOOP => return error.SymLinkLoop, - wasi.ENAMETOOLONG => return error.NameTooLong, - wasi.ENOENT => return error.FileNotFound, - wasi.ENOTDIR => return error.NotDir, - wasi.ENOMEM => return error.SystemResources, - wasi.EROFS => return error.ReadOnlyFileSystem, - wasi.ENOTEMPTY => return error.DirNotEmpty, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .BUSY => return error.FileBusy, + .FAULT => unreachable, + .IO => return error.FileSystem, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .ROFS => return error.ReadOnlyFileSystem, + .NOTEMPTY => return error.DirNotEmpty, + .NOTCAPABLE => return error.AccessDenied, - wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component - wasi.EBADF => unreachable, // always a race condition + .INVAL => unreachable, // invalid flags, or pathname has . as last component + .BADF => unreachable, // always a race condition else => |err| return unexpectedErrno(err), } @@ -1905,23 +1906,23 @@ pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatEr return unlinkatW(dirfd, file_path_w.span(), flags); } switch (errno(system.unlinkat(dirfd, file_path_c, flags))) { - 0 => return, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EBUSY => return error.FileBusy, - EFAULT => unreachable, - EIO => return error.FileSystem, - EISDIR => return error.IsDir, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - ENOMEM => return error.SystemResources, - EROFS => return error.ReadOnlyFileSystem, - ENOTEMPTY => return error.DirNotEmpty, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .BUSY => return error.FileBusy, + .FAULT => unreachable, + .IO => return error.FileSystem, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .ROFS => return error.ReadOnlyFileSystem, + .NOTEMPTY => return error.DirNotEmpty, - EINVAL => unreachable, // invalid flags, or pathname has . as last component - EBADF => unreachable, // always a race condition + .INVAL => unreachable, // invalid flags, or pathname has . as last component + .BADF => unreachable, // always a race condition else => |err| return unexpectedErrno(err), } @@ -1982,25 +1983,25 @@ pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!voi return renameW(old_path_w.span().ptr, new_path_w.span().ptr); } switch (errno(system.rename(old_path, new_path))) { - 0 => return, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EBUSY => return error.FileBusy, - EDQUOT => return error.DiskQuota, - EFAULT => unreachable, - EINVAL => unreachable, - EISDIR => return error.IsDir, - ELOOP => return error.SymLinkLoop, - EMLINK => return error.LinkQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - EEXIST => return error.PathAlreadyExists, - ENOTEMPTY => return error.PathAlreadyExists, - EROFS => return error.ReadOnlyFileSystem, - EXDEV => return error.RenameAcrossMountPoints, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .BUSY => return error.FileBusy, + .DQUOT => return error.DiskQuota, + .FAULT => unreachable, + .INVAL => unreachable, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .MLINK => return error.LinkQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .EXIST => return error.PathAlreadyExists, + .NOTEMPTY => return error.PathAlreadyExists, + .ROFS => return error.ReadOnlyFileSystem, + .XDEV => return error.RenameAcrossMountPoints, else => |err| return unexpectedErrno(err), } } @@ -2036,26 +2037,26 @@ pub fn renameat( /// See also `renameat`. pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void { switch (wasi.path_rename(old_dir_fd, old_path.ptr, old_path.len, new_dir_fd, new_path.ptr, new_path.len)) { - wasi.ESUCCESS => return, - wasi.EACCES => return error.AccessDenied, - wasi.EPERM => return error.AccessDenied, - wasi.EBUSY => return error.FileBusy, - wasi.EDQUOT => return error.DiskQuota, - wasi.EFAULT => unreachable, - wasi.EINVAL => unreachable, - wasi.EISDIR => return error.IsDir, - wasi.ELOOP => return error.SymLinkLoop, - wasi.EMLINK => return error.LinkQuotaExceeded, - wasi.ENAMETOOLONG => return error.NameTooLong, - wasi.ENOENT => return error.FileNotFound, - wasi.ENOTDIR => return error.NotDir, - wasi.ENOMEM => return error.SystemResources, - wasi.ENOSPC => return error.NoSpaceLeft, - wasi.EEXIST => return error.PathAlreadyExists, - wasi.ENOTEMPTY => return error.PathAlreadyExists, - wasi.EROFS => return error.ReadOnlyFileSystem, - wasi.EXDEV => return error.RenameAcrossMountPoints, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .BUSY => return error.FileBusy, + .DQUOT => return error.DiskQuota, + .FAULT => unreachable, + .INVAL => unreachable, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .MLINK => return error.LinkQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .EXIST => return error.PathAlreadyExists, + .NOTEMPTY => return error.PathAlreadyExists, + .ROFS => return error.ReadOnlyFileSystem, + .XDEV => return error.RenameAcrossMountPoints, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -2074,25 +2075,25 @@ pub fn renameatZ( } switch (errno(system.renameat(old_dir_fd, old_path, new_dir_fd, new_path))) { - 0 => return, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EBUSY => return error.FileBusy, - EDQUOT => return error.DiskQuota, - EFAULT => unreachable, - EINVAL => unreachable, - EISDIR => return error.IsDir, - ELOOP => return error.SymLinkLoop, - EMLINK => return error.LinkQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - EEXIST => return error.PathAlreadyExists, - ENOTEMPTY => return error.PathAlreadyExists, - EROFS => return error.ReadOnlyFileSystem, - EXDEV => return error.RenameAcrossMountPoints, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .BUSY => return error.FileBusy, + .DQUOT => return error.DiskQuota, + .FAULT => unreachable, + .INVAL => unreachable, + .ISDIR => return error.IsDir, + .LOOP => return error.SymLinkLoop, + .MLINK => return error.LinkQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .EXIST => return error.PathAlreadyExists, + .NOTEMPTY => return error.PathAlreadyExists, + .ROFS => return error.ReadOnlyFileSystem, + .XDEV => return error.RenameAcrossMountPoints, else => |err| return unexpectedErrno(err), } } @@ -2172,22 +2173,22 @@ pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ"); pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void { _ = mode; switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) { - wasi.ESUCCESS => return, - wasi.EACCES => return error.AccessDenied, - wasi.EBADF => unreachable, - wasi.EPERM => return error.AccessDenied, - wasi.EDQUOT => return error.DiskQuota, - wasi.EEXIST => return error.PathAlreadyExists, - wasi.EFAULT => unreachable, - wasi.ELOOP => return error.SymLinkLoop, - wasi.EMLINK => return error.LinkQuotaExceeded, - wasi.ENAMETOOLONG => return error.NameTooLong, - wasi.ENOENT => return error.FileNotFound, - wasi.ENOMEM => return error.SystemResources, - wasi.ENOSPC => return error.NoSpaceLeft, - wasi.ENOTDIR => return error.NotDir, - wasi.EROFS => return error.ReadOnlyFileSystem, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .BADF => unreachable, + .PERM => return error.AccessDenied, + .DQUOT => return error.DiskQuota, + .EXIST => return error.PathAlreadyExists, + .FAULT => unreachable, + .LOOP => return error.SymLinkLoop, + .MLINK => return error.LinkQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .NOTDIR => return error.NotDir, + .ROFS => return error.ReadOnlyFileSystem, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -2198,21 +2199,21 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirErr return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode); } switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) { - 0 => return, - EACCES => return error.AccessDenied, - EBADF => unreachable, - EPERM => return error.AccessDenied, - EDQUOT => return error.DiskQuota, - EEXIST => return error.PathAlreadyExists, - EFAULT => unreachable, - ELOOP => return error.SymLinkLoop, - EMLINK => return error.LinkQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - ENOTDIR => return error.NotDir, - EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .BADF => unreachable, + .PERM => return error.AccessDenied, + .DQUOT => return error.DiskQuota, + .EXIST => return error.PathAlreadyExists, + .FAULT => unreachable, + .LOOP => return error.SymLinkLoop, + .MLINK => return error.LinkQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .NOTDIR => return error.NotDir, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } @@ -2274,20 +2275,20 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: u32) MakeDirError!void { return mkdirW(dir_path_w.span(), mode); } switch (errno(system.mkdir(dir_path, mode))) { - 0 => return, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EDQUOT => return error.DiskQuota, - EEXIST => return error.PathAlreadyExists, - EFAULT => unreachable, - ELOOP => return error.SymLinkLoop, - EMLINK => return error.LinkQuotaExceeded, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOSPC => return error.NoSpaceLeft, - ENOTDIR => return error.NotDir, - EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .DQUOT => return error.DiskQuota, + .EXIST => return error.PathAlreadyExists, + .FAULT => unreachable, + .LOOP => return error.SymLinkLoop, + .MLINK => return error.LinkQuotaExceeded, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.NoSpaceLeft, + .NOTDIR => return error.NotDir, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } @@ -2346,20 +2347,20 @@ pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void { return rmdirW(dir_path_w.span()); } switch (errno(system.rmdir(dir_path))) { - 0 => return, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EBUSY => return error.FileBusy, - EFAULT => unreachable, - EINVAL => unreachable, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOTDIR => return error.NotDir, - EEXIST => return error.DirNotEmpty, - ENOTEMPTY => return error.DirNotEmpty, - EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .BUSY => return error.FileBusy, + .FAULT => unreachable, + .INVAL => unreachable, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOTDIR => return error.NotDir, + .EXIST => return error.DirNotEmpty, + .NOTEMPTY => return error.DirNotEmpty, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } @@ -2413,15 +2414,15 @@ pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { return chdirW(utf16_dir_path[0..len]); } switch (errno(system.chdir(dir_path))) { - 0 => return, - EACCES => return error.AccessDenied, - EFAULT => unreachable, - EIO => return error.FileSystem, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOTDIR => return error.NotDir, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .FAULT => unreachable, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOTDIR => return error.NotDir, else => |err| return unexpectedErrno(err), } } @@ -2443,12 +2444,12 @@ pub const FchdirError = error{ pub fn fchdir(dirfd: fd_t) FchdirError!void { while (true) { switch (errno(system.fchdir(dirfd))) { - 0 => return, - EACCES => return error.AccessDenied, - EBADF => unreachable, - ENOTDIR => return error.NotDir, - EINTR => continue, - EIO => return error.FileSystem, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .BADF => unreachable, + .NOTDIR => return error.NotDir, + .INTR => continue, + .IO => return error.FileSystem, else => |err| return unexpectedErrno(err), } } @@ -2501,16 +2502,16 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 } const rc = system.readlink(file_path, out_buffer.ptr, out_buffer.len); switch (errno(rc)) { - 0 => return out_buffer[0..@bitCast(usize, rc)], - EACCES => return error.AccessDenied, - EFAULT => unreachable, - EINVAL => unreachable, - EIO => return error.FileSystem, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOTDIR => return error.NotDir, + .SUCCESS => return out_buffer[0..@bitCast(usize, rc)], + .ACCES => return error.AccessDenied, + .FAULT => unreachable, + .INVAL => unreachable, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOTDIR => return error.NotDir, else => |err| return unexpectedErrno(err), } } @@ -2537,17 +2538,17 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ"); pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { var bufused: usize = undefined; switch (wasi.path_readlink(dirfd, file_path.ptr, file_path.len, out_buffer.ptr, out_buffer.len, &bufused)) { - wasi.ESUCCESS => return out_buffer[0..bufused], - wasi.EACCES => return error.AccessDenied, - wasi.EFAULT => unreachable, - wasi.EINVAL => unreachable, - wasi.EIO => return error.FileSystem, - wasi.ELOOP => return error.SymLinkLoop, - wasi.ENAMETOOLONG => return error.NameTooLong, - wasi.ENOENT => return error.FileNotFound, - wasi.ENOMEM => return error.SystemResources, - wasi.ENOTDIR => return error.NotDir, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return out_buffer[0..bufused], + .ACCES => return error.AccessDenied, + .FAULT => unreachable, + .INVAL => unreachable, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOTDIR => return error.NotDir, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -2567,16 +2568,16 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read } const rc = system.readlinkat(dirfd, file_path, out_buffer.ptr, out_buffer.len); switch (errno(rc)) { - 0 => return out_buffer[0..@bitCast(usize, rc)], - EACCES => return error.AccessDenied, - EFAULT => unreachable, - EINVAL => unreachable, - EIO => return error.FileSystem, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOTDIR => return error.NotDir, + .SUCCESS => return out_buffer[0..@bitCast(usize, rc)], + .ACCES => return error.AccessDenied, + .FAULT => unreachable, + .INVAL => unreachable, + .IO => return error.FileSystem, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOTDIR => return error.NotDir, else => |err| return unexpectedErrno(err), } } @@ -2590,58 +2591,58 @@ pub const SetIdError = error{ResourceLimitReached} || SetEidError; pub fn setuid(uid: uid_t) SetIdError!void { switch (errno(system.setuid(uid))) { - 0 => return, - EAGAIN => return error.ResourceLimitReached, - EINVAL => return error.InvalidUserId, - EPERM => return error.PermissionDenied, + .SUCCESS => return, + .AGAIN => return error.ResourceLimitReached, + .INVAL => return error.InvalidUserId, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } pub fn seteuid(uid: uid_t) SetEidError!void { switch (errno(system.seteuid(uid))) { - 0 => return, - EINVAL => return error.InvalidUserId, - EPERM => return error.PermissionDenied, + .SUCCESS => return, + .INVAL => return error.InvalidUserId, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } pub fn setreuid(ruid: uid_t, euid: uid_t) SetIdError!void { switch (errno(system.setreuid(ruid, euid))) { - 0 => return, - EAGAIN => return error.ResourceLimitReached, - EINVAL => return error.InvalidUserId, - EPERM => return error.PermissionDenied, + .SUCCESS => return, + .AGAIN => return error.ResourceLimitReached, + .INVAL => return error.InvalidUserId, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } pub fn setgid(gid: gid_t) SetIdError!void { switch (errno(system.setgid(gid))) { - 0 => return, - EAGAIN => return error.ResourceLimitReached, - EINVAL => return error.InvalidUserId, - EPERM => return error.PermissionDenied, + .SUCCESS => return, + .AGAIN => return error.ResourceLimitReached, + .INVAL => return error.InvalidUserId, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } pub fn setegid(uid: uid_t) SetEidError!void { switch (errno(system.setegid(uid))) { - 0 => return, - EINVAL => return error.InvalidUserId, - EPERM => return error.PermissionDenied, + .SUCCESS => return, + .INVAL => return error.InvalidUserId, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } pub fn setregid(rgid: gid_t, egid: gid_t) SetIdError!void { switch (errno(system.setregid(rgid, egid))) { - 0 => return, - EAGAIN => return error.ResourceLimitReached, - EINVAL => return error.InvalidUserId, - EPERM => return error.PermissionDenied, + .SUCCESS => return, + .AGAIN => return error.ResourceLimitReached, + .INVAL => return error.InvalidUserId, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } @@ -2680,9 +2681,10 @@ pub fn isatty(handle: fd_t) bool { while (true) { var wsz: linux.winsize = undefined; const fd = @bitCast(usize, @as(isize, handle)); - switch (linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz))) { - 0 => return true, - EINTR => continue, + const rc = linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz)); + switch (linux.getErrno(rc)) { + .SUCCESS => return true, + .INTR => continue, else => return false, } } @@ -2777,22 +2779,22 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t socket_type; const rc = system.socket(domain, filtered_sock_type, protocol); switch (errno(rc)) { - 0 => { + .SUCCESS => { const fd = @intCast(fd_t, rc); if (!have_sock_flags) { try setSockFlags(fd, socket_type); } return fd; }, - EACCES => return error.PermissionDenied, - EAFNOSUPPORT => return error.AddressFamilyNotSupported, - EINVAL => return error.ProtocolFamilyNotAvailable, - EMFILE => return error.ProcessFdQuotaExceeded, - ENFILE => return error.SystemFdQuotaExceeded, - ENOBUFS => return error.SystemResources, - ENOMEM => return error.SystemResources, - EPROTONOSUPPORT => return error.ProtocolNotSupported, - EPROTOTYPE => return error.SocketTypeNotSupported, + .ACCES => return error.PermissionDenied, + .AFNOSUPPORT => return error.AddressFamilyNotSupported, + .INVAL => return error.ProtocolFamilyNotAvailable, + .MFILE => return error.ProcessFdQuotaExceeded, + .NFILE => return error.SystemFdQuotaExceeded, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .PROTONOSUPPORT => return error.ProtocolNotSupported, + .PROTOTYPE => return error.SocketTypeNotSupported, else => |err| return unexpectedErrno(err), } } @@ -2840,12 +2842,12 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void { .both => SHUT_RDWR, }); switch (errno(rc)) { - 0 => return, - EBADF => unreachable, - EINVAL => unreachable, - ENOTCONN => return error.SocketNotConnected, - ENOTSOCK => unreachable, - ENOBUFS => return error.SystemResources, + .SUCCESS => return, + .BADF => unreachable, + .INVAL => unreachable, + .NOTCONN => return error.SocketNotConnected, + .NOTSOCK => unreachable, + .NOBUFS => return error.SystemResources, else => |err| return unexpectedErrno(err), } } @@ -2924,20 +2926,20 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi } else { const rc = system.bind(sock, addr, len); switch (errno(rc)) { - 0 => return, - EACCES => return error.AccessDenied, - EADDRINUSE => return error.AddressInUse, - EBADF => unreachable, // always a race condition if this error is returned - EINVAL => unreachable, // invalid parameters - ENOTSOCK => unreachable, // invalid `sockfd` - EADDRNOTAVAIL => return error.AddressNotAvailable, - EFAULT => unreachable, // invalid `addr` pointer - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOTDIR => return error.NotDir, - EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .ADDRINUSE => return error.AddressInUse, + .BADF => unreachable, // always a race condition if this error is returned + .INVAL => unreachable, // invalid parameters + .NOTSOCK => unreachable, // invalid `sockfd` + .ADDRNOTAVAIL => return error.AddressNotAvailable, + .FAULT => unreachable, // invalid `addr` pointer + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOTDIR => return error.NotDir, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } @@ -2993,11 +2995,11 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void { } else { const rc = system.listen(sock, backlog); switch (errno(rc)) { - 0 => return, - EADDRINUSE => return error.AddressInUse, - EBADF => unreachable, - ENOTSOCK => return error.FileDescriptorNotASocket, - EOPNOTSUPP => return error.OperationNotSupported, + .SUCCESS => return, + .ADDRINUSE => return error.AddressInUse, + .BADF => unreachable, + .NOTSOCK => return error.FileDescriptorNotASocket, + .OPNOTSUPP => return error.OperationNotSupported, else => |err| return unexpectedErrno(err), } } @@ -3099,23 +3101,23 @@ pub fn accept( } } else { switch (errno(rc)) { - 0 => { + .SUCCESS => { break @intCast(socket_t, rc); }, - EINTR => continue, - EAGAIN => return error.WouldBlock, - EBADF => unreachable, // always a race condition - ECONNABORTED => return error.ConnectionAborted, - EFAULT => unreachable, - EINVAL => return error.SocketNotListening, - ENOTSOCK => unreachable, - EMFILE => return error.ProcessFdQuotaExceeded, - ENFILE => return error.SystemFdQuotaExceeded, - ENOBUFS => return error.SystemResources, - ENOMEM => return error.SystemResources, - EOPNOTSUPP => unreachable, - EPROTO => return error.ProtocolFailure, - EPERM => return error.BlockedByFirewall, + .INTR => continue, + .AGAIN => return error.WouldBlock, + .BADF => unreachable, // always a race condition + .CONNABORTED => return error.ConnectionAborted, + .FAULT => unreachable, + .INVAL => return error.SocketNotListening, + .NOTSOCK => unreachable, + .MFILE => return error.ProcessFdQuotaExceeded, + .NFILE => return error.SystemFdQuotaExceeded, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .OPNOTSUPP => unreachable, + .PROTO => return error.ProtocolFailure, + .PERM => return error.BlockedByFirewall, else => |err| return unexpectedErrno(err), } } @@ -3144,13 +3146,13 @@ pub const EpollCreateError = error{ pub fn epoll_create1(flags: u32) EpollCreateError!i32 { const rc = system.epoll_create1(flags); switch (errno(rc)) { - 0 => return @intCast(i32, rc), + .SUCCESS => return @intCast(i32, rc), else => |err| return unexpectedErrno(err), - EINVAL => unreachable, - EMFILE => return error.ProcessFdQuotaExceeded, - ENFILE => return error.SystemFdQuotaExceeded, - ENOMEM => return error.SystemResources, + .INVAL => unreachable, + .MFILE => return error.ProcessFdQuotaExceeded, + .NFILE => return error.SystemFdQuotaExceeded, + .NOMEM => return error.SystemResources, } } @@ -3183,17 +3185,17 @@ pub const EpollCtlError = error{ pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void { const rc = system.epoll_ctl(epfd, op, fd, event); switch (errno(rc)) { - 0 => return, + .SUCCESS => return, else => |err| return unexpectedErrno(err), - EBADF => unreachable, // always a race condition if this happens - EEXIST => return error.FileDescriptorAlreadyPresentInSet, - EINVAL => unreachable, - ELOOP => return error.OperationCausesCircularLoop, - ENOENT => return error.FileDescriptorNotRegistered, - ENOMEM => return error.SystemResources, - ENOSPC => return error.UserResourceLimitReached, - EPERM => return error.FileDescriptorIncompatibleWithEpoll, + .BADF => unreachable, // always a race condition if this happens + .EXIST => return error.FileDescriptorAlreadyPresentInSet, + .INVAL => unreachable, + .LOOP => return error.OperationCausesCircularLoop, + .NOENT => return error.FileDescriptorNotRegistered, + .NOMEM => return error.SystemResources, + .NOSPC => return error.UserResourceLimitReached, + .PERM => return error.FileDescriptorIncompatibleWithEpoll, } } @@ -3205,11 +3207,11 @@ pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize { // TODO get rid of the @intCast const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EBADF => unreachable, - EFAULT => unreachable, - EINVAL => unreachable, + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .BADF => unreachable, + .FAULT => unreachable, + .INVAL => unreachable, else => unreachable, } } @@ -3224,14 +3226,14 @@ pub const EventFdError = error{ pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 { const rc = system.eventfd(initval, flags); switch (errno(rc)) { - 0 => return @intCast(i32, rc), + .SUCCESS => return @intCast(i32, rc), else => |err| return unexpectedErrno(err), - EINVAL => unreachable, // invalid parameters - EMFILE => return error.ProcessFdQuotaExceeded, - ENFILE => return error.SystemFdQuotaExceeded, - ENODEV => return error.SystemResources, - ENOMEM => return error.SystemResources, + .INVAL => unreachable, // invalid parameters + .MFILE => return error.ProcessFdQuotaExceeded, + .NFILE => return error.SystemFdQuotaExceeded, + .NODEV => return error.SystemResources, + .NOMEM => return error.SystemResources, } } @@ -3265,14 +3267,14 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock } else { const rc = system.getsockname(sock, addr, addrlen); switch (errno(rc)) { - 0 => return, + .SUCCESS => return, else => |err| return unexpectedErrno(err), - EBADF => unreachable, // always a race condition - EFAULT => unreachable, - EINVAL => unreachable, // invalid parameters - ENOTSOCK => return error.FileDescriptorNotASocket, - ENOBUFS => return error.SystemResources, + .BADF => unreachable, // always a race condition + .FAULT => unreachable, + .INVAL => unreachable, // invalid parameters + .NOTSOCK => return error.FileDescriptorNotASocket, + .NOBUFS => return error.SystemResources, } } } @@ -3294,14 +3296,14 @@ pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock } else { const rc = system.getpeername(sock, addr, addrlen); switch (errno(rc)) { - 0 => return, + .SUCCESS => return, else => |err| return unexpectedErrno(err), - EBADF => unreachable, // always a race condition - EFAULT => unreachable, - EINVAL => unreachable, // invalid parameters - ENOTSOCK => return error.FileDescriptorNotASocket, - ENOBUFS => return error.SystemResources, + .BADF => unreachable, // always a race condition + .FAULT => unreachable, + .INVAL => unreachable, // invalid parameters + .NOTSOCK => return error.FileDescriptorNotASocket, + .NOBUFS => return error.SystemResources, } } } @@ -3384,61 +3386,61 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne while (true) { switch (errno(system.connect(sock, sock_addr, len))) { - 0 => return, - EACCES => return error.PermissionDenied, - EPERM => return error.PermissionDenied, - EADDRINUSE => return error.AddressInUse, - EADDRNOTAVAIL => return error.AddressNotAvailable, - EAFNOSUPPORT => return error.AddressFamilyNotSupported, - EAGAIN, EINPROGRESS => return error.WouldBlock, - EALREADY => return error.ConnectionPending, - EBADF => unreachable, // sockfd is not a valid open file descriptor. - ECONNREFUSED => return error.ConnectionRefused, - ECONNRESET => return error.ConnectionResetByPeer, - EFAULT => unreachable, // The socket structure address is outside the user's address space. - EINTR => continue, - EISCONN => unreachable, // The socket is already connected. - ENETUNREACH => return error.NetworkUnreachable, - ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. - EPROTOTYPE => unreachable, // The socket type does not support the requested communications protocol. - ETIMEDOUT => return error.ConnectionTimedOut, - ENOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist. + .SUCCESS => return, + .ACCES => return error.PermissionDenied, + .PERM => return error.PermissionDenied, + .ADDRINUSE => return error.AddressInUse, + .ADDRNOTAVAIL => return error.AddressNotAvailable, + .AFNOSUPPORT => return error.AddressFamilyNotSupported, + .AGAIN, .INPROGRESS => return error.WouldBlock, + .ALREADY => return error.ConnectionPending, + .BADF => unreachable, // sockfd is not a valid open file descriptor. + .CONNREFUSED => return error.ConnectionRefused, + .CONNRESET => return error.ConnectionResetByPeer, + .FAULT => unreachable, // The socket structure address is outside the user's address space. + .INTR => continue, + .ISCONN => unreachable, // The socket is already connected. + .NETUNREACH => return error.NetworkUnreachable, + .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. + .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol. + .TIMEDOUT => return error.ConnectionTimedOut, + .NOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist. else => |err| return unexpectedErrno(err), } } } pub fn getsockoptError(sockfd: fd_t) ConnectError!void { - var err_code: u32 = undefined; + var err_code: i32 = undefined; var size: u32 = @sizeOf(u32); const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size); assert(size == 4); switch (errno(rc)) { - 0 => switch (err_code) { - 0 => return, - EACCES => return error.PermissionDenied, - EPERM => return error.PermissionDenied, - EADDRINUSE => return error.AddressInUse, - EADDRNOTAVAIL => return error.AddressNotAvailable, - EAFNOSUPPORT => return error.AddressFamilyNotSupported, - EAGAIN => return error.SystemResources, - EALREADY => return error.ConnectionPending, - EBADF => unreachable, // sockfd is not a valid open file descriptor. - ECONNREFUSED => return error.ConnectionRefused, - EFAULT => unreachable, // The socket structure address is outside the user's address space. - EISCONN => unreachable, // The socket is already connected. - ENETUNREACH => return error.NetworkUnreachable, - ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. - EPROTOTYPE => unreachable, // The socket type does not support the requested communications protocol. - ETIMEDOUT => return error.ConnectionTimedOut, - ECONNRESET => return error.ConnectionResetByPeer, + .SUCCESS => switch (@intToEnum(E, err_code)) { + .SUCCESS => return, + .ACCES => return error.PermissionDenied, + .PERM => return error.PermissionDenied, + .ADDRINUSE => return error.AddressInUse, + .ADDRNOTAVAIL => return error.AddressNotAvailable, + .AFNOSUPPORT => return error.AddressFamilyNotSupported, + .AGAIN => return error.SystemResources, + .ALREADY => return error.ConnectionPending, + .BADF => unreachable, // sockfd is not a valid open file descriptor. + .CONNREFUSED => return error.ConnectionRefused, + .FAULT => unreachable, // The socket structure address is outside the user's address space. + .ISCONN => unreachable, // The socket is already connected. + .NETUNREACH => return error.NetworkUnreachable, + .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. + .PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol. + .TIMEDOUT => return error.ConnectionTimedOut, + .CONNRESET => return error.ConnectionResetByPeer, else => |err| return unexpectedErrno(err), }, - EBADF => unreachable, // The argument sockfd is not a valid file descriptor. - EFAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space. - EINVAL => unreachable, - ENOPROTOOPT => unreachable, // The option is unknown at the level indicated. - ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. + .BADF => unreachable, // The argument sockfd is not a valid file descriptor. + .FAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space. + .INVAL => unreachable, + .NOPROTOOPT => unreachable, // The option is unknown at the level indicated. + .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. else => |err| return unexpectedErrno(err), } } @@ -3454,13 +3456,13 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult { while (true) { const rc = system.waitpid(pid, &status, if (builtin.link_libc) @intCast(c_int, flags) else flags); switch (errno(rc)) { - 0 => return .{ + .SUCCESS => return .{ .pid = @intCast(pid_t, rc), .status = @bitCast(u32, status), }, - EINTR => continue, - ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error. - EINVAL => unreachable, // Invalid flags. + .INTR => continue, + .CHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error. + .INVAL => unreachable, // Invalid flags. else => unreachable, } } @@ -3484,12 +3486,12 @@ pub fn fstat(fd: fd_t) FStatError!Stat { if (builtin.os.tag == .wasi and !builtin.link_libc) { var stat: wasi.filestat_t = undefined; switch (wasi.fd_filestat_get(fd, &stat)) { - wasi.ESUCCESS => return Stat.fromFilestat(stat), - wasi.EINVAL => unreachable, - wasi.EBADF => unreachable, // Always a race condition. - wasi.ENOMEM => return error.SystemResources, - wasi.EACCES => return error.AccessDenied, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return Stat.fromFilestat(stat), + .INVAL => unreachable, + .BADF => unreachable, // Always a race condition. + .NOMEM => return error.SystemResources, + .ACCES => return error.AccessDenied, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -3504,11 +3506,11 @@ pub fn fstat(fd: fd_t) FStatError!Stat { var stat = mem.zeroes(Stat); switch (errno(fstat_sym(fd, &stat))) { - 0 => return stat, - EINVAL => unreachable, - EBADF => unreachable, // Always a race condition. - ENOMEM => return error.SystemResources, - EACCES => return error.AccessDenied, + .SUCCESS => return stat, + .INVAL => unreachable, + .BADF => unreachable, // Always a race condition. + .NOMEM => return error.SystemResources, + .ACCES => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -3536,16 +3538,16 @@ pub const fstatatC = @compileError("deprecated: renamed to fstatatZ"); pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat { var stat: wasi.filestat_t = undefined; switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) { - wasi.ESUCCESS => return Stat.fromFilestat(stat), - wasi.EINVAL => unreachable, - wasi.EBADF => unreachable, // Always a race condition. - wasi.ENOMEM => return error.SystemResources, - wasi.EACCES => return error.AccessDenied, - wasi.EFAULT => unreachable, - wasi.ENAMETOOLONG => return error.NameTooLong, - wasi.ENOENT => return error.FileNotFound, - wasi.ENOTDIR => return error.FileNotFound, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return Stat.fromFilestat(stat), + .INVAL => unreachable, + .BADF => unreachable, // Always a race condition. + .NOMEM => return error.SystemResources, + .ACCES => return error.AccessDenied, + .FAULT => unreachable, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.FileNotFound, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -3560,17 +3562,17 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S var stat = mem.zeroes(Stat); switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) { - 0 => return stat, - EINVAL => unreachable, - EBADF => unreachable, // Always a race condition. - ENOMEM => return error.SystemResources, - EACCES => return error.AccessDenied, - EPERM => return error.AccessDenied, - EFAULT => unreachable, - ENAMETOOLONG => return error.NameTooLong, - ELOOP => return error.SymLinkLoop, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.FileNotFound, + .SUCCESS => return stat, + .INVAL => unreachable, + .BADF => unreachable, // Always a race condition. + .NOMEM => return error.SystemResources, + .ACCES => return error.AccessDenied, + .PERM => return error.AccessDenied, + .FAULT => unreachable, + .NAMETOOLONG => return error.NameTooLong, + .LOOP => return error.SymLinkLoop, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.FileNotFound, else => |err| return unexpectedErrno(err), } } @@ -3586,9 +3588,9 @@ pub const KQueueError = error{ pub fn kqueue() KQueueError!i32 { const rc = system.kqueue(); switch (errno(rc)) { - 0 => return @intCast(i32, rc), - EMFILE => return error.ProcessFdQuotaExceeded, - ENFILE => return error.SystemFdQuotaExceeded, + .SUCCESS => return @intCast(i32, rc), + .MFILE => return error.ProcessFdQuotaExceeded, + .NFILE => return error.SystemFdQuotaExceeded, else => |err| return unexpectedErrno(err), } } @@ -3627,15 +3629,15 @@ pub fn kevent( timeout, ); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EACCES => return error.AccessDenied, - EFAULT => unreachable, - EBADF => unreachable, // Always a race condition. - EINTR => continue, - EINVAL => unreachable, - ENOENT => return error.EventNotFound, - ENOMEM => return error.SystemResources, - ESRCH => return error.ProcessNotFound, + .SUCCESS => return @intCast(usize, rc), + .ACCES => return error.AccessDenied, + .FAULT => unreachable, + .BADF => unreachable, // Always a race condition. + .INTR => continue, + .INVAL => unreachable, + .NOENT => return error.EventNotFound, + .NOMEM => return error.SystemResources, + .SRCH => return error.ProcessNotFound, else => unreachable, } } @@ -3651,11 +3653,11 @@ pub const INotifyInitError = error{ pub fn inotify_init1(flags: u32) INotifyInitError!i32 { const rc = system.inotify_init1(flags); switch (errno(rc)) { - 0 => return @intCast(i32, rc), - EINVAL => unreachable, - EMFILE => return error.ProcessFdQuotaExceeded, - ENFILE => return error.SystemFdQuotaExceeded, - ENOMEM => return error.SystemResources, + .SUCCESS => return @intCast(i32, rc), + .INVAL => unreachable, + .MFILE => return error.ProcessFdQuotaExceeded, + .NFILE => return error.SystemFdQuotaExceeded, + .NOMEM => return error.SystemResources, else => |err| return unexpectedErrno(err), } } @@ -3681,16 +3683,16 @@ pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 { const rc = system.inotify_add_watch(inotify_fd, pathname, mask); switch (errno(rc)) { - 0 => return @intCast(i32, rc), - EACCES => return error.AccessDenied, - EBADF => unreachable, - EFAULT => unreachable, - EINVAL => unreachable, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOMEM => return error.SystemResources, - ENOSPC => return error.UserResourceLimitReached, - ENOTDIR => return error.NotDir, + .SUCCESS => return @intCast(i32, rc), + .ACCES => return error.AccessDenied, + .BADF => unreachable, + .FAULT => unreachable, + .INVAL => unreachable, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOSPC => return error.UserResourceLimitReached, + .NOTDIR => return error.NotDir, else => |err| return unexpectedErrno(err), } } @@ -3698,9 +3700,9 @@ pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) I /// remove an existing watch from an inotify instance pub fn inotify_rm_watch(inotify_fd: i32, wd: i32) void { switch (errno(system.inotify_rm_watch(inotify_fd, wd))) { - 0 => return, - EBADF => unreachable, - EINVAL => unreachable, + .SUCCESS => return, + .BADF => unreachable, + .INVAL => unreachable, else => unreachable, } } @@ -3723,10 +3725,10 @@ pub const MProtectError = error{ pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void { assert(mem.isAligned(memory.len, mem.page_size)); switch (errno(system.mprotect(memory.ptr, memory.len, protection))) { - 0 => return, - EINVAL => unreachable, - EACCES => return error.AccessDenied, - ENOMEM => return error.OutOfMemory, + .SUCCESS => return, + .INVAL => unreachable, + .ACCES => return error.AccessDenied, + .NOMEM => return error.OutOfMemory, else => |err| return unexpectedErrno(err), } } @@ -3736,9 +3738,9 @@ pub const ForkError = error{SystemResources} || UnexpectedError; pub fn fork() ForkError!pid_t { const rc = system.fork(); switch (errno(rc)) { - 0 => return @intCast(pid_t, rc), - EAGAIN => return error.SystemResources, - ENOMEM => return error.SystemResources, + .SUCCESS => return @intCast(pid_t, rc), + .AGAIN => return error.SystemResources, + .NOMEM => return error.SystemResources, else => |err| return unexpectedErrno(err), } } @@ -3782,22 +3784,23 @@ pub fn mmap( const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset); const err = if (builtin.link_libc) blk: { if (rc != std.c.MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length]; - break :blk system._errno().*; + break :blk @intToEnum(E, system._errno().*); } else blk: { const err = errno(rc); - if (err == 0) return @intToPtr([*]align(mem.page_size) u8, rc)[0..length]; + if (err == .SUCCESS) return @intToPtr([*]align(mem.page_size) u8, rc)[0..length]; break :blk err; }; switch (err) { - ETXTBSY => return error.AccessDenied, - EACCES => return error.AccessDenied, - EPERM => return error.PermissionDenied, - EAGAIN => return error.LockedMemoryLimitExceeded, - EBADF => unreachable, // Always a race condition. - EOVERFLOW => unreachable, // The number of pages used for length + offset would overflow. - ENODEV => return error.MemoryMappingNotSupported, - EINVAL => unreachable, // Invalid parameters to mmap() - ENOMEM => return error.OutOfMemory, + .SUCCESS => unreachable, + .TXTBSY => return error.AccessDenied, + .ACCES => return error.AccessDenied, + .PERM => return error.PermissionDenied, + .AGAIN => return error.LockedMemoryLimitExceeded, + .BADF => unreachable, // Always a race condition. + .OVERFLOW => unreachable, // The number of pages used for length + offset would overflow. + .NODEV => return error.MemoryMappingNotSupported, + .INVAL => unreachable, // Invalid parameters to mmap() + .NOMEM => return error.OutOfMemory, else => return unexpectedErrno(err), } } @@ -3810,9 +3813,9 @@ pub fn mmap( /// * The Windows function, VirtualFree, has this restriction. pub fn munmap(memory: []align(mem.page_size) const u8) void { switch (errno(system.munmap(memory.ptr, memory.len))) { - 0 => return, - EINVAL => unreachable, // Invalid parameters. - ENOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping. + .SUCCESS => return, + .INVAL => unreachable, // Invalid parameters. + .NOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping. else => unreachable, } } @@ -3854,18 +3857,18 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void { return; } switch (errno(system.access(path, mode))) { - 0 => return, - EACCES => return error.PermissionDenied, - EROFS => return error.ReadOnlyFileSystem, - ELOOP => return error.SymLinkLoop, - ETXTBSY => return error.FileBusy, - ENOTDIR => return error.FileNotFound, - ENOENT => return error.FileNotFound, - ENAMETOOLONG => return error.NameTooLong, - EINVAL => unreachable, - EFAULT => unreachable, - EIO => return error.InputOutput, - ENOMEM => return error.SystemResources, + .SUCCESS => return, + .ACCES => return error.PermissionDenied, + .ROFS => return error.ReadOnlyFileSystem, + .LOOP => return error.SymLinkLoop, + .TXTBSY => return error.FileBusy, + .NOTDIR => return error.FileNotFound, + .NOENT => return error.FileNotFound, + .NAMETOOLONG => return error.NameTooLong, + .INVAL => unreachable, + .FAULT => unreachable, + .IO => return error.InputOutput, + .NOMEM => return error.SystemResources, else => |err| return unexpectedErrno(err), } } @@ -3905,18 +3908,18 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces return faccessatW(dirfd, path_w.span().ptr, mode, flags); } switch (errno(system.faccessat(dirfd, path, mode, flags))) { - 0 => return, - EACCES => return error.PermissionDenied, - EROFS => return error.ReadOnlyFileSystem, - ELOOP => return error.SymLinkLoop, - ETXTBSY => return error.FileBusy, - ENOTDIR => return error.FileNotFound, - ENOENT => return error.FileNotFound, - ENAMETOOLONG => return error.NameTooLong, - EINVAL => unreachable, - EFAULT => unreachable, - EIO => return error.InputOutput, - ENOMEM => return error.SystemResources, + .SUCCESS => return, + .ACCES => return error.PermissionDenied, + .ROFS => return error.ReadOnlyFileSystem, + .LOOP => return error.SymLinkLoop, + .TXTBSY => return error.FileBusy, + .NOTDIR => return error.FileNotFound, + .NOENT => return error.FileNotFound, + .NAMETOOLONG => return error.NameTooLong, + .INVAL => unreachable, + .FAULT => unreachable, + .IO => return error.InputOutput, + .NOMEM => return error.SystemResources, else => |err| return unexpectedErrno(err), } } @@ -3972,11 +3975,11 @@ pub const PipeError = error{ pub fn pipe() PipeError![2]fd_t { var fds: [2]fd_t = undefined; switch (errno(system.pipe(&fds))) { - 0 => return fds, - EINVAL => unreachable, // Invalid parameters to pipe() - EFAULT => unreachable, // Invalid fds pointer - ENFILE => return error.SystemFdQuotaExceeded, - EMFILE => return error.ProcessFdQuotaExceeded, + .SUCCESS => return fds, + .INVAL => unreachable, // Invalid parameters to pipe() + .FAULT => unreachable, // Invalid fds pointer + .NFILE => return error.SystemFdQuotaExceeded, + .MFILE => return error.ProcessFdQuotaExceeded, else => |err| return unexpectedErrno(err), } } @@ -3985,11 +3988,11 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { if (@hasDecl(system, "pipe2")) { var fds: [2]fd_t = undefined; switch (errno(system.pipe2(&fds, flags))) { - 0 => return fds, - EINVAL => unreachable, // Invalid flags - EFAULT => unreachable, // Invalid fds pointer - ENFILE => return error.SystemFdQuotaExceeded, - EMFILE => return error.ProcessFdQuotaExceeded, + .SUCCESS => return fds, + .INVAL => unreachable, // Invalid flags + .FAULT => unreachable, // Invalid fds pointer + .NFILE => return error.SystemFdQuotaExceeded, + .MFILE => return error.ProcessFdQuotaExceeded, else => |err| return unexpectedErrno(err), } } @@ -4008,9 +4011,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { if (flags & O_CLOEXEC != 0) { for (fds) |fd| { switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) { - 0 => {}, - EINVAL => unreachable, // Invalid flags - EBADF => unreachable, // Always a race condition + .SUCCESS => {}, + .INVAL => unreachable, // Invalid flags + .BADF => unreachable, // Always a race condition else => |err| return unexpectedErrno(err), } } @@ -4021,9 +4024,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { if (new_flags != 0) { for (fds) |fd| { switch (errno(system.fcntl(fd, F_SETFL, new_flags))) { - 0 => {}, - EINVAL => unreachable, // Invalid flags - EBADF => unreachable, // Always a race condition + .SUCCESS => {}, + .INVAL => unreachable, // Invalid flags + .BADF => unreachable, // Always a race condition else => |err| return unexpectedErrno(err), } } @@ -4055,11 +4058,11 @@ pub fn sysctl( const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong; switch (errno(system.sysctl(name.ptr, name_len, oldp, oldlenp, newp, newlen))) { - 0 => return, - EFAULT => unreachable, - EPERM => return error.PermissionDenied, - ENOMEM => return error.SystemResources, - ENOENT => return error.UnknownName, + .SUCCESS => return, + .FAULT => unreachable, + .PERM => return error.PermissionDenied, + .NOMEM => return error.SystemResources, + .NOENT => return error.UnknownName, else => |err| return unexpectedErrno(err), } } @@ -4081,19 +4084,19 @@ pub fn sysctlbynameZ( } switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) { - 0 => return, - EFAULT => unreachable, - EPERM => return error.PermissionDenied, - ENOMEM => return error.SystemResources, - ENOENT => return error.UnknownName, + .SUCCESS => return, + .FAULT => unreachable, + .PERM => return error.PermissionDenied, + .NOMEM => return error.SystemResources, + .NOENT => return error.UnknownName, else => |err| return unexpectedErrno(err), } } pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void { switch (errno(system.gettimeofday(tv, tz))) { - 0 => return, - EINVAL => unreachable, + .SUCCESS => return, + .INVAL => unreachable, else => unreachable, } } @@ -4111,12 +4114,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) { var result: u64 = undefined; switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) { - 0 => return, - EBADF => unreachable, // always a race condition - EINVAL => return error.Unseekable, - EOVERFLOW => return error.Unseekable, - ESPIPE => return error.Unseekable, - ENXIO => return error.Unseekable, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -4126,13 +4129,13 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), wasi.WHENCE_SET, &new_offset)) { - wasi.ESUCCESS => return, - wasi.EBADF => unreachable, // always a race condition - wasi.EINVAL => return error.Unseekable, - wasi.EOVERFLOW => return error.Unseekable, - wasi.ESPIPE => return error.Unseekable, - wasi.ENXIO => return error.Unseekable, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -4144,12 +4147,12 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned switch (errno(lseek_sym(fd, ioffset, SEEK_SET))) { - 0 => return, - EBADF => unreachable, // always a race condition - EINVAL => return error.Unseekable, - EOVERFLOW => return error.Unseekable, - ESPIPE => return error.Unseekable, - ENXIO => return error.Unseekable, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -4159,12 +4162,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) { var result: u64 = undefined; switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) { - 0 => return, - EBADF => unreachable, // always a race condition - EINVAL => return error.Unseekable, - EOVERFLOW => return error.Unseekable, - ESPIPE => return error.Unseekable, - ENXIO => return error.Unseekable, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -4174,13 +4177,13 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; switch (wasi.fd_seek(fd, offset, wasi.WHENCE_CUR, &new_offset)) { - wasi.ESUCCESS => return, - wasi.EBADF => unreachable, // always a race condition - wasi.EINVAL => return error.Unseekable, - wasi.EOVERFLOW => return error.Unseekable, - wasi.ESPIPE => return error.Unseekable, - wasi.ENXIO => return error.Unseekable, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -4191,12 +4194,12 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned switch (errno(lseek_sym(fd, ioffset, SEEK_CUR))) { - 0 => return, - EBADF => unreachable, // always a race condition - EINVAL => return error.Unseekable, - EOVERFLOW => return error.Unseekable, - ESPIPE => return error.Unseekable, - ENXIO => return error.Unseekable, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -4206,12 +4209,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) { var result: u64 = undefined; switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) { - 0 => return, - EBADF => unreachable, // always a race condition - EINVAL => return error.Unseekable, - EOVERFLOW => return error.Unseekable, - ESPIPE => return error.Unseekable, - ENXIO => return error.Unseekable, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -4221,13 +4224,13 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; switch (wasi.fd_seek(fd, offset, wasi.WHENCE_END, &new_offset)) { - wasi.ESUCCESS => return, - wasi.EBADF => unreachable, // always a race condition - wasi.EINVAL => return error.Unseekable, - wasi.EOVERFLOW => return error.Unseekable, - wasi.ESPIPE => return error.Unseekable, - wasi.ENXIO => return error.Unseekable, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -4238,12 +4241,12 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned switch (errno(lseek_sym(fd, ioffset, SEEK_END))) { - 0 => return, - EBADF => unreachable, // always a race condition - EINVAL => return error.Unseekable, - EOVERFLOW => return error.Unseekable, - ESPIPE => return error.Unseekable, - ENXIO => return error.Unseekable, + .SUCCESS => return, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -4253,12 +4256,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) { var result: u64 = undefined; switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) { - 0 => return result, - EBADF => unreachable, // always a race condition - EINVAL => return error.Unseekable, - EOVERFLOW => return error.Unseekable, - ESPIPE => return error.Unseekable, - ENXIO => return error.Unseekable, + .SUCCESS => return result, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -4268,13 +4271,13 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; switch (wasi.fd_seek(fd, 0, wasi.WHENCE_CUR, &new_offset)) { - wasi.ESUCCESS => return new_offset, - wasi.EBADF => unreachable, // always a race condition - wasi.EINVAL => return error.Unseekable, - wasi.EOVERFLOW => return error.Unseekable, - wasi.ESPIPE => return error.Unseekable, - wasi.ENXIO => return error.Unseekable, - wasi.ENOTCAPABLE => return error.AccessDenied, + .SUCCESS => return new_offset, + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, + .NOTCAPABLE => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -4285,12 +4288,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { const rc = lseek_sym(fd, 0, SEEK_CUR); switch (errno(rc)) { - 0 => return @bitCast(u64, rc), - EBADF => unreachable, // always a race condition - EINVAL => return error.Unseekable, - EOVERFLOW => return error.Unseekable, - ESPIPE => return error.Unseekable, - ENXIO => return error.Unseekable, + .SUCCESS => return @bitCast(u64, rc), + .BADF => unreachable, // always a race condition + .INVAL => return error.Unseekable, + .OVERFLOW => return error.Unseekable, + .SPIPE => return error.Unseekable, + .NXIO => return error.Unseekable, else => |err| return unexpectedErrno(err), } } @@ -4306,15 +4309,15 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize { while (true) { const rc = system.fcntl(fd, cmd, arg); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EINTR => continue, - EACCES => return error.Locked, - EBADF => unreachable, - EBUSY => return error.FileBusy, - EINVAL => unreachable, // invalid parameters - EPERM => return error.PermissionDenied, - EMFILE => return error.ProcessFdQuotaExceeded, - ENOTDIR => unreachable, // invalid parameter + .SUCCESS => return @intCast(usize, rc), + .INTR => continue, + .ACCES => return error.Locked, + .BADF => unreachable, + .BUSY => return error.FileBusy, + .INVAL => unreachable, // invalid parameters + .PERM => return error.PermissionDenied, + .MFILE => return error.ProcessFdQuotaExceeded, + .NOTDIR => unreachable, // invalid parameter else => |err| return unexpectedErrno(err), } } @@ -4381,12 +4384,12 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void { while (true) { const rc = system.flock(fd, operation); switch (errno(rc)) { - 0 => return, - EBADF => unreachable, - EINTR => continue, - EINVAL => unreachable, // invalid parameters - ENOLCK => return error.SystemResources, - EWOULDBLOCK => return error.WouldBlock, // TODO: integrate with async instead of just returning an error + .SUCCESS => return, + .BADF => unreachable, + .INTR => continue, + .INVAL => unreachable, // invalid parameters + .NOLCK => return error.SystemResources, + .AGAIN => return error.WouldBlock, // TODO: integrate with async instead of just returning an error else => |err| return unexpectedErrno(err), } } @@ -4456,17 +4459,18 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP return getFdPath(fd, out_buffer); } - const result_path = std.c.realpath(pathname, out_buffer) orelse switch (std.c._errno().*) { - EINVAL => unreachable, - EBADF => unreachable, - EFAULT => unreachable, - EACCES => return error.AccessDenied, - ENOENT => return error.FileNotFound, - ENOTSUP => return error.NotSupported, - ENOTDIR => return error.NotDir, - ENAMETOOLONG => return error.NameTooLong, - ELOOP => return error.SymLinkLoop, - EIO => return error.InputOutput, + const result_path = std.c.realpath(pathname, out_buffer) orelse switch (@intToEnum(E, std.c._errno().*)) { + .SUCCESS => unreachable, + .INVAL => unreachable, + .BADF => unreachable, + .FAULT => unreachable, + .ACCES => return error.AccessDenied, + .NOENT => return error.FileNotFound, + .OPNOTSUPP => return error.NotSupported, + .NOTDIR => return error.NotDir, + .NAMETOOLONG => return error.NameTooLong, + .LOOP => return error.SymLinkLoop, + .IO => return error.InputOutput, else => |err| return unexpectedErrno(err), }; return mem.spanZ(result_path); @@ -4528,8 +4532,8 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { // the path to the file descriptor. @memset(out_buffer, 0, MAX_PATH_BYTES); switch (errno(system.fcntl(fd, F_GETPATH, out_buffer))) { - 0 => {}, - EBADF => return error.FileNotFound, + .SUCCESS => {}, + .BADF => return error.FileNotFound, // TODO man pages for fcntl on macOS don't really tell you what // errno values to expect when command is F_GETPATH... else => |err| return unexpectedErrno(err), @@ -4562,13 +4566,13 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void { var rem: timespec = undefined; while (true) { switch (errno(system.nanosleep(&req, &rem))) { - EFAULT => unreachable, - EINVAL => { + .FAULT => unreachable, + .INVAL => { // Sometimes Darwin returns EINVAL for no reason. // We treat it as a spurious wakeup. return; }, - EINTR => { + .INTR => { req = rem; continue; }, @@ -4668,13 +4672,13 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { if (std.Target.current.os.tag == .wasi and !builtin.link_libc) { var ts: timestamp_t = undefined; switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) { - 0 => { + .SUCCESS => { tp.* = .{ .tv_sec = @intCast(i64, ts / std.time.ns_per_s), .tv_nsec = @intCast(isize, ts % std.time.ns_per_s), }; }, - EINVAL => return error.UnsupportedClock, + .INVAL => return error.UnsupportedClock, else => |err| return unexpectedErrno(err), } return; @@ -4698,9 +4702,9 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { } switch (errno(system.clock_gettime(clk_id, tp))) { - 0 => return, - EFAULT => unreachable, - EINVAL => return error.UnsupportedClock, + .SUCCESS => return, + .FAULT => unreachable, + .INVAL => return error.UnsupportedClock, else => |err| return unexpectedErrno(err), } } @@ -4709,20 +4713,20 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void { if (std.Target.current.os.tag == .wasi and !builtin.link_libc) { var ts: timestamp_t = undefined; switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) { - 0 => res.* = .{ + .SUCCESS => res.* = .{ .tv_sec = @intCast(i64, ts / std.time.ns_per_s), .tv_nsec = @intCast(isize, ts % std.time.ns_per_s), }, - EINVAL => return error.UnsupportedClock, + .INVAL => return error.UnsupportedClock, else => |err| return unexpectedErrno(err), } return; } switch (errno(system.clock_getres(clk_id, res))) { - 0 => return, - EFAULT => unreachable, - EINVAL => return error.UnsupportedClock, + .SUCCESS => return, + .FAULT => unreachable, + .INVAL => return error.UnsupportedClock, else => |err| return unexpectedErrno(err), } } @@ -4732,11 +4736,11 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError; pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t { var set: cpu_set_t = undefined; switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) { - 0 => return set, - EFAULT => unreachable, - EINVAL => unreachable, - ESRCH => unreachable, - EPERM => return error.PermissionDenied, + .SUCCESS => return set, + .FAULT => unreachable, + .INVAL => unreachable, + .SRCH => unreachable, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } @@ -4768,13 +4772,9 @@ pub const UnexpectedError = error{ /// Call this when you made a syscall or something that sets errno /// and you get an unexpected error. -pub fn unexpectedErrno(err: anytype) UnexpectedError { - if (@typeInfo(@TypeOf(err)) != .Int) { - @compileError("err is expected to be an integer"); - } - +pub fn unexpectedErrno(err: E) UnexpectedError { if (unexpected_error_tracing) { - std.debug.warn("unexpected errno: {d}\n", .{err}); + std.debug.warn("unexpected errno: {d}\n", .{@enumToInt(err)}); std.debug.dumpCurrentStackTrace(null); } return error.Unexpected; @@ -4790,11 +4790,11 @@ pub const SigaltstackError = error{ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { switch (errno(system.sigaltstack(ss, old_ss))) { - 0 => return, - EFAULT => unreachable, - EINVAL => unreachable, - ENOMEM => return error.SizeTooSmall, - EPERM => return error.PermissionDenied, + .SUCCESS => return, + .FAULT => unreachable, + .INVAL => unreachable, + .NOMEM => return error.SizeTooSmall, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } @@ -4802,9 +4802,9 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { /// Examine and change a signal action. pub fn sigaction(sig: u6, act: ?*const Sigaction, oact: ?*Sigaction) void { switch (errno(system.sigaction(sig, act, oact))) { - 0 => return, - EFAULT => unreachable, - EINVAL => unreachable, + .SUCCESS => return, + .FAULT => unreachable, + .INVAL => unreachable, else => unreachable, } } @@ -4841,25 +4841,25 @@ pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void { const atim = times[0].toTimestamp(); const mtim = times[1].toTimestamp(); switch (wasi.fd_filestat_set_times(fd, atim, mtim, wasi.FILESTAT_SET_ATIM | wasi.FILESTAT_SET_MTIM)) { - wasi.ESUCCESS => return, - wasi.EACCES => return error.AccessDenied, - wasi.EPERM => return error.PermissionDenied, - wasi.EBADF => unreachable, // always a race condition - wasi.EFAULT => unreachable, - wasi.EINVAL => unreachable, - wasi.EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.PermissionDenied, + .BADF => unreachable, // always a race condition + .FAULT => unreachable, + .INVAL => unreachable, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } switch (errno(system.futimens(fd, times))) { - 0 => return, - EACCES => return error.AccessDenied, - EPERM => return error.PermissionDenied, - EBADF => unreachable, // always a race condition - EFAULT => unreachable, - EINVAL => unreachable, - EROFS => return error.ReadOnlyFileSystem, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .PERM => return error.PermissionDenied, + .BADF => unreachable, // always a race condition + .FAULT => unreachable, + .INVAL => unreachable, + .ROFS => return error.ReadOnlyFileSystem, else => |err| return unexpectedErrno(err), } } @@ -4869,10 +4869,10 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError; pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { if (builtin.link_libc) { switch (errno(system.gethostname(name_buffer, name_buffer.len))) { - 0 => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)), - EFAULT => unreachable, - ENAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this - EPERM => return error.PermissionDenied, + .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)), + .FAULT => unreachable, + .NAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } @@ -4889,8 +4889,8 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { pub fn uname() utsname { var uts: utsname = undefined; switch (errno(system.uname(&uts))) { - 0 => return uts, - EFAULT => unreachable, + .SUCCESS => return uts, + .FAULT => unreachable, else => unreachable, } } @@ -5049,33 +5049,33 @@ pub fn sendmsg( } } else { switch (errno(rc)) { - 0 => return @intCast(usize, rc), + .SUCCESS => return @intCast(usize, rc), - EACCES => return error.AccessDenied, - EAGAIN => return error.WouldBlock, - EALREADY => return error.FastOpenAlreadyInProgress, - EBADF => unreachable, // always a race condition - ECONNRESET => return error.ConnectionResetByPeer, - EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set. - EFAULT => unreachable, // An invalid user space address was specified for an argument. - EINTR => continue, - EINVAL => unreachable, // Invalid argument passed. - EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified - EMSGSIZE => return error.MessageTooBig, - ENOBUFS => return error.SystemResources, - ENOMEM => return error.SystemResources, - ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. - EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type. - EPIPE => return error.BrokenPipe, - EAFNOSUPPORT => return error.AddressFamilyNotSupported, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - EHOSTUNREACH => return error.NetworkUnreachable, - ENETUNREACH => return error.NetworkUnreachable, - ENOTCONN => return error.SocketNotConnected, - ENETDOWN => return error.NetworkSubsystemFailed, + .ACCES => return error.AccessDenied, + .AGAIN => return error.WouldBlock, + .ALREADY => return error.FastOpenAlreadyInProgress, + .BADF => unreachable, // always a race condition + .CONNRESET => return error.ConnectionResetByPeer, + .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set. + .FAULT => unreachable, // An invalid user space address was specified for an argument. + .INTR => continue, + .INVAL => unreachable, // Invalid argument passed. + .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified + .MSGSIZE => return error.MessageTooBig, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. + .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type. + .PIPE => return error.BrokenPipe, + .AFNOSUPPORT => return error.AddressFamilyNotSupported, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .HOSTUNREACH => return error.NetworkUnreachable, + .NETUNREACH => return error.NetworkUnreachable, + .NOTCONN => return error.SocketNotConnected, + .NETDOWN => return error.NetworkSubsystemFailed, else => |err| return unexpectedErrno(err), } } @@ -5149,33 +5149,33 @@ pub fn sendto( } } else { switch (errno(rc)) { - 0 => return @intCast(usize, rc), + .SUCCESS => return @intCast(usize, rc), - EACCES => return error.AccessDenied, - EAGAIN => return error.WouldBlock, - EALREADY => return error.FastOpenAlreadyInProgress, - EBADF => unreachable, // always a race condition - ECONNRESET => return error.ConnectionResetByPeer, - EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set. - EFAULT => unreachable, // An invalid user space address was specified for an argument. - EINTR => continue, - EINVAL => unreachable, // Invalid argument passed. - EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified - EMSGSIZE => return error.MessageTooBig, - ENOBUFS => return error.SystemResources, - ENOMEM => return error.SystemResources, - ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. - EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type. - EPIPE => return error.BrokenPipe, - EAFNOSUPPORT => return error.AddressFamilyNotSupported, - ELOOP => return error.SymLinkLoop, - ENAMETOOLONG => return error.NameTooLong, - ENOENT => return error.FileNotFound, - ENOTDIR => return error.NotDir, - EHOSTUNREACH => return error.NetworkUnreachable, - ENETUNREACH => return error.NetworkUnreachable, - ENOTCONN => return error.SocketNotConnected, - ENETDOWN => return error.NetworkSubsystemFailed, + .ACCES => return error.AccessDenied, + .AGAIN => return error.WouldBlock, + .ALREADY => return error.FastOpenAlreadyInProgress, + .BADF => unreachable, // always a race condition + .CONNRESET => return error.ConnectionResetByPeer, + .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set. + .FAULT => unreachable, // An invalid user space address was specified for an argument. + .INTR => continue, + .INVAL => unreachable, // Invalid argument passed. + .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified + .MSGSIZE => return error.MessageTooBig, + .NOBUFS => return error.SystemResources, + .NOMEM => return error.SystemResources, + .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. + .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type. + .PIPE => return error.BrokenPipe, + .AFNOSUPPORT => return error.AddressFamilyNotSupported, + .LOOP => return error.SymLinkLoop, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.NotDir, + .HOSTUNREACH => return error.NetworkUnreachable, + .NETUNREACH => return error.NetworkUnreachable, + .NOTCONN => return error.SocketNotConnected, + .NETDOWN => return error.NetworkSubsystemFailed, else => |err| return unexpectedErrno(err), } } @@ -5312,7 +5312,7 @@ pub fn sendfile( var offset: off_t = @bitCast(off_t, in_offset); const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count); switch (errno(rc)) { - 0 => { + .SUCCESS => { const amt = @bitCast(usize, rc); total_written += amt; if (in_len == 0 and amt == 0) { @@ -5325,12 +5325,12 @@ pub fn sendfile( } }, - EBADF => unreachable, // Always a race condition. - EFAULT => unreachable, // Segmentation fault. - EOVERFLOW => unreachable, // We avoid passing too large of a `count`. - ENOTCONN => unreachable, // `out_fd` is an unconnected socket. + .BADF => unreachable, // Always a race condition. + .FAULT => unreachable, // Segmentation fault. + .OVERFLOW => unreachable, // We avoid passing too large of a `count`. + .NOTCONN => unreachable, // `out_fd` is an unconnected socket. - EINVAL, ENOSYS => { + .INVAL, .NOSYS => { // EINVAL could be any of the following situations: // * Descriptor is not valid or locked // * an mmap(2)-like operation is not available for in_fd @@ -5340,17 +5340,17 @@ pub fn sendfile( // manually, the same as ENOSYS. break :sf; }, - EAGAIN => if (std.event.Loop.instance) |loop| { + .AGAIN => if (std.event.Loop.instance) |loop| { loop.waitUntilFdWritable(out_fd); continue; } else { return error.WouldBlock; }, - EIO => return error.InputOutput, - EPIPE => return error.BrokenPipe, - ENOMEM => return error.SystemResources, - ENXIO => return error.Unseekable, - ESPIPE => return error.Unseekable, + .IO => return error.InputOutput, + .PIPE => return error.BrokenPipe, + .NOMEM => return error.SystemResources, + .NXIO => return error.Unseekable, + .SPIPE => return error.Unseekable, else => |err| { unexpectedErrno(err) catch {}; break :sf; @@ -5392,13 +5392,13 @@ pub fn sendfile( const err = errno(system.sendfile(in_fd, out_fd, offset, adjusted_count, hdtr, &sbytes, flags)); const amt = @bitCast(usize, sbytes); switch (err) { - 0 => return amt, + .SUCCESS => return amt, - EBADF => unreachable, // Always a race condition. - EFAULT => unreachable, // Segmentation fault. - ENOTCONN => unreachable, // `out_fd` is an unconnected socket. + .BADF => unreachable, // Always a race condition. + .FAULT => unreachable, // Segmentation fault. + .NOTCONN => unreachable, // `out_fd` is an unconnected socket. - EINVAL, EOPNOTSUPP, ENOTSOCK, ENOSYS => { + .INVAL, .OPNOTSUPP, .NOTSOCK, .NOSYS => { // EINVAL could be any of the following situations: // * The fd argument is not a regular file. // * The s argument is not a SOCK_STREAM type socket. @@ -5408,9 +5408,9 @@ pub fn sendfile( break :sf; }, - EINTR => if (amt != 0) return amt else continue, + .INTR => if (amt != 0) return amt else continue, - EAGAIN => if (amt != 0) { + .AGAIN => if (amt != 0) { return amt; } else if (std.event.Loop.instance) |loop| { loop.waitUntilFdWritable(out_fd); @@ -5419,7 +5419,7 @@ pub fn sendfile( return error.WouldBlock; }, - EBUSY => if (amt != 0) { + .BUSY => if (amt != 0) { return amt; } else if (std.event.Loop.instance) |loop| { loop.waitUntilFdReadable(in_fd); @@ -5428,9 +5428,9 @@ pub fn sendfile( return error.WouldBlock; }, - EIO => return error.InputOutput, - ENOBUFS => return error.SystemResources, - EPIPE => return error.BrokenPipe, + .IO => return error.InputOutput, + .NOBUFS => return error.SystemResources, + .PIPE => return error.BrokenPipe, else => { unexpectedErrno(err) catch {}; @@ -5471,18 +5471,18 @@ pub fn sendfile( const err = errno(system.sendfile(in_fd, out_fd, signed_offset, &sbytes, hdtr, flags)); const amt = @bitCast(usize, sbytes); switch (err) { - 0 => return amt, + .SUCCESS => return amt, - EBADF => unreachable, // Always a race condition. - EFAULT => unreachable, // Segmentation fault. - EINVAL => unreachable, - ENOTCONN => unreachable, // `out_fd` is an unconnected socket. + .BADF => unreachable, // Always a race condition. + .FAULT => unreachable, // Segmentation fault. + .INVAL => unreachable, + .NOTCONN => unreachable, // `out_fd` is an unconnected socket. - ENOTSUP, ENOTSOCK, ENOSYS => break :sf, + .OPNOTSUPP, .NOTSOCK, .NOSYS => break :sf, - EINTR => if (amt != 0) return amt else continue, + .INTR => if (amt != 0) return amt else continue, - EAGAIN => if (amt != 0) { + .AGAIN => if (amt != 0) { return amt; } else if (std.event.Loop.instance) |loop| { loop.waitUntilFdWritable(out_fd); @@ -5491,8 +5491,8 @@ pub fn sendfile( return error.WouldBlock; }, - EIO => return error.InputOutput, - EPIPE => return error.BrokenPipe, + .IO => return error.InputOutput, + .PIPE => return error.BrokenPipe, else => { 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 const rc = system.copy_file_range(fd_in, &off_in_copy, fd_out, &off_out_copy, len, flags); switch (system.getErrno(rc)) { - 0 => return @intCast(usize, rc), - EBADF => return error.FilesOpenedWithWrongFlags, - EFBIG => return error.FileTooBig, - EIO => return error.InputOutput, - EISDIR => return error.IsDir, - ENOMEM => return error.OutOfMemory, - ENOSPC => return error.NoSpaceLeft, - EOVERFLOW => return error.Unseekable, - EPERM => return error.PermissionDenied, - ETXTBSY => return error.FileBusy, + .SUCCESS => return @intCast(usize, rc), + .BADF => return error.FilesOpenedWithWrongFlags, + .FBIG => return error.FileTooBig, + .IO => return error.InputOutput, + .ISDIR => return error.IsDir, + .NOMEM => return error.OutOfMemory, + .NOSPC => return error.NoSpaceLeft, + .OVERFLOW => return error.Unseekable, + .PERM => return error.PermissionDenied, + .TXTBSY => return error.FileBusy, // these may not be regular files, try fallback - EINVAL => {}, + .INVAL => {}, // support for cross-filesystem copy added in Linux 5.3, use fallback - EXDEV => {}, + .XDEV => {}, // syscall added in Linux 4.5, use fallback - ENOSYS => { + .NOSYS => { has_copy_file_range_syscall.store(false, .Monotonic); }, else => |err| return unexpectedErrno(err), @@ -5652,11 +5652,11 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize { } } else { switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EFAULT => unreachable, - EINTR => continue, - EINVAL => unreachable, - ENOMEM => return error.SystemResources, + .SUCCESS => return @intCast(usize, rc), + .FAULT => unreachable, + .INTR => continue, + .INVAL => unreachable, + .NOMEM => return error.SystemResources, else => |err| return unexpectedErrno(err), } } @@ -5681,11 +5681,11 @@ pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) P } const rc = system.ppoll(fds.ptr, fds.len, ts_ptr, mask); switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EFAULT => unreachable, - EINTR => return error.SignalInterrupt, - EINVAL => unreachable, - ENOMEM => return error.SystemResources, + .SUCCESS => return @intCast(usize, rc), + .FAULT => unreachable, + .INTR => return error.SignalInterrupt, + .INVAL => unreachable, + .NOMEM => return error.SystemResources, else => |err| return unexpectedErrno(err), } } @@ -5750,17 +5750,17 @@ pub fn recvfrom( } } else { switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EBADF => unreachable, // always a race condition - EFAULT => unreachable, - EINVAL => unreachable, - ENOTCONN => unreachable, - ENOTSOCK => unreachable, - EINTR => continue, - EAGAIN => return error.WouldBlock, - ENOMEM => return error.SystemResources, - ECONNREFUSED => return error.ConnectionRefused, - ECONNRESET => return error.ConnectionResetByPeer, + .SUCCESS => return @intCast(usize, rc), + .BADF => unreachable, // always a race condition + .FAULT => unreachable, + .INVAL => unreachable, + .NOTCONN => unreachable, + .NOTSOCK => unreachable, + .INTR => continue, + .AGAIN => return error.WouldBlock, + .NOMEM => return error.SystemResources, + .CONNREFUSED => return error.ConnectionRefused, + .CONNRESET => return error.ConnectionResetByPeer, else => |err| return unexpectedErrno(err), } } @@ -5830,8 +5830,8 @@ pub fn sched_yield() SchedYieldError!void { return; } switch (errno(system.sched_yield())) { - 0 => return, - ENOSYS => return error.SystemCannotYield, + .SUCCESS => return, + .NOSYS => return error.SystemCannotYield, else => return error.SystemCannotYield, } } @@ -5874,17 +5874,17 @@ pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSo return; } else { switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) { - 0 => {}, - EBADF => unreachable, // always a race condition - ENOTSOCK => unreachable, // always a race condition - EINVAL => unreachable, - EFAULT => unreachable, - EDOM => return error.TimeoutTooBig, - EISCONN => return error.AlreadyConnected, - ENOPROTOOPT => return error.InvalidProtocolOption, - ENOMEM => return error.SystemResources, - ENOBUFS => return error.SystemResources, - EPERM => return error.PermissionDenied, + .SUCCESS => {}, + .BADF => unreachable, // always a race condition + .NOTSOCK => unreachable, // always a race condition + .INVAL => unreachable, + .FAULT => unreachable, + .DOM => return error.TimeoutTooBig, + .ISCONN => return error.AlreadyConnected, + .NOPROTOOPT => return error.InvalidProtocolOption, + .NOMEM => return error.SystemResources, + .NOBUFS => return error.SystemResources, + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } @@ -5909,13 +5909,13 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t { const getErrno = if (use_c) std.c.getErrno else linux.getErrno; const rc = sys.memfd_create(name, flags); switch (getErrno(rc)) { - 0 => return @intCast(fd_t, rc), - EFAULT => unreachable, // name has invalid memory - EINVAL => unreachable, // name/flags are faulty - ENFILE => return error.SystemFdQuotaExceeded, - EMFILE => return error.ProcessFdQuotaExceeded, - ENOMEM => return error.OutOfMemory, - ENOSYS => return error.SystemOutdated, + .SUCCESS => return @intCast(fd_t, rc), + .FAULT => unreachable, // name has invalid memory + .INVAL => unreachable, // name/flags are faulty + .NFILE => return error.SystemFdQuotaExceeded, + .MFILE => return error.ProcessFdQuotaExceeded, + .NOMEM => return error.OutOfMemory, + .NOSYS => return error.SystemOutdated, else => |err| return unexpectedErrno(err), } } @@ -5940,9 +5940,9 @@ pub fn getrusage(who: i32) rusage { var result: rusage = undefined; const rc = system.getrusage(who, &result); switch (errno(rc)) { - 0 => return result, - EINVAL => unreachable, - EFAULT => unreachable, + .SUCCESS => return result, + .INVAL => unreachable, + .FAULT => unreachable, else => unreachable, } } @@ -5953,10 +5953,10 @@ pub fn tcgetattr(handle: fd_t) TermiosGetError!termios { while (true) { var term: termios = undefined; switch (errno(system.tcgetattr(handle, &term))) { - 0 => return term, - EINTR => continue, - EBADF => unreachable, - ENOTTY => return error.NotATerminal, + .SUCCESS => return term, + .INTR => continue, + .BADF => unreachable, + .NOTTY => return error.NotATerminal, else => |err| return unexpectedErrno(err), } } @@ -5967,12 +5967,12 @@ pub const TermiosSetError = TermiosGetError || error{ProcessOrphaned}; pub fn tcsetattr(handle: fd_t, optional_action: TCSA, termios_p: termios) TermiosSetError!void { while (true) { switch (errno(system.tcsetattr(handle, optional_action, &termios_p))) { - 0 => return, - EBADF => unreachable, - EINTR => continue, - EINVAL => unreachable, - ENOTTY => return error.NotATerminal, - EIO => return error.ProcessOrphaned, + .SUCCESS => return, + .BADF => unreachable, + .INTR => continue, + .INVAL => unreachable, + .NOTTY => return error.NotATerminal, + .IO => return error.ProcessOrphaned, else => |err| return unexpectedErrno(err), } } @@ -5986,15 +5986,15 @@ pub const IoCtl_SIOCGIFINDEX_Error = error{ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void { while (true) { switch (errno(system.ioctl(fd, SIOCGIFINDEX, @ptrToInt(ifr)))) { - 0 => return, - EINVAL => unreachable, // Bad parameters. - ENOTTY => unreachable, - ENXIO => unreachable, - EBADF => unreachable, // Always a race condition. - EFAULT => unreachable, // Bad pointer parameter. - EINTR => continue, - EIO => return error.FileSystem, - ENODEV => return error.InterfaceNotFound, + .SUCCESS => return, + .INVAL => unreachable, // Bad parameters. + .NOTTY => unreachable, + .NXIO => unreachable, + .BADF => unreachable, // Always a race condition. + .FAULT => unreachable, // Bad pointer parameter. + .INTR => continue, + .IO => return error.FileSystem, + .NODEV => return error.InterfaceNotFound, else => |err| return unexpectedErrno(err), } } @@ -6003,13 +6003,13 @@ pub fn ioctl_SIOCGIFINDEX(fd: fd_t, ifr: *ifreq) IoCtl_SIOCGIFINDEX_Error!void { pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t { const rc = system.signalfd(fd, mask, flags); switch (errno(rc)) { - 0 => return @intCast(fd_t, rc), - EBADF, EINVAL => unreachable, - ENFILE => return error.SystemFdQuotaExceeded, - ENOMEM => return error.SystemResources, - EMFILE => return error.ProcessResources, - ENODEV => return error.InodeMountFail, - ENOSYS => return error.SystemOutdated, + .SUCCESS => return @intCast(fd_t, rc), + .BADF, .INVAL => unreachable, + .NFILE => return error.SystemFdQuotaExceeded, + .NOMEM => return error.SystemResources, + .MFILE => return error.ProcessResources, + .NODEV => return error.InodeMountFail, + .NOSYS => return error.SystemOutdated, else => |err| return unexpectedErrno(err), } } @@ -6030,11 +6030,11 @@ pub fn sync() void { pub fn syncfs(fd: fd_t) SyncError!void { const rc = system.syncfs(fd); switch (errno(rc)) { - 0 => return, - EBADF, EINVAL, EROFS => unreachable, - EIO => return error.InputOutput, - ENOSPC => return error.NoSpaceLeft, - EDQUOT => return error.DiskQuota, + .SUCCESS => return, + .BADF, .INVAL, .ROFS => unreachable, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .DQUOT => return error.DiskQuota, else => |err| return unexpectedErrno(err), } } @@ -6054,11 +6054,11 @@ pub fn fsync(fd: fd_t) SyncError!void { } const rc = system.fsync(fd); switch (errno(rc)) { - 0 => return, - EBADF, EINVAL, EROFS => unreachable, - EIO => return error.InputOutput, - ENOSPC => return error.NoSpaceLeft, - EDQUOT => return error.DiskQuota, + .SUCCESS => return, + .BADF, .INVAL, .ROFS => unreachable, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .DQUOT => return error.DiskQuota, else => |err| return unexpectedErrno(err), } } @@ -6073,11 +6073,11 @@ pub fn fdatasync(fd: fd_t) SyncError!void { } const rc = system.fdatasync(fd); switch (errno(rc)) { - 0 => return, - EBADF, EINVAL, EROFS => unreachable, - EIO => return error.InputOutput, - ENOSPC => return error.NoSpaceLeft, - EDQUOT => return error.DiskQuota, + .SUCCESS => return, + .BADF, .INVAL, .ROFS => unreachable, + .IO => return error.InputOutput, + .NOSPC => return error.NoSpaceLeft, + .DQUOT => return error.DiskQuota, else => |err| return unexpectedErrno(err), } } @@ -6111,15 +6111,15 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 { const rc = system.prctl(@enumToInt(option), buf[0], buf[1], buf[2], buf[3]); switch (errno(rc)) { - 0 => return @intCast(u31, rc), - EACCES => return error.AccessDenied, - EBADF => return error.InvalidFileDescriptor, - EFAULT => return error.InvalidAddress, - EINVAL => unreachable, - ENODEV, ENXIO => return error.UnsupportedFeature, - EOPNOTSUPP => return error.OperationNotSupported, - EPERM, EBUSY => return error.PermissionDenied, - ERANGE => unreachable, + .SUCCESS => return @intCast(u31, rc), + .ACCES => return error.AccessDenied, + .BADF => return error.InvalidFileDescriptor, + .FAULT => return error.InvalidAddress, + .INVAL => unreachable, + .NODEV, .NXIO => return error.UnsupportedFeature, + .OPNOTSUPP => return error.OperationNotSupported, + .PERM, .BUSY => return error.PermissionDenied, + .RANGE => unreachable, else => |err| return unexpectedErrno(err), } } @@ -6134,9 +6134,9 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { var limits: rlimit = undefined; switch (errno(getrlimit_sym(resource, &limits))) { - 0 => return limits, - EFAULT => unreachable, // bogus pointer - EINVAL => unreachable, + .SUCCESS => return limits, + .FAULT => unreachable, // bogus pointer + .INVAL => unreachable, else => |err| return unexpectedErrno(err), } } @@ -6150,10 +6150,10 @@ pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void system.setrlimit; switch (errno(setrlimit_sym(resource, &limits))) { - 0 => return, - EFAULT => unreachable, // bogus pointer - EINVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable - EPERM => return error.PermissionDenied, + .SUCCESS => return, + .FAULT => unreachable, // bogus pointer + .INVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable + .PERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } } @@ -6194,14 +6194,14 @@ pub const MadviseError = error{ /// This syscall is optional and is sometimes configured to be disabled. pub fn madvise(ptr: [*]align(mem.page_size) u8, length: usize, advice: u32) MadviseError!void { switch (errno(system.madvise(ptr, length, advice))) { - 0 => return, - EACCES => return error.AccessDenied, - EAGAIN => return error.SystemResources, - EBADF => unreachable, // The map exists, but the area maps something that isn't a file. - EINVAL => return error.InvalidSyscall, - EIO => return error.WouldExceedMaximumResidentSetSize, - ENOMEM => return error.OutOfMemory, - ENOSYS => return error.MadviseUnavailable, + .SUCCESS => return, + .ACCES => return error.AccessDenied, + .AGAIN => return error.SystemResources, + .BADF => unreachable, // The map exists, but the area maps something that isn't a file. + .INVAL => return error.InvalidSyscall, + .IO => return error.WouldExceedMaximumResidentSetSize, + .NOMEM => return error.OutOfMemory, + .NOSYS => return error.MadviseUnavailable, else => |err| return unexpectedErrno(err), } } diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig index f39b5948d7..35d507541e 100644 --- a/lib/std/os/bits/darwin.zig +++ b/lib/std/os/bits/darwin.zig @@ -866,337 +866,342 @@ pub fn WIFSIGNALED(x: u32) bool { return wstatus(x) != wstopped and wstatus(x) != 0; } -/// Operation not permitted -pub const EPERM = 1; +pub const E = enum(u16) { + /// No error occurred. + SUCCESS = 0, -/// No such file or directory -pub const ENOENT = 2; + /// Operation not permitted + PERM = 1, -/// No such process -pub const ESRCH = 3; + /// No such file or directory + NOENT = 2, -/// Interrupted system call -pub const EINTR = 4; + /// No such process + SRCH = 3, -/// Input/output error -pub const EIO = 5; + /// Interrupted system call + INTR = 4, -/// Device not configured -pub const ENXIO = 6; + /// Input/output error + IO = 5, -/// Argument list too long -pub const E2BIG = 7; + /// Device not configured + NXIO = 6, -/// Exec format error -pub const ENOEXEC = 8; + /// Argument list too long + @"2BIG" = 7, -/// Bad file descriptor -pub const EBADF = 9; + /// Exec format error + NOEXEC = 8, -/// No child processes -pub const ECHILD = 10; + /// Bad file descriptor + BADF = 9, -/// Resource deadlock avoided -pub const EDEADLK = 11; + /// No child processes + CHILD = 10, -/// Cannot allocate memory -pub const ENOMEM = 12; + /// Resource deadlock avoided + DEADLK = 11, -/// Permission denied -pub const EACCES = 13; + /// Cannot allocate memory + NOMEM = 12, -/// Bad address -pub const EFAULT = 14; + /// Permission denied + ACCES = 13, -/// Block device required -pub const ENOTBLK = 15; + /// Bad address + FAULT = 14, -/// Device / Resource busy -pub const EBUSY = 16; + /// Block device required + NOTBLK = 15, -/// File exists -pub const EEXIST = 17; + /// Device / Resource busy + BUSY = 16, -/// Cross-device link -pub const EXDEV = 18; + /// File exists + EXIST = 17, -/// Operation not supported by device -pub const ENODEV = 19; + /// Cross-device link + XDEV = 18, -/// Not a directory -pub const ENOTDIR = 20; + /// Operation not supported by device + NODEV = 19, -/// Is a directory -pub const EISDIR = 21; + /// Not a directory + NOTDIR = 20, -/// Invalid argument -pub const EINVAL = 22; + /// Is a directory + ISDIR = 21, -/// Too many open files in system -pub const ENFILE = 23; + /// Invalid argument + INVAL = 22, -/// Too many open files -pub const EMFILE = 24; + /// Too many open files in system + NFILE = 23, -/// Inappropriate ioctl for device -pub const ENOTTY = 25; + /// Too many open files + MFILE = 24, -/// Text file busy -pub const ETXTBSY = 26; + /// Inappropriate ioctl for device + NOTTY = 25, -/// File too large -pub const EFBIG = 27; + /// Text file busy + TXTBSY = 26, -/// No space left on device -pub const ENOSPC = 28; + /// File too large + FBIG = 27, -/// Illegal seek -pub const ESPIPE = 29; + /// No space left on device + NOSPC = 28, -/// Read-only file system -pub const EROFS = 30; + /// Illegal seek + SPIPE = 29, -/// Too many links -pub const EMLINK = 31; -/// Broken pipe + /// Read-only file system + ROFS = 30, -// math software -pub const EPIPE = 32; + /// Too many links + MLINK = 31, -/// Numerical argument out of domain -pub const EDOM = 33; -/// Result too large + /// Broken pipe + PIPE = 32, -// non-blocking and interrupt i/o -pub const ERANGE = 34; + // math software -/// Resource temporarily unavailable -pub const EAGAIN = 35; + /// Numerical argument out of domain + DOM = 33, -/// Operation would block -pub const EWOULDBLOCK = EAGAIN; + /// Result too large + RANGE = 34, -/// Operation now in progress -pub const EINPROGRESS = 36; -/// Operation already in progress + // non-blocking and interrupt i/o -// ipc/network software -- argument errors -pub const EALREADY = 37; + /// Resource temporarily unavailable + /// This is the same code used for `WOULDBLOCK`. + AGAIN = 35, -/// Socket operation on non-socket -pub const ENOTSOCK = 38; + /// Operation now in progress + INPROGRESS = 36, -/// Destination address required -pub const EDESTADDRREQ = 39; + /// Operation already in progress + ALREADY = 37, -/// Message too long -pub const EMSGSIZE = 40; + // ipc/network software -- argument errors -/// Protocol wrong type for socket -pub const EPROTOTYPE = 41; + /// Socket operation on non-socket + NOTSOCK = 38, -/// Protocol not available -pub const ENOPROTOOPT = 42; + /// Destination address required + DESTADDRREQ = 39, -/// Protocol not supported -pub const EPROTONOSUPPORT = 43; + /// Message too long + MSGSIZE = 40, -/// Socket type not supported -pub const ESOCKTNOSUPPORT = 44; + /// Protocol wrong type for socket + PROTOTYPE = 41, -/// Operation not supported -pub const ENOTSUP = 45; + /// Protocol not available + NOPROTOOPT = 42, -/// Operation not supported. Alias of `ENOTSUP`. -pub const EOPNOTSUPP = ENOTSUP; + /// Protocol not supported + PROTONOSUPPORT = 43, -/// Protocol family not supported -pub const EPFNOSUPPORT = 46; + /// Socket type not supported + SOCKTNOSUPPORT = 44, -/// Address family not supported by protocol family -pub const EAFNOSUPPORT = 47; + /// Operation not supported + /// The same code is used for `NOTSUP`. + OPNOTSUPP = 45, -/// Address already in use -pub const EADDRINUSE = 48; -/// Can't assign requested address + /// Protocol family not supported + PFNOSUPPORT = 46, -// ipc/network software -- operational errors -pub const EADDRNOTAVAIL = 49; + /// Address family not supported by protocol family + AFNOSUPPORT = 47, -/// Network is down -pub const ENETDOWN = 50; + /// Address already in use + ADDRINUSE = 48, + /// Can't assign requested address -/// Network is unreachable -pub const ENETUNREACH = 51; + // ipc/network software -- operational errors + ADDRNOTAVAIL = 49, -/// Network dropped connection on reset -pub const ENETRESET = 52; + /// Network is down + NETDOWN = 50, -/// Software caused connection abort -pub const ECONNABORTED = 53; + /// Network is unreachable + NETUNREACH = 51, -/// Connection reset by peer -pub const ECONNRESET = 54; + /// Network dropped connection on reset + NETRESET = 52, -/// No buffer space available -pub const ENOBUFS = 55; + /// Software caused connection abort + CONNABORTED = 53, -/// Socket is already connected -pub const EISCONN = 56; + /// Connection reset by peer + CONNRESET = 54, -/// Socket is not connected -pub const ENOTCONN = 57; + /// No buffer space available + NOBUFS = 55, -/// Can't send after socket shutdown -pub const ESHUTDOWN = 58; + /// Socket is already connected + ISCONN = 56, -/// Too many references: can't splice -pub const ETOOMANYREFS = 59; + /// Socket is not connected + NOTCONN = 57, -/// Operation timed out -pub const ETIMEDOUT = 60; + /// Can't send after socket shutdown + SHUTDOWN = 58, -/// Connection refused -pub const ECONNREFUSED = 61; + /// Too many references: can't splice + TOOMANYREFS = 59, -/// Too many levels of symbolic links -pub const ELOOP = 62; + /// Operation timed out + TIMEDOUT = 60, -/// File name too long -pub const ENAMETOOLONG = 63; + /// Connection refused + CONNREFUSED = 61, -/// Host is down -pub const EHOSTDOWN = 64; + /// Too many levels of symbolic links + LOOP = 62, -/// No route to host -pub const EHOSTUNREACH = 65; -/// Directory not empty + /// File name too long + NAMETOOLONG = 63, -// quotas & mush -pub const ENOTEMPTY = 66; + /// Host is down + HOSTDOWN = 64, -/// Too many processes -pub const EPROCLIM = 67; + /// No route to host + HOSTUNREACH = 65, + /// Directory not empty -/// Too many users -pub const EUSERS = 68; -/// Disc quota exceeded + // quotas & mush + NOTEMPTY = 66, -// Network File System -pub const EDQUOT = 69; + /// Too many processes + PROCLIM = 67, -/// Stale NFS file handle -pub const ESTALE = 70; + /// Too many users + USERS = 68, + /// Disc quota exceeded -/// Too many levels of remote in path -pub const EREMOTE = 71; + // Network File System + DQUOT = 69, -/// RPC struct is bad -pub const EBADRPC = 72; + /// Stale NFS file handle + STALE = 70, -/// RPC version wrong -pub const ERPCMISMATCH = 73; + /// Too many levels of remote in path + REMOTE = 71, -/// RPC prog. not avail -pub const EPROGUNAVAIL = 74; + /// RPC struct is bad + BADRPC = 72, -/// Program version wrong -pub const EPROGMISMATCH = 75; + /// RPC version wrong + RPCMISMATCH = 73, -/// Bad procedure for program -pub const EPROCUNAVAIL = 76; + /// RPC prog. not avail + PROGUNAVAIL = 74, -/// No locks available -pub const ENOLCK = 77; + /// Program version wrong + PROGMISMATCH = 75, -/// Function not implemented -pub const ENOSYS = 78; + /// Bad procedure for program + PROCUNAVAIL = 76, -/// Inappropriate file type or format -pub const EFTYPE = 79; + /// No locks available + NOLCK = 77, -/// Authentication error -pub const EAUTH = 80; -/// Need authenticator + /// Function not implemented + NOSYS = 78, -// Intelligent device errors -pub const ENEEDAUTH = 81; + /// Inappropriate file type or format + FTYPE = 79, -/// Device power is off -pub const EPWROFF = 82; + /// Authentication error + AUTH = 80, -/// Device error, e.g. paper out -pub const EDEVERR = 83; -/// Value too large to be stored in data type + /// Need authenticator + NEEDAUTH = 81, -// Program loading errors -pub const EOVERFLOW = 84; + // Intelligent device errors -/// Bad executable -pub const EBADEXEC = 85; + /// Device power is off + PWROFF = 82, -/// Bad CPU type in executable -pub const EBADARCH = 86; + /// Device error, e.g. paper out + DEVERR = 83, -/// Shared library version mismatch -pub const ESHLIBVERS = 87; + /// Value too large to be stored in data type + OVERFLOW = 84, -/// Malformed Macho file -pub const EBADMACHO = 88; + // Program loading errors -/// Operation canceled -pub const ECANCELED = 89; + /// Bad executable + BADEXEC = 85, -/// Identifier removed -pub const EIDRM = 90; + /// Bad CPU type in executable + BADARCH = 86, -/// No message of desired type -pub const ENOMSG = 91; + /// Shared library version mismatch + SHLIBVERS = 87, -/// Illegal byte sequence -pub const EILSEQ = 92; + /// Malformed Macho file + BADMACHO = 88, -/// Attribute not found -pub const ENOATTR = 93; + /// Operation canceled + CANCELED = 89, -/// Bad message -pub const EBADMSG = 94; + /// Identifier removed + IDRM = 90, -/// Reserved -pub const EMULTIHOP = 95; + /// No message of desired type + NOMSG = 91, -/// No message available on STREAM -pub const ENODATA = 96; + /// Illegal byte sequence + ILSEQ = 92, -/// Reserved -pub const ENOLINK = 97; + /// Attribute not found + NOATTR = 93, -/// No STREAM resources -pub const ENOSR = 98; + /// Bad message + BADMSG = 94, -/// Not a STREAM -pub const ENOSTR = 99; + /// Reserved + MULTIHOP = 95, -/// Protocol error -pub const EPROTO = 100; + /// No message available on STREAM + NODATA = 96, -/// STREAM ioctl timeout -pub const ETIME = 101; + /// Reserved + NOLINK = 97, -/// No such policy registered -pub const ENOPOLICY = 103; + /// No STREAM resources + NOSR = 98, -/// State not recoverable -pub const ENOTRECOVERABLE = 104; + /// Not a STREAM + NOSTR = 99, -/// Previous owner died -pub const EOWNERDEAD = 105; + /// Protocol error + PROTO = 100, -/// Interface output queue is full -pub const EQFULL = 106; + /// STREAM ioctl timeout + TIME = 101, -/// Must be equal largest errno -pub const ELAST = 106; + /// No such policy registered + NOPOLICY = 103, + + /// State not recoverable + NOTRECOVERABLE = 104, + + /// Previous owner died + OWNERDEAD = 105, + + /// Interface output queue is full + QFULL = 106, + + _, +}; pub const SIGSTKSZ = 131072; pub const MINSIGSTKSZ = 32768; diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index dfa54972f3..cf647a8438 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -25,103 +25,108 @@ pub const gid_t = u32; pub const time_t = isize; pub const suseconds_t = c_long; -pub const ENOTSUP = EOPNOTSUPP; -pub const EWOULDBLOCK = EAGAIN; -pub const EPERM = 1; -pub const ENOENT = 2; -pub const ESRCH = 3; -pub const EINTR = 4; -pub const EIO = 5; -pub const ENXIO = 6; -pub const E2BIG = 7; -pub const ENOEXEC = 8; -pub const EBADF = 9; -pub const ECHILD = 10; -pub const EDEADLK = 11; -pub const ENOMEM = 12; -pub const EACCES = 13; -pub const EFAULT = 14; -pub const ENOTBLK = 15; -pub const EBUSY = 16; -pub const EEXIST = 17; -pub const EXDEV = 18; -pub const ENODEV = 19; -pub const ENOTDIR = 20; -pub const EISDIR = 21; -pub const EINVAL = 22; -pub const ENFILE = 23; -pub const EMFILE = 24; -pub const ENOTTY = 25; -pub const ETXTBSY = 26; -pub const EFBIG = 27; -pub const ENOSPC = 28; -pub const ESPIPE = 29; -pub const EROFS = 30; -pub const EMLINK = 31; -pub const EPIPE = 32; -pub const EDOM = 33; -pub const ERANGE = 34; -pub const EAGAIN = 35; -pub const EINPROGRESS = 36; -pub const EALREADY = 37; -pub const ENOTSOCK = 38; -pub const EDESTADDRREQ = 39; -pub const EMSGSIZE = 40; -pub const EPROTOTYPE = 41; -pub const ENOPROTOOPT = 42; -pub const EPROTONOSUPPORT = 43; -pub const ESOCKTNOSUPPORT = 44; -pub const EOPNOTSUPP = 45; -pub const EPFNOSUPPORT = 46; -pub const EAFNOSUPPORT = 47; -pub const EADDRINUSE = 48; -pub const EADDRNOTAVAIL = 49; -pub const ENETDOWN = 50; -pub const ENETUNREACH = 51; -pub const ENETRESET = 52; -pub const ECONNABORTED = 53; -pub const ECONNRESET = 54; -pub const ENOBUFS = 55; -pub const EISCONN = 56; -pub const ENOTCONN = 57; -pub const ESHUTDOWN = 58; -pub const ETOOMANYREFS = 59; -pub const ETIMEDOUT = 60; -pub const ECONNREFUSED = 61; -pub const ELOOP = 62; -pub const ENAMETOOLONG = 63; -pub const EHOSTDOWN = 64; -pub const EHOSTUNREACH = 65; -pub const ENOTEMPTY = 66; -pub const EPROCLIM = 67; -pub const EUSERS = 68; -pub const EDQUOT = 69; -pub const ESTALE = 70; -pub const EREMOTE = 71; -pub const EBADRPC = 72; -pub const ERPCMISMATCH = 73; -pub const EPROGUNAVAIL = 74; -pub const EPROGMISMATCH = 75; -pub const EPROCUNAVAIL = 76; -pub const ENOLCK = 77; -pub const ENOSYS = 78; -pub const EFTYPE = 79; -pub const EAUTH = 80; -pub const ENEEDAUTH = 81; -pub const EIDRM = 82; -pub const ENOMSG = 83; -pub const EOVERFLOW = 84; -pub const ECANCELED = 85; -pub const EILSEQ = 86; -pub const ENOATTR = 87; -pub const EDOOFUS = 88; -pub const EBADMSG = 89; -pub const EMULTIHOP = 90; -pub const ENOLINK = 91; -pub const EPROTO = 92; -pub const ENOMEDIUM = 93; -pub const ELAST = 99; -pub const EASYNC = 99; +pub const E = enum(u16) { + /// No error occurred. + SUCCESS = 0, + + PERM = 1, + NOENT = 2, + SRCH = 3, + INTR = 4, + IO = 5, + NXIO = 6, + @"2BIG" = 7, + NOEXEC = 8, + BADF = 9, + CHILD = 10, + DEADLK = 11, + NOMEM = 12, + ACCES = 13, + FAULT = 14, + NOTBLK = 15, + BUSY = 16, + EXIST = 17, + XDEV = 18, + NODEV = 19, + NOTDIR = 20, + ISDIR = 21, + INVAL = 22, + NFILE = 23, + MFILE = 24, + NOTTY = 25, + TXTBSY = 26, + FBIG = 27, + NOSPC = 28, + SPIPE = 29, + ROFS = 30, + MLINK = 31, + PIPE = 32, + DOM = 33, + RANGE = 34, + /// This code is also used for `WOULDBLOCK`. + AGAIN = 35, + INPROGRESS = 36, + ALREADY = 37, + NOTSOCK = 38, + DESTADDRREQ = 39, + MSGSIZE = 40, + PROTOTYPE = 41, + NOPROTOOPT = 42, + PROTONOSUPPORT = 43, + SOCKTNOSUPPORT = 44, + /// This code is also used for `NOTSUP`. + OPNOTSUPP = 45, + PFNOSUPPORT = 46, + AFNOSUPPORT = 47, + ADDRINUSE = 48, + ADDRNOTAVAIL = 49, + NETDOWN = 50, + NETUNREACH = 51, + NETRESET = 52, + CONNABORTED = 53, + CONNRESET = 54, + NOBUFS = 55, + ISCONN = 56, + NOTCONN = 57, + SHUTDOWN = 58, + TOOMANYREFS = 59, + TIMEDOUT = 60, + CONNREFUSED = 61, + LOOP = 62, + NAMETOOLONG = 63, + HOSTDOWN = 64, + HOSTUNREACH = 65, + NOTEMPTY = 66, + PROCLIM = 67, + USERS = 68, + DQUOT = 69, + STALE = 70, + REMOTE = 71, + BADRPC = 72, + RPCMISMATCH = 73, + PROGUNAVAIL = 74, + PROGMISMATCH = 75, + PROCUNAVAIL = 76, + NOLCK = 77, + NOSYS = 78, + FTYPE = 79, + AUTH = 80, + NEEDAUTH = 81, + IDRM = 82, + NOMSG = 83, + OVERFLOW = 84, + CANCELED = 85, + ILSEQ = 86, + NOATTR = 87, + DOOFUS = 88, + BADMSG = 89, + MULTIHOP = 90, + NOLINK = 91, + PROTO = 92, + NOMEDIUM = 93, + ASYNC = 99, + _, +}; pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index b08c31c8e3..b60676e266 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -887,127 +887,134 @@ pub usingnamespace switch (builtin.target.cpu.arch) { else => struct {}, }; -pub const EPERM = 1; // Operation not permitted -pub const ENOENT = 2; // No such file or directory -pub const ESRCH = 3; // No such process -pub const EINTR = 4; // Interrupted system call -pub const EIO = 5; // Input/output error -pub const ENXIO = 6; // Device not configured -pub const E2BIG = 7; // Argument list too long -pub const ENOEXEC = 8; // Exec format error -pub const EBADF = 9; // Bad file descriptor -pub const ECHILD = 10; // No child processes -pub const EDEADLK = 11; // Resource deadlock avoided -// 11 was EAGAIN -pub const ENOMEM = 12; // Cannot allocate memory -pub const EACCES = 13; // Permission denied -pub const EFAULT = 14; // Bad address -pub const ENOTBLK = 15; // Block device required -pub const EBUSY = 16; // Device busy -pub const EEXIST = 17; // File exists -pub const EXDEV = 18; // Cross-device link -pub const ENODEV = 19; // Operation not supported by device -pub const ENOTDIR = 20; // Not a directory -pub const EISDIR = 21; // Is a directory -pub const EINVAL = 22; // Invalid argument -pub const ENFILE = 23; // Too many open files in system -pub const EMFILE = 24; // Too many open files -pub const ENOTTY = 25; // Inappropriate ioctl for device -pub const ETXTBSY = 26; // Text file busy -pub const EFBIG = 27; // File too large -pub const ENOSPC = 28; // No space left on device -pub const ESPIPE = 29; // Illegal seek -pub const EROFS = 30; // Read-only filesystem -pub const EMLINK = 31; // Too many links -pub const EPIPE = 32; // Broken pipe +pub const E = enum(u16) { + /// No error occurred. + SUCCESS = 0, -// math software -pub const EDOM = 33; // Numerical argument out of domain -pub const ERANGE = 34; // Result too large + PERM = 1, // Operation not permitted + NOENT = 2, // No such file or directory + SRCH = 3, // No such process + INTR = 4, // Interrupted system call + IO = 5, // Input/output error + NXIO = 6, // Device not configured + @"2BIG" = 7, // Argument list too long + NOEXEC = 8, // Exec format error + BADF = 9, // Bad file descriptor + CHILD = 10, // No child processes + DEADLK = 11, // Resource deadlock avoided + // 11 was AGAIN + NOMEM = 12, // Cannot allocate memory + ACCES = 13, // Permission denied + FAULT = 14, // Bad address + NOTBLK = 15, // Block device required + BUSY = 16, // Device busy + EXIST = 17, // File exists + XDEV = 18, // Cross-device link + NODEV = 19, // Operation not supported by device + NOTDIR = 20, // Not a directory + ISDIR = 21, // Is a directory + INVAL = 22, // Invalid argument + NFILE = 23, // Too many open files in system + MFILE = 24, // Too many open files + NOTTY = 25, // Inappropriate ioctl for device + TXTBSY = 26, // Text file busy + FBIG = 27, // File too large + NOSPC = 28, // No space left on device + SPIPE = 29, // Illegal seek + ROFS = 30, // Read-only filesystem + MLINK = 31, // Too many links + PIPE = 32, // Broken pipe -// non-blocking and interrupt i/o -pub const EAGAIN = 35; // Resource temporarily unavailable -pub const EWOULDBLOCK = EAGAIN; // Operation would block -pub const EINPROGRESS = 36; // Operation now in progress -pub const EALREADY = 37; // Operation already in progress + // math software + DOM = 33, // Numerical argument out of domain + RANGE = 34, // Result too large -// ipc/network software -- argument errors -pub const ENOTSOCK = 38; // Socket operation on non-socket -pub const EDESTADDRREQ = 39; // Destination address required -pub const EMSGSIZE = 40; // Message too long -pub const EPROTOTYPE = 41; // Protocol wrong type for socket -pub const ENOPROTOOPT = 42; // Protocol not available -pub const EPROTONOSUPPORT = 43; // Protocol not supported -pub const ESOCKTNOSUPPORT = 44; // Socket type not supported -pub const EOPNOTSUPP = 45; // Operation not supported -pub const ENOTSUP = EOPNOTSUPP; // Operation not supported -pub const EPFNOSUPPORT = 46; // Protocol family not supported -pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family -pub const EADDRINUSE = 48; // Address already in use -pub const EADDRNOTAVAIL = 49; // Can't assign requested address + // non-blocking and interrupt i/o -// ipc/network software -- operational errors -pub const ENETDOWN = 50; // Network is down -pub const ENETUNREACH = 51; // Network is unreachable -pub const ENETRESET = 52; // Network dropped connection on reset -pub const ECONNABORTED = 53; // Software caused connection abort -pub const ECONNRESET = 54; // Connection reset by peer -pub const ENOBUFS = 55; // No buffer space available -pub const EISCONN = 56; // Socket is already connected -pub const ENOTCONN = 57; // Socket is not connected -pub const ESHUTDOWN = 58; // Can't send after socket shutdown -pub const ETOOMANYREFS = 59; // Too many references: can't splice -pub const ETIMEDOUT = 60; // Operation timed out -pub const ECONNREFUSED = 61; // Connection refused + /// Resource temporarily unavailable + /// This code is also used for `WOULDBLOCK`: operation would block. + AGAIN = 35, + INPROGRESS = 36, // Operation now in progress + ALREADY = 37, // Operation already in progress -pub const ELOOP = 62; // Too many levels of symbolic links -pub const ENAMETOOLONG = 63; // File name too long + // ipc/network software -- argument errors + NOTSOCK = 38, // Socket operation on non-socket + DESTADDRREQ = 39, // Destination address required + MSGSIZE = 40, // Message too long + PROTOTYPE = 41, // Protocol wrong type for socket + NOPROTOOPT = 42, // Protocol not available + PROTONOSUPPORT = 43, // Protocol not supported + SOCKTNOSUPPORT = 44, // Socket type not supported + /// Operation not supported + /// This code is also used for `NOTSUP`. + OPNOTSUPP = 45, + PFNOSUPPORT = 46, // Protocol family not supported + AFNOSUPPORT = 47, // Address family not supported by protocol family + ADDRINUSE = 48, // Address already in use + ADDRNOTAVAIL = 49, // Can't assign requested address -// should be rearranged -pub const EHOSTDOWN = 64; // Host is down -pub const EHOSTUNREACH = 65; // No route to host -pub const ENOTEMPTY = 66; // Directory not empty + // ipc/network software -- operational errors + NETDOWN = 50, // Network is down + NETUNREACH = 51, // Network is unreachable + NETRESET = 52, // Network dropped connection on reset + CONNABORTED = 53, // Software caused connection abort + CONNRESET = 54, // Connection reset by peer + NOBUFS = 55, // No buffer space available + ISCONN = 56, // Socket is already connected + NOTCONN = 57, // Socket is not connected + SHUTDOWN = 58, // Can't send after socket shutdown + TOOMANYREFS = 59, // Too many references: can't splice + TIMEDOUT = 60, // Operation timed out + CONNREFUSED = 61, // Connection refused -// quotas & mush -pub const EPROCLIM = 67; // Too many processes -pub const EUSERS = 68; // Too many users -pub const EDQUOT = 69; // Disc quota exceeded + LOOP = 62, // Too many levels of symbolic links + NAMETOOLONG = 63, // File name too long -// Network File System -pub const ESTALE = 70; // Stale NFS file handle -pub const EREMOTE = 71; // Too many levels of remote in path -pub const EBADRPC = 72; // RPC struct is bad -pub const ERPCMISMATCH = 73; // RPC version wrong -pub const EPROGUNAVAIL = 74; // RPC prog. not avail -pub const EPROGMISMATCH = 75; // Program version wrong -pub const EPROCUNAVAIL = 76; // Bad procedure for program + // should be rearranged + HOSTDOWN = 64, // Host is down + HOSTUNREACH = 65, // No route to host + NOTEMPTY = 66, // Directory not empty -pub const ENOLCK = 77; // No locks available -pub const ENOSYS = 78; // Function not implemented + // quotas & mush + PROCLIM = 67, // Too many processes + USERS = 68, // Too many users + DQUOT = 69, // Disc quota exceeded -pub const EFTYPE = 79; // Inappropriate file type or format -pub const EAUTH = 80; // Authentication error -pub const ENEEDAUTH = 81; // Need authenticator -pub const EIDRM = 82; // Identifier removed -pub const ENOMSG = 83; // No message of desired type -pub const EOVERFLOW = 84; // Value too large to be stored in data type -pub const ECANCELED = 85; // Operation canceled -pub const EILSEQ = 86; // Illegal byte sequence -pub const ENOATTR = 87; // Attribute not found + // Network File System + STALE = 70, // Stale NFS file handle + REMOTE = 71, // Too many levels of remote in path + BADRPC = 72, // RPC struct is bad + RPCMISMATCH = 73, // RPC version wrong + PROGUNAVAIL = 74, // RPC prog. not avail + PROGMISMATCH = 75, // Program version wrong + PROCUNAVAIL = 76, // Bad procedure for program -pub const EDOOFUS = 88; // Programming error + NOLCK = 77, // No locks available + NOSYS = 78, // Function not implemented -pub const EBADMSG = 89; // Bad message -pub const EMULTIHOP = 90; // Multihop attempted -pub const ENOLINK = 91; // Link has been severed -pub const EPROTO = 92; // Protocol error + FTYPE = 79, // Inappropriate file type or format + AUTH = 80, // Authentication error + NEEDAUTH = 81, // Need authenticator + IDRM = 82, // Identifier removed + NOMSG = 83, // No message of desired type + OVERFLOW = 84, // Value too large to be stored in data type + CANCELED = 85, // Operation canceled + ILSEQ = 86, // Illegal byte sequence + NOATTR = 87, // Attribute not found -pub const ENOTCAPABLE = 93; // Capabilities insufficient -pub const ECAPMODE = 94; // Not permitted in capability mode -pub const ENOTRECOVERABLE = 95; // State not recoverable -pub const EOWNERDEAD = 96; // Previous owner died + DOOFUS = 88, // Programming error -pub const ELAST = 96; // Must be equal largest errno + BADMSG = 89, // Bad message + MULTIHOP = 90, // Multihop attempted + NOLINK = 91, // Link has been severed + PROTO = 92, // Protocol error + + NOTCAPABLE = 93, // Capabilities insufficient + CAPMODE = 94, // Not permitted in capability mode + NOTRECOVERABLE = 95, // State not recoverable + OWNERDEAD = 96, // Previous owner died + _, +}; pub const MINSIGSTKSZ = switch (builtin.target.cpu.arch) { .i386, .x86_64 => 2048, diff --git a/lib/std/os/bits/haiku.zig b/lib/std/os/bits/haiku.zig index b3ea4aa0e2..8421c80a52 100644 --- a/lib/std/os/bits/haiku.zig +++ b/lib/std/os/bits/haiku.zig @@ -734,125 +734,130 @@ pub const sigset_t = extern struct { __bits: [_SIG_WORDS]u32, }; -pub const EPERM = -0x7ffffff1; // Operation not permitted -pub const ENOENT = -0x7fff9ffd; // No such file or directory -pub const ESRCH = -0x7fff8ff3; // No such process -pub const EINTR = -0x7ffffff6; // Interrupted system call -pub const EIO = -0x7fffffff; // Input/output error -pub const ENXIO = -0x7fff8ff5; // Device not configured -pub const E2BIG = -0x7fff8fff; // Argument list too long -pub const ENOEXEC = -0x7fffecfe; // Exec format error -pub const ECHILD = -0x7fff8ffe; // No child processes -pub const EDEADLK = -0x7fff8ffd; // Resource deadlock avoided -pub const ENOMEM = -0x80000000; // Cannot allocate memory -pub const EACCES = -0x7ffffffe; // Permission denied -pub const EFAULT = -0x7fffecff; // Bad address -pub const EBUSY = -0x7ffffff2; // Device busy -pub const EEXIST = -0x7fff9ffe; // File exists -pub const EXDEV = -0x7fff9ff5; // Cross-device link -pub const ENODEV = -0x7fff8ff9; // Operation not supported by device -pub const ENOTDIR = -0x7fff9ffb; // Not a directory -pub const EISDIR = -0x7fff9ff7; // Is a directory -pub const EINVAL = -0x7ffffffb; // Invalid argument -pub const ENFILE = -0x7fff8ffa; // Too many open files in system -pub const EMFILE = -0x7fff9ff6; // Too many open files -pub const ENOTTY = -0x7fff8ff6; // Inappropriate ioctl for device -pub const ETXTBSY = -0x7fff8fc5; // Text file busy -pub const EFBIG = -0x7fff8ffc; // File too large -pub const ENOSPC = -0x7fff9ff9; // No space left on device -pub const ESPIPE = -0x7fff8ff4; // Illegal seek -pub const EROFS = -0x7fff9ff8; // Read-only filesystem -pub const EMLINK = -0x7fff8ffb; // Too many links -pub const EPIPE = -0x7fff9ff3; // Broken pipe -pub const EBADF = -0x7fffa000; // Bad file descriptor +pub const E = enum(i32) { + /// No error occurred. + SUCCESS = 0, + PERM = -0x7ffffff1, // Operation not permitted + NOENT = -0x7fff9ffd, // No such file or directory + SRCH = -0x7fff8ff3, // No such process + INTR = -0x7ffffff6, // Interrupted system call + IO = -0x7fffffff, // Input/output error + NXIO = -0x7fff8ff5, // Device not configured + @"2BIG" = -0x7fff8fff, // Argument list too long + NOEXEC = -0x7fffecfe, // Exec format error + CHILD = -0x7fff8ffe, // No child processes + DEADLK = -0x7fff8ffd, // Resource deadlock avoided + NOMEM = -0x80000000, // Cannot allocate memory + ACCES = -0x7ffffffe, // Permission denied + FAULT = -0x7fffecff, // Bad address + BUSY = -0x7ffffff2, // Device busy + EXIST = -0x7fff9ffe, // File exists + XDEV = -0x7fff9ff5, // Cross-device link + NODEV = -0x7fff8ff9, // Operation not supported by device + NOTDIR = -0x7fff9ffb, // Not a directory + ISDIR = -0x7fff9ff7, // Is a directory + INVAL = -0x7ffffffb, // Invalid argument + NFILE = -0x7fff8ffa, // Too many open files in system + MFILE = -0x7fff9ff6, // Too many open files + NOTTY = -0x7fff8ff6, // Inappropriate ioctl for device + TXTBSY = -0x7fff8fc5, // Text file busy + FBIG = -0x7fff8ffc, // File too large + NOSPC = -0x7fff9ff9, // No space left on device + SPIPE = -0x7fff8ff4, // Illegal seek + ROFS = -0x7fff9ff8, // Read-only filesystem + MLINK = -0x7fff8ffb, // Too many links + PIPE = -0x7fff9ff3, // Broken pipe + BADF = -0x7fffa000, // Bad file descriptor -// math software -pub const EDOM = 33; // Numerical argument out of domain -pub const ERANGE = 34; // Result too large + // math software + DOM = 33, // Numerical argument out of domain + RANGE = 34, // Result too large -// non-blocking and interrupt i/o -pub const EAGAIN = -0x7ffffff5; -pub const EWOULDBLOCK = -0x7ffffff5; -pub const EINPROGRESS = -0x7fff8fdc; -pub const EALREADY = -0x7fff8fdb; + // non-blocking and interrupt i/o -// ipc/network software -- argument errors -pub const ENOTSOCK = 38; // Socket operation on non-socket -pub const EDESTADDRREQ = 39; // Destination address required -pub const EMSGSIZE = 40; // Message too long -pub const EPROTOTYPE = 41; // Protocol wrong type for socket -pub const ENOPROTOOPT = 42; // Protocol not available -pub const EPROTONOSUPPORT = 43; // Protocol not supported -pub const ESOCKTNOSUPPORT = 44; // Socket type not supported -pub const EOPNOTSUPP = 45; // Operation not supported -pub const ENOTSUP = EOPNOTSUPP; // Operation not supported -pub const EPFNOSUPPORT = 46; // Protocol family not supported -pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family -pub const EADDRINUSE = 48; // Address already in use -pub const EADDRNOTAVAIL = 49; // Can't assign requested address + /// Also used for `WOULDBLOCK`. + AGAIN = -0x7ffffff5, + INPROGRESS = -0x7fff8fdc, + ALREADY = -0x7fff8fdb, -// ipc/network software -- operational errors -pub const ENETDOWN = 50; // Network is down -pub const ENETUNREACH = 51; // Network is unreachable -pub const ENETRESET = 52; // Network dropped connection on reset -pub const ECONNABORTED = 53; // Software caused connection abort -pub const ECONNRESET = 54; // Connection reset by peer -pub const ENOBUFS = 55; // No buffer space available -pub const EISCONN = 56; // Socket is already connected -pub const ENOTCONN = 57; // Socket is not connected -pub const ESHUTDOWN = 58; // Can't send after socket shutdown -pub const ETOOMANYREFS = 59; // Too many references: can't splice -pub const ETIMEDOUT = 60; // Operation timed out -pub const ECONNREFUSED = 61; // Connection refused + // ipc/network software -- argument errors + NOTSOCK = 38, // Socket operation on non-socket + DESTADDRREQ = 39, // Destination address required + MSGSIZE = 40, // Message too long + PROTOTYPE = 41, // Protocol wrong type for socket + NOPROTOOPT = 42, // Protocol not available + PROTONOSUPPORT = 43, // Protocol not supported + SOCKTNOSUPPORT = 44, // Socket type not supported + /// Also used for `NOTSUP`. + OPNOTSUPP = 45, // Operation not supported + PFNOSUPPORT = 46, // Protocol family not supported + AFNOSUPPORT = 47, // Address family not supported by protocol family + ADDRINUSE = 48, // Address already in use + ADDRNOTAVAIL = 49, // Can't assign requested address -pub const ELOOP = 62; // Too many levels of symbolic links -pub const ENAMETOOLONG = 63; // File name too long + // ipc/network software -- operational errors + NETDOWN = 50, // Network is down + NETUNREACH = 51, // Network is unreachable + NETRESET = 52, // Network dropped connection on reset + CONNABORTED = 53, // Software caused connection abort + CONNRESET = 54, // Connection reset by peer + NOBUFS = 55, // No buffer space available + ISCONN = 56, // Socket is already connected + NOTCONN = 57, // Socket is not connected + SHUTDOWN = 58, // Can't send after socket shutdown + TOOMANYREFS = 59, // Too many references: can't splice + TIMEDOUT = 60, // Operation timed out + CONNREFUSED = 61, // Connection refused -// should be rearranged -pub const EHOSTDOWN = 64; // Host is down -pub const EHOSTUNREACH = 65; // No route to host -pub const ENOTEMPTY = 66; // Directory not empty + LOOP = 62, // Too many levels of symbolic links + NAMETOOLONG = 63, // File name too long -// quotas & mush -pub const EPROCLIM = 67; // Too many processes -pub const EUSERS = 68; // Too many users -pub const EDQUOT = 69; // Disc quota exceeded + // should be rearranged + HOSTDOWN = 64, // Host is down + HOSTUNREACH = 65, // No route to host + NOTEMPTY = 66, // Directory not empty -// Network File System -pub const ESTALE = 70; // Stale NFS file handle -pub const EREMOTE = 71; // Too many levels of remote in path -pub const EBADRPC = 72; // RPC struct is bad -pub const ERPCMISMATCH = 73; // RPC version wrong -pub const EPROGUNAVAIL = 74; // RPC prog. not avail -pub const EPROGMISMATCH = 75; // Program version wrong -pub const EPROCUNAVAIL = 76; // Bad procedure for program + // quotas & mush + PROCLIM = 67, // Too many processes + USERS = 68, // Too many users + DQUOT = 69, // Disc quota exceeded -pub const ENOLCK = 77; // No locks available -pub const ENOSYS = 78; // Function not implemented + // Network File System + STALE = 70, // Stale NFS file handle + REMOTE = 71, // Too many levels of remote in path + BADRPC = 72, // RPC struct is bad + RPCMISMATCH = 73, // RPC version wrong + PROGUNAVAIL = 74, // RPC prog. not avail + PROGMISMATCH = 75, // Program version wrong + PROCUNAVAIL = 76, // Bad procedure for program -pub const EFTYPE = 79; // Inappropriate file type or format -pub const EAUTH = 80; // Authentication error -pub const ENEEDAUTH = 81; // Need authenticator -pub const EIDRM = 82; // Identifier removed -pub const ENOMSG = 83; // No message of desired type -pub const EOVERFLOW = 84; // Value too large to be stored in data type -pub const ECANCELED = 85; // Operation canceled -pub const EILSEQ = 86; // Illegal byte sequence -pub const ENOATTR = 87; // Attribute not found + NOLCK = 77, // No locks available + NOSYS = 78, // Function not implemented -pub const EDOOFUS = 88; // Programming error + FTYPE = 79, // Inappropriate file type or format + AUTH = 80, // Authentication error + NEEDAUTH = 81, // Need authenticator + IDRM = 82, // Identifier removed + NOMSG = 83, // No message of desired type + OVERFLOW = 84, // Value too large to be stored in data type + CANCELED = 85, // Operation canceled + ILSEQ = 86, // Illegal byte sequence + NOATTR = 87, // Attribute not found -pub const EBADMSG = 89; // Bad message -pub const EMULTIHOP = 90; // Multihop attempted -pub const ENOLINK = 91; // Link has been severed -pub const EPROTO = 92; // Protocol error + DOOFUS = 88, // Programming error -pub const ENOTCAPABLE = 93; // Capabilities insufficient -pub const ECAPMODE = 94; // Not permitted in capability mode -pub const ENOTRECOVERABLE = 95; // State not recoverable -pub const EOWNERDEAD = 96; // Previous owner died + BADMSG = 89, // Bad message + MULTIHOP = 90, // Multihop attempted + NOLINK = 91, // Link has been severed + PROTO = 92, // Protocol error -pub const ELAST = 96; // Must be equal largest errno + NOTCAPABLE = 93, // Capabilities insufficient + CAPMODE = 94, // Not permitted in capability mode + NOTRECOVERABLE = 95, // State not recoverable + OWNERDEAD = 96, // Previous owner died + + _, +}; pub const MINSIGSTKSZ = switch (builtin.cpu.arch) { .i386, .x86_64 => 2048, diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index ffe74b74e9..1dbc552b3c 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -8,10 +8,10 @@ const maxInt = std.math.maxInt; const arch = @import("builtin").target.cpu.arch; pub usingnamespace @import("posix.zig"); -pub usingnamespace switch (arch) { - .mips, .mipsel => @import("linux/errno-mips.zig"), - .sparc, .sparcel, .sparcv9 => @import("linux/errno-sparc.zig"), - else => @import("linux/errno-generic.zig"), +pub const E = switch (arch) { + .mips, .mipsel => @import("linux/errno/mips.zig").E, + .sparc, .sparcel, .sparcv9 => @import("linux/errno/sparc.zig").E, + else => @import("linux/errno/generic.zig").E, }; pub usingnamespace switch (arch) { @@ -1665,6 +1665,13 @@ pub const io_uring_cqe = extern struct { /// result code for this event res: i32, flags: u32, + + pub fn err(self: io_uring_cqe) E { + if (self.res > -4096 and self.res < 0) { + return @intToEnum(E, -self.res); + } + return .SUCCESS; + } }; // io_uring_cqe.flags diff --git a/lib/std/os/bits/linux/errno-generic.zig b/lib/std/os/bits/linux/errno-generic.zig deleted file mode 100644 index f55aa3698e..0000000000 --- a/lib/std/os/bits/linux/errno-generic.zig +++ /dev/null @@ -1,462 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2015-2021 Zig Contributors -// This file is part of [zig](https://ziglang.org/), which is MIT licensed. -// The MIT license requires this copyright notice to be included in all copies -// and substantial portions of the software. -/// Operation not permitted -pub const EPERM = 1; - -/// No such file or directory -pub const ENOENT = 2; - -/// No such process -pub const ESRCH = 3; - -/// Interrupted system call -pub const EINTR = 4; - -/// I/O error -pub const EIO = 5; - -/// No such device or address -pub const ENXIO = 6; - -/// Arg list too long -pub const E2BIG = 7; - -/// Exec format error -pub const ENOEXEC = 8; - -/// Bad file number -pub const EBADF = 9; - -/// No child processes -pub const ECHILD = 10; - -/// Try again -pub const EAGAIN = 11; - -/// Out of memory -pub const ENOMEM = 12; - -/// Permission denied -pub const EACCES = 13; - -/// Bad address -pub const EFAULT = 14; - -/// Block device required -pub const ENOTBLK = 15; - -/// Device or resource busy -pub const EBUSY = 16; - -/// File exists -pub const EEXIST = 17; - -/// Cross-device link -pub const EXDEV = 18; - -/// No such device -pub const ENODEV = 19; - -/// Not a directory -pub const ENOTDIR = 20; - -/// Is a directory -pub const EISDIR = 21; - -/// Invalid argument -pub const EINVAL = 22; - -/// File table overflow -pub const ENFILE = 23; - -/// Too many open files -pub const EMFILE = 24; - -/// Not a typewriter -pub const ENOTTY = 25; - -/// Text file busy -pub const ETXTBSY = 26; - -/// File too large -pub const EFBIG = 27; - -/// No space left on device -pub const ENOSPC = 28; - -/// Illegal seek -pub const ESPIPE = 29; - -/// Read-only file system -pub const EROFS = 30; - -/// Too many links -pub const EMLINK = 31; - -/// Broken pipe -pub const EPIPE = 32; - -/// Math argument out of domain of func -pub const EDOM = 33; - -/// Math result not representable -pub const ERANGE = 34; - -/// Resource deadlock would occur -pub const EDEADLK = 35; - -/// File name too long -pub const ENAMETOOLONG = 36; - -/// No record locks available -pub const ENOLCK = 37; - -/// Function not implemented -pub const ENOSYS = 38; - -/// Directory not empty -pub const ENOTEMPTY = 39; - -/// Too many symbolic links encountered -pub const ELOOP = 40; - -/// Operation would block -pub const EWOULDBLOCK = EAGAIN; - -/// No message of desired type -pub const ENOMSG = 42; - -/// Identifier removed -pub const EIDRM = 43; - -/// Channel number out of range -pub const ECHRNG = 44; - -/// Level 2 not synchronized -pub const EL2NSYNC = 45; - -/// Level 3 halted -pub const EL3HLT = 46; - -/// Level 3 reset -pub const EL3RST = 47; - -/// Link number out of range -pub const ELNRNG = 48; - -/// Protocol driver not attached -pub const EUNATCH = 49; - -/// No CSI structure available -pub const ENOCSI = 50; - -/// Level 2 halted -pub const EL2HLT = 51; - -/// Invalid exchange -pub const EBADE = 52; - -/// Invalid request descriptor -pub const EBADR = 53; - -/// Exchange full -pub const EXFULL = 54; - -/// No anode -pub const ENOANO = 55; - -/// Invalid request code -pub const EBADRQC = 56; - -/// Invalid slot -pub const EBADSLT = 57; - -/// Bad font file format -pub const EBFONT = 59; - -/// Device not a stream -pub const ENOSTR = 60; - -/// No data available -pub const ENODATA = 61; - -/// Timer expired -pub const ETIME = 62; - -/// Out of streams resources -pub const ENOSR = 63; - -/// Machine is not on the network -pub const ENONET = 64; - -/// Package not installed -pub const ENOPKG = 65; - -/// Object is remote -pub const EREMOTE = 66; - -/// Link has been severed -pub const ENOLINK = 67; - -/// Advertise error -pub const EADV = 68; - -/// Srmount error -pub const ESRMNT = 69; - -/// Communication error on send -pub const ECOMM = 70; - -/// Protocol error -pub const EPROTO = 71; - -/// Multihop attempted -pub const EMULTIHOP = 72; - -/// RFS specific error -pub const EDOTDOT = 73; - -/// Not a data message -pub const EBADMSG = 74; - -/// Value too large for defined data type -pub const EOVERFLOW = 75; - -/// Name not unique on network -pub const ENOTUNIQ = 76; - -/// File descriptor in bad state -pub const EBADFD = 77; - -/// Remote address changed -pub const EREMCHG = 78; - -/// Can not access a needed shared library -pub const ELIBACC = 79; - -/// Accessing a corrupted shared library -pub const ELIBBAD = 80; - -/// .lib section in a.out corrupted -pub const ELIBSCN = 81; - -/// Attempting to link in too many shared libraries -pub const ELIBMAX = 82; - -/// Cannot exec a shared library directly -pub const ELIBEXEC = 83; - -/// Illegal byte sequence -pub const EILSEQ = 84; - -/// Interrupted system call should be restarted -pub const ERESTART = 85; - -/// Streams pipe error -pub const ESTRPIPE = 86; - -/// Too many users -pub const EUSERS = 87; - -/// Socket operation on non-socket -pub const ENOTSOCK = 88; - -/// Destination address required -pub const EDESTADDRREQ = 89; - -/// Message too long -pub const EMSGSIZE = 90; - -/// Protocol wrong type for socket -pub const EPROTOTYPE = 91; - -/// Protocol not available -pub const ENOPROTOOPT = 92; - -/// Protocol not supported -pub const EPROTONOSUPPORT = 93; - -/// Socket type not supported -pub const ESOCKTNOSUPPORT = 94; - -/// Operation not supported on transport endpoint -pub const EOPNOTSUPP = 95; -pub const ENOTSUP = EOPNOTSUPP; - -/// Protocol family not supported -pub const EPFNOSUPPORT = 96; - -/// Address family not supported by protocol -pub const EAFNOSUPPORT = 97; - -/// Address already in use -pub const EADDRINUSE = 98; - -/// Cannot assign requested address -pub const EADDRNOTAVAIL = 99; - -/// Network is down -pub const ENETDOWN = 100; - -/// Network is unreachable -pub const ENETUNREACH = 101; - -/// Network dropped connection because of reset -pub const ENETRESET = 102; - -/// Software caused connection abort -pub const ECONNABORTED = 103; - -/// Connection reset by peer -pub const ECONNRESET = 104; - -/// No buffer space available -pub const ENOBUFS = 105; - -/// Transport endpoint is already connected -pub const EISCONN = 106; - -/// Transport endpoint is not connected -pub const ENOTCONN = 107; - -/// Cannot send after transport endpoint shutdown -pub const ESHUTDOWN = 108; - -/// Too many references: cannot splice -pub const ETOOMANYREFS = 109; - -/// Connection timed out -pub const ETIMEDOUT = 110; - -/// Connection refused -pub const ECONNREFUSED = 111; - -/// Host is down -pub const EHOSTDOWN = 112; - -/// No route to host -pub const EHOSTUNREACH = 113; - -/// Operation already in progress -pub const EALREADY = 114; - -/// Operation now in progress -pub const EINPROGRESS = 115; - -/// Stale NFS file handle -pub const ESTALE = 116; - -/// Structure needs cleaning -pub const EUCLEAN = 117; - -/// Not a XENIX named type file -pub const ENOTNAM = 118; - -/// No XENIX semaphores available -pub const ENAVAIL = 119; - -/// Is a named type file -pub const EISNAM = 120; - -/// Remote I/O error -pub const EREMOTEIO = 121; - -/// Quota exceeded -pub const EDQUOT = 122; - -/// No medium found -pub const ENOMEDIUM = 123; - -/// Wrong medium type -pub const EMEDIUMTYPE = 124; - -/// Operation canceled -pub const ECANCELED = 125; - -/// Required key not available -pub const ENOKEY = 126; - -/// Key has expired -pub const EKEYEXPIRED = 127; - -/// Key has been revoked -pub const EKEYREVOKED = 128; - -/// Key was rejected by service -pub const EKEYREJECTED = 129; - -// for robust mutexes - -/// Owner died -pub const EOWNERDEAD = 130; - -/// State not recoverable -pub const ENOTRECOVERABLE = 131; - -/// Operation not possible due to RF-kill -pub const ERFKILL = 132; - -/// Memory page has hardware error -pub const EHWPOISON = 133; - -// nameserver query return codes - -/// DNS server returned answer with no data -pub const ENSROK = 0; - -/// DNS server returned answer with no data -pub const ENSRNODATA = 160; - -/// DNS server claims query was misformatted -pub const ENSRFORMERR = 161; - -/// DNS server returned general failure -pub const ENSRSERVFAIL = 162; - -/// Domain name not found -pub const ENSRNOTFOUND = 163; - -/// DNS server does not implement requested operation -pub const ENSRNOTIMP = 164; - -/// DNS server refused query -pub const ENSRREFUSED = 165; - -/// Misformatted DNS query -pub const ENSRBADQUERY = 166; - -/// Misformatted domain name -pub const ENSRBADNAME = 167; - -/// Unsupported address family -pub const ENSRBADFAMILY = 168; - -/// Misformatted DNS reply -pub const ENSRBADRESP = 169; - -/// Could not contact DNS servers -pub const ENSRCONNREFUSED = 170; - -/// Timeout while contacting DNS servers -pub const ENSRTIMEOUT = 171; - -/// End of file -pub const ENSROF = 172; - -/// Error reading file -pub const ENSRFILE = 173; - -/// Out of memory -pub const ENSRNOMEM = 174; - -/// Application terminated lookup -pub const ENSRDESTRUCTION = 175; - -/// Domain name is too long -pub const ENSRQUERYDOMAINTOOLONG = 176; - -/// Domain name is too long -pub const ENSRCNAMELOOP = 177; diff --git a/lib/std/os/bits/linux/errno-mips.zig b/lib/std/os/bits/linux/errno-mips.zig deleted file mode 100644 index 2c22290288..0000000000 --- a/lib/std/os/bits/linux/errno-mips.zig +++ /dev/null @@ -1,143 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2015-2021 Zig Contributors -// This file is part of [zig](https://ziglang.org/), which is MIT licensed. -// The MIT license requires this copyright notice to be included in all copies -// and substantial portions of the software. - -// These are MIPS ABI compatible. - -pub const EPERM = 1; -pub const ENOENT = 2; -pub const ESRCH = 3; -pub const EINTR = 4; -pub const EIO = 5; -pub const ENXIO = 6; -pub const E2BIG = 7; -pub const ENOEXEC = 8; -pub const EBADF = 9; -pub const ECHILD = 10; -pub const EAGAIN = 11; -pub const ENOMEM = 12; -pub const EACCES = 13; -pub const EFAULT = 14; -pub const ENOTBLK = 15; -pub const EBUSY = 16; -pub const EEXIST = 17; -pub const EXDEV = 18; -pub const ENODEV = 19; -pub const ENOTDIR = 20; -pub const EISDIR = 21; -pub const EINVAL = 22; -pub const ENFILE = 23; -pub const EMFILE = 24; -pub const ENOTTY = 25; -pub const ETXTBSY = 26; -pub const EFBIG = 27; -pub const ENOSPC = 28; -pub const ESPIPE = 29; -pub const EROFS = 30; -pub const EMLINK = 31; -pub const EPIPE = 32; -pub const EDOM = 33; -pub const ERANGE = 34; - -pub const ENOMSG = 35; -pub const EIDRM = 36; -pub const ECHRNG = 37; -pub const EL2NSYNC = 38; -pub const EL3HLT = 39; -pub const EL3RST = 40; -pub const ELNRNG = 41; -pub const EUNATCH = 42; -pub const ENOCSI = 43; -pub const EL2HLT = 44; -pub const EDEADLK = 45; -pub const ENOLCK = 46; -pub const EBADE = 50; -pub const EBADR = 51; -pub const EXFULL = 52; -pub const ENOANO = 53; -pub const EBADRQC = 54; -pub const EBADSLT = 55; -pub const EDEADLOCK = 56; -pub const EBFONT = 59; -pub const ENOSTR = 60; -pub const ENODATA = 61; -pub const ETIME = 62; -pub const ENOSR = 63; -pub const ENONET = 64; -pub const ENOPKG = 65; -pub const EREMOTE = 66; -pub const ENOLINK = 67; -pub const EADV = 68; -pub const ESRMNT = 69; -pub const ECOMM = 70; -pub const EPROTO = 71; -pub const EDOTDOT = 73; -pub const EMULTIHOP = 74; -pub const EBADMSG = 77; -pub const ENAMETOOLONG = 78; -pub const EOVERFLOW = 79; -pub const ENOTUNIQ = 80; -pub const EBADFD = 81; -pub const EREMCHG = 82; -pub const ELIBACC = 83; -pub const ELIBBAD = 84; -pub const ELIBSCN = 85; -pub const ELIBMAX = 86; -pub const ELIBEXEC = 87; -pub const EILSEQ = 88; -pub const ENOSYS = 89; -pub const ELOOP = 90; -pub const ERESTART = 91; -pub const ESTRPIPE = 92; -pub const ENOTEMPTY = 93; -pub const EUSERS = 94; -pub const ENOTSOCK = 95; -pub const EDESTADDRREQ = 96; -pub const EMSGSIZE = 97; -pub const EPROTOTYPE = 98; -pub const ENOPROTOOPT = 99; -pub const EPROTONOSUPPORT = 120; -pub const ESOCKTNOSUPPORT = 121; -pub const EOPNOTSUPP = 122; -pub const ENOTSUP = EOPNOTSUPP; -pub const EPFNOSUPPORT = 123; -pub const EAFNOSUPPORT = 124; -pub const EADDRINUSE = 125; -pub const EADDRNOTAVAIL = 126; -pub const ENETDOWN = 127; -pub const ENETUNREACH = 128; -pub const ENETRESET = 129; -pub const ECONNABORTED = 130; -pub const ECONNRESET = 131; -pub const ENOBUFS = 132; -pub const EISCONN = 133; -pub const ENOTCONN = 134; -pub const EUCLEAN = 135; -pub const ENOTNAM = 137; -pub const ENAVAIL = 138; -pub const EISNAM = 139; -pub const EREMOTEIO = 140; -pub const ESHUTDOWN = 143; -pub const ETOOMANYREFS = 144; -pub const ETIMEDOUT = 145; -pub const ECONNREFUSED = 146; -pub const EHOSTDOWN = 147; -pub const EHOSTUNREACH = 148; -pub const EWOULDBLOCK = EAGAIN; -pub const EALREADY = 149; -pub const EINPROGRESS = 150; -pub const ESTALE = 151; -pub const ECANCELED = 158; -pub const ENOMEDIUM = 159; -pub const EMEDIUMTYPE = 160; -pub const ENOKEY = 161; -pub const EKEYEXPIRED = 162; -pub const EKEYREVOKED = 163; -pub const EKEYREJECTED = 164; -pub const EOWNERDEAD = 165; -pub const ENOTRECOVERABLE = 166; -pub const ERFKILL = 167; -pub const EHWPOISON = 168; -pub const EDQUOT = 1133; diff --git a/lib/std/os/bits/linux/errno-sparc.zig b/lib/std/os/bits/linux/errno-sparc.zig deleted file mode 100644 index 94b696fc35..0000000000 --- a/lib/std/os/bits/linux/errno-sparc.zig +++ /dev/null @@ -1,145 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2015-2021 Zig Contributors -// This file is part of [zig](https://ziglang.org/), which is MIT licensed. -// The MIT license requires this copyright notice to be included in all copies -// and substantial portions of the software. - -// These match the SunOS error numbering scheme. - -pub const EPERM = 1; -pub const ENOENT = 2; -pub const ESRCH = 3; -pub const EINTR = 4; -pub const EIO = 5; -pub const ENXIO = 6; -pub const E2BIG = 7; -pub const ENOEXEC = 8; -pub const EBADF = 9; -pub const ECHILD = 10; -pub const EAGAIN = 11; -pub const ENOMEM = 12; -pub const EACCES = 13; -pub const EFAULT = 14; -pub const ENOTBLK = 15; -pub const EBUSY = 16; -pub const EEXIST = 17; -pub const EXDEV = 18; -pub const ENODEV = 19; -pub const ENOTDIR = 20; -pub const EISDIR = 21; -pub const EINVAL = 22; -pub const ENFILE = 23; -pub const EMFILE = 24; -pub const ENOTTY = 25; -pub const ETXTBSY = 26; -pub const EFBIG = 27; -pub const ENOSPC = 28; -pub const ESPIPE = 29; -pub const EROFS = 30; -pub const EMLINK = 31; -pub const EPIPE = 32; -pub const EDOM = 33; -pub const ERANGE = 34; - -pub const EWOULDBLOCK = EAGAIN; -pub const EINPROGRESS = 36; -pub const EALREADY = 37; -pub const ENOTSOCK = 38; -pub const EDESTADDRREQ = 39; -pub const EMSGSIZE = 40; -pub const EPROTOTYPE = 41; -pub const ENOPROTOOPT = 42; -pub const EPROTONOSUPPORT = 43; -pub const ESOCKTNOSUPPORT = 44; -pub const EOPNOTSUPP = 45; -pub const ENOTSUP = EOPNOTSUPP; -pub const EPFNOSUPPORT = 46; -pub const EAFNOSUPPORT = 47; -pub const EADDRINUSE = 48; -pub const EADDRNOTAVAIL = 49; -pub const ENETDOWN = 50; -pub const ENETUNREACH = 51; -pub const ENETRESET = 52; -pub const ECONNABORTED = 53; -pub const ECONNRESET = 54; -pub const ENOBUFS = 55; -pub const EISCONN = 56; -pub const ENOTCONN = 57; -pub const ESHUTDOWN = 58; -pub const ETOOMANYREFS = 59; -pub const ETIMEDOUT = 60; -pub const ECONNREFUSED = 61; -pub const ELOOP = 62; -pub const ENAMETOOLONG = 63; -pub const EHOSTDOWN = 64; -pub const EHOSTUNREACH = 65; -pub const ENOTEMPTY = 66; -pub const EPROCLIM = 67; -pub const EUSERS = 68; -pub const EDQUOT = 69; -pub const ESTALE = 70; -pub const EREMOTE = 71; -pub const ENOSTR = 72; -pub const ETIME = 73; -pub const ENOSR = 74; -pub const ENOMSG = 75; -pub const EBADMSG = 76; -pub const EIDRM = 77; -pub const EDEADLK = 78; -pub const ENOLCK = 79; -pub const ENONET = 80; -pub const ERREMOTE = 81; -pub const ENOLINK = 82; -pub const EADV = 83; -pub const ESRMNT = 84; -pub const ECOMM = 85; -pub const EPROTO = 86; -pub const EMULTIHOP = 87; -pub const EDOTDOT = 88; -pub const EREMCHG = 89; -pub const ENOSYS = 90; -pub const ESTRPIPE = 91; -pub const EOVERFLOW = 92; -pub const EBADFD = 93; -pub const ECHRNG = 94; -pub const EL2NSYNC = 95; -pub const EL3HLT = 96; -pub const EL3RST = 97; -pub const ELNRNG = 98; -pub const EUNATCH = 99; -pub const ENOCSI = 100; -pub const EL2HLT = 101; -pub const EBADE = 102; -pub const EBADR = 103; -pub const EXFULL = 104; -pub const ENOANO = 105; -pub const EBADRQC = 106; -pub const EBADSLT = 107; -pub const EDEADLOCK = 108; -pub const EBFONT = 109; -pub const ELIBEXEC = 110; -pub const ENODATA = 111; -pub const ELIBBAD = 112; -pub const ENOPKG = 113; -pub const ELIBACC = 114; -pub const ENOTUNIQ = 115; -pub const ERESTART = 116; -pub const EUCLEAN = 117; -pub const ENOTNAM = 118; -pub const ENAVAIL = 119; -pub const EISNAM = 120; -pub const EREMOTEIO = 121; -pub const EILSEQ = 122; -pub const ELIBMAX = 123; -pub const ELIBSCN = 124; -pub const ENOMEDIUM = 125; -pub const EMEDIUMTYPE = 126; -pub const ECANCELED = 127; -pub const ENOKEY = 128; -pub const EKEYEXPIRED = 129; -pub const EKEYREVOKED = 130; -pub const EKEYREJECTED = 131; -pub const EOWNERDEAD = 132; -pub const ENOTRECOVERABLE = 133; -pub const ERFKILL = 134; -pub const EHWPOISON = 135; diff --git a/lib/std/os/bits/linux/errno/generic.zig b/lib/std/os/bits/linux/errno/generic.zig new file mode 100644 index 0000000000..49b35f6501 --- /dev/null +++ b/lib/std/os/bits/linux/errno/generic.zig @@ -0,0 +1,466 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +pub const E = enum(u16) { + /// No error occurred. + /// Same code used for `NSROK`. + SUCCESS = 0, + + /// Operation not permitted + PERM = 1, + + /// No such file or directory + NOENT = 2, + + /// No such process + SRCH = 3, + + /// Interrupted system call + INTR = 4, + + /// I/O error + IO = 5, + + /// No such device or address + NXIO = 6, + + /// Arg list too long + @"2BIG" = 7, + + /// Exec format error + NOEXEC = 8, + + /// Bad file number + BADF = 9, + + /// No child processes + CHILD = 10, + + /// Try again + /// Also means: WOULDBLOCK: operation would block + AGAIN = 11, + + /// Out of memory + NOMEM = 12, + + /// Permission denied + ACCES = 13, + + /// Bad address + FAULT = 14, + + /// Block device required + NOTBLK = 15, + + /// Device or resource busy + BUSY = 16, + + /// File exists + EXIST = 17, + + /// Cross-device link + XDEV = 18, + + /// No such device + NODEV = 19, + + /// Not a directory + NOTDIR = 20, + + /// Is a directory + ISDIR = 21, + + /// Invalid argument + INVAL = 22, + + /// File table overflow + NFILE = 23, + + /// Too many open files + MFILE = 24, + + /// Not a typewriter + NOTTY = 25, + + /// Text file busy + TXTBSY = 26, + + /// File too large + FBIG = 27, + + /// No space left on device + NOSPC = 28, + + /// Illegal seek + SPIPE = 29, + + /// Read-only file system + ROFS = 30, + + /// Too many links + MLINK = 31, + + /// Broken pipe + PIPE = 32, + + /// Math argument out of domain of func + DOM = 33, + + /// Math result not representable + RANGE = 34, + + /// Resource deadlock would occur + DEADLK = 35, + + /// File name too long + NAMETOOLONG = 36, + + /// No record locks available + NOLCK = 37, + + /// Function not implemented + NOSYS = 38, + + /// Directory not empty + NOTEMPTY = 39, + + /// Too many symbolic links encountered + LOOP = 40, + + /// No message of desired type + NOMSG = 42, + + /// Identifier removed + IDRM = 43, + + /// Channel number out of range + CHRNG = 44, + + /// Level 2 not synchronized + L2NSYNC = 45, + + /// Level 3 halted + L3HLT = 46, + + /// Level 3 reset + L3RST = 47, + + /// Link number out of range + LNRNG = 48, + + /// Protocol driver not attached + UNATCH = 49, + + /// No CSI structure available + NOCSI = 50, + + /// Level 2 halted + L2HLT = 51, + + /// Invalid exchange + BADE = 52, + + /// Invalid request descriptor + BADR = 53, + + /// Exchange full + XFULL = 54, + + /// No anode + NOANO = 55, + + /// Invalid request code + BADRQC = 56, + + /// Invalid slot + BADSLT = 57, + + /// Bad font file format + BFONT = 59, + + /// Device not a stream + NOSTR = 60, + + /// No data available + NODATA = 61, + + /// Timer expired + TIME = 62, + + /// Out of streams resources + NOSR = 63, + + /// Machine is not on the network + NONET = 64, + + /// Package not installed + NOPKG = 65, + + /// Object is remote + REMOTE = 66, + + /// Link has been severed + NOLINK = 67, + + /// Advertise error + ADV = 68, + + /// Srmount error + SRMNT = 69, + + /// Communication error on send + COMM = 70, + + /// Protocol error + PROTO = 71, + + /// Multihop attempted + MULTIHOP = 72, + + /// RFS specific error + DOTDOT = 73, + + /// Not a data message + BADMSG = 74, + + /// Value too large for defined data type + OVERFLOW = 75, + + /// Name not unique on network + NOTUNIQ = 76, + + /// File descriptor in bad state + BADFD = 77, + + /// Remote address changed + REMCHG = 78, + + /// Can not access a needed shared library + LIBACC = 79, + + /// Accessing a corrupted shared library + LIBBAD = 80, + + /// .lib section in a.out corrupted + LIBSCN = 81, + + /// Attempting to link in too many shared libraries + LIBMAX = 82, + + /// Cannot exec a shared library directly + LIBEXEC = 83, + + /// Illegal byte sequence + ILSEQ = 84, + + /// Interrupted system call should be restarted + RESTART = 85, + + /// Streams pipe error + STRPIPE = 86, + + /// Too many users + USERS = 87, + + /// Socket operation on non-socket + NOTSOCK = 88, + + /// Destination address required + DESTADDRREQ = 89, + + /// Message too long + MSGSIZE = 90, + + /// Protocol wrong type for socket + PROTOTYPE = 91, + + /// Protocol not available + NOPROTOOPT = 92, + + /// Protocol not supported + PROTONOSUPPORT = 93, + + /// Socket type not supported + SOCKTNOSUPPORT = 94, + + /// Operation not supported on transport endpoint + /// This code also means `NOTSUP`. + OPNOTSUPP = 95, + + /// Protocol family not supported + PFNOSUPPORT = 96, + + /// Address family not supported by protocol + AFNOSUPPORT = 97, + + /// Address already in use + ADDRINUSE = 98, + + /// Cannot assign requested address + ADDRNOTAVAIL = 99, + + /// Network is down + NETDOWN = 100, + + /// Network is unreachable + NETUNREACH = 101, + + /// Network dropped connection because of reset + NETRESET = 102, + + /// Software caused connection abort + CONNABORTED = 103, + + /// Connection reset by peer + CONNRESET = 104, + + /// No buffer space available + NOBUFS = 105, + + /// Transport endpoint is already connected + ISCONN = 106, + + /// Transport endpoint is not connected + NOTCONN = 107, + + /// Cannot send after transport endpoint shutdown + SHUTDOWN = 108, + + /// Too many references: cannot splice + TOOMANYREFS = 109, + + /// Connection timed out + TIMEDOUT = 110, + + /// Connection refused + CONNREFUSED = 111, + + /// Host is down + HOSTDOWN = 112, + + /// No route to host + HOSTUNREACH = 113, + + /// Operation already in progress + ALREADY = 114, + + /// Operation now in progress + INPROGRESS = 115, + + /// Stale NFS file handle + STALE = 116, + + /// Structure needs cleaning + UCLEAN = 117, + + /// Not a XENIX named type file + NOTNAM = 118, + + /// No XENIX semaphores available + NAVAIL = 119, + + /// Is a named type file + ISNAM = 120, + + /// Remote I/O error + REMOTEIO = 121, + + /// Quota exceeded + DQUOT = 122, + + /// No medium found + NOMEDIUM = 123, + + /// Wrong medium type + MEDIUMTYPE = 124, + + /// Operation canceled + CANCELED = 125, + + /// Required key not available + NOKEY = 126, + + /// Key has expired + KEYEXPIRED = 127, + + /// Key has been revoked + KEYREVOKED = 128, + + /// Key was rejected by service + KEYREJECTED = 129, + + // for robust mutexes + + /// Owner died + OWNERDEAD = 130, + + /// State not recoverable + NOTRECOVERABLE = 131, + + /// Operation not possible due to RF-kill + RFKILL = 132, + + /// Memory page has hardware error + HWPOISON = 133, + + // nameserver query return codes + + /// DNS server returned answer with no data + NSRNODATA = 160, + + /// DNS server claims query was misformatted + NSRFORMERR = 161, + + /// DNS server returned general failure + NSRSERVFAIL = 162, + + /// Domain name not found + NSRNOTFOUND = 163, + + /// DNS server does not implement requested operation + NSRNOTIMP = 164, + + /// DNS server refused query + NSRREFUSED = 165, + + /// Misformatted DNS query + NSRBADQUERY = 166, + + /// Misformatted domain name + NSRBADNAME = 167, + + /// Unsupported address family + NSRBADFAMILY = 168, + + /// Misformatted DNS reply + NSRBADRESP = 169, + + /// Could not contact DNS servers + NSRCONNREFUSED = 170, + + /// Timeout while contacting DNS servers + NSRTIMEOUT = 171, + + /// End of file + NSROF = 172, + + /// Error reading file + NSRFILE = 173, + + /// Out of memory + NSRNOMEM = 174, + + /// Application terminated lookup + NSRDESTRUCTION = 175, + + /// Domain name is too long + NSRQUERYDOMAINTOOLONG = 176, + + /// Domain name is too long + NSRCNAMELOOP = 177, + + _, +}; diff --git a/lib/std/os/bits/linux/errno/mips.zig b/lib/std/os/bits/linux/errno/mips.zig new file mode 100644 index 0000000000..4f14db65ee --- /dev/null +++ b/lib/std/os/bits/linux/errno/mips.zig @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +//! These are MIPS ABI compatible. +pub const E = enum(i32) { + /// No error occurred. + SUCCESS = 0, + + PERM = 1, + NOENT = 2, + SRCH = 3, + INTR = 4, + IO = 5, + NXIO = 6, + @"2BIG" = 7, + NOEXEC = 8, + BADF = 9, + CHILD = 10, + /// Also used for WOULDBLOCK. + AGAIN = 11, + NOMEM = 12, + ACCES = 13, + FAULT = 14, + NOTBLK = 15, + BUSY = 16, + EXIST = 17, + XDEV = 18, + NODEV = 19, + NOTDIR = 20, + ISDIR = 21, + INVAL = 22, + NFILE = 23, + MFILE = 24, + NOTTY = 25, + TXTBSY = 26, + FBIG = 27, + NOSPC = 28, + SPIPE = 29, + ROFS = 30, + MLINK = 31, + PIPE = 32, + DOM = 33, + RANGE = 34, + + NOMSG = 35, + IDRM = 36, + CHRNG = 37, + L2NSYNC = 38, + L3HLT = 39, + L3RST = 40, + LNRNG = 41, + UNATCH = 42, + NOCSI = 43, + L2HLT = 44, + DEADLK = 45, + NOLCK = 46, + BADE = 50, + BADR = 51, + XFULL = 52, + NOANO = 53, + BADRQC = 54, + BADSLT = 55, + DEADLOCK = 56, + BFONT = 59, + NOSTR = 60, + NODATA = 61, + TIME = 62, + NOSR = 63, + NONET = 64, + NOPKG = 65, + REMOTE = 66, + NOLINK = 67, + ADV = 68, + SRMNT = 69, + COMM = 70, + PROTO = 71, + DOTDOT = 73, + MULTIHOP = 74, + BADMSG = 77, + NAMETOOLONG = 78, + OVERFLOW = 79, + NOTUNIQ = 80, + BADFD = 81, + REMCHG = 82, + LIBACC = 83, + LIBBAD = 84, + LIBSCN = 85, + LIBMAX = 86, + LIBEXEC = 87, + ILSEQ = 88, + NOSYS = 89, + LOOP = 90, + RESTART = 91, + STRPIPE = 92, + NOTEMPTY = 93, + USERS = 94, + NOTSOCK = 95, + DESTADDRREQ = 96, + MSGSIZE = 97, + PROTOTYPE = 98, + NOPROTOOPT = 99, + PROTONOSUPPORT = 120, + SOCKTNOSUPPORT = 121, + OPNOTSUPP = 122, + PFNOSUPPORT = 123, + AFNOSUPPORT = 124, + ADDRINUSE = 125, + ADDRNOTAVAIL = 126, + NETDOWN = 127, + NETUNREACH = 128, + NETRESET = 129, + CONNABORTED = 130, + CONNRESET = 131, + NOBUFS = 132, + ISCONN = 133, + NOTCONN = 134, + UCLEAN = 135, + NOTNAM = 137, + NAVAIL = 138, + ISNAM = 139, + REMOTEIO = 140, + SHUTDOWN = 143, + TOOMANYREFS = 144, + TIMEDOUT = 145, + CONNREFUSED = 146, + HOSTDOWN = 147, + HOSTUNREACH = 148, + ALREADY = 149, + INPROGRESS = 150, + STALE = 151, + CANCELED = 158, + NOMEDIUM = 159, + MEDIUMTYPE = 160, + NOKEY = 161, + KEYEXPIRED = 162, + KEYREVOKED = 163, + KEYREJECTED = 164, + OWNERDEAD = 165, + NOTRECOVERABLE = 166, + RFKILL = 167, + HWPOISON = 168, + DQUOT = 1133, + _, +}; diff --git a/lib/std/os/bits/linux/errno/sparc.zig b/lib/std/os/bits/linux/errno/sparc.zig new file mode 100644 index 0000000000..cc43ce1a94 --- /dev/null +++ b/lib/std/os/bits/linux/errno/sparc.zig @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +//! These match the SunOS error numbering scheme. +pub const E = enum(i32) { + /// No error occurred. + SUCCESS = 0, + + PERM = 1, + NOENT = 2, + SRCH = 3, + INTR = 4, + IO = 5, + NXIO = 6, + @"2BIG" = 7, + NOEXEC = 8, + BADF = 9, + CHILD = 10, + /// Also used for WOULDBLOCK + AGAIN = 11, + NOMEM = 12, + ACCES = 13, + FAULT = 14, + NOTBLK = 15, + BUSY = 16, + EXIST = 17, + XDEV = 18, + NODEV = 19, + NOTDIR = 20, + ISDIR = 21, + INVAL = 22, + NFILE = 23, + MFILE = 24, + NOTTY = 25, + TXTBSY = 26, + FBIG = 27, + NOSPC = 28, + SPIPE = 29, + ROFS = 30, + MLINK = 31, + PIPE = 32, + DOM = 33, + RANGE = 34, + + INPROGRESS = 36, + ALREADY = 37, + NOTSOCK = 38, + DESTADDRREQ = 39, + MSGSIZE = 40, + PROTOTYPE = 41, + NOPROTOOPT = 42, + PROTONOSUPPORT = 43, + SOCKTNOSUPPORT = 44, + /// Also used for NOTSUP + OPNOTSUPP = 45, + PFNOSUPPORT = 46, + AFNOSUPPORT = 47, + ADDRINUSE = 48, + ADDRNOTAVAIL = 49, + NETDOWN = 50, + NETUNREACH = 51, + NETRESET = 52, + CONNABORTED = 53, + CONNRESET = 54, + NOBUFS = 55, + ISCONN = 56, + NOTCONN = 57, + SHUTDOWN = 58, + TOOMANYREFS = 59, + TIMEDOUT = 60, + CONNREFUSED = 61, + LOOP = 62, + NAMETOOLONG = 63, + HOSTDOWN = 64, + HOSTUNREACH = 65, + NOTEMPTY = 66, + PROCLIM = 67, + USERS = 68, + DQUOT = 69, + STALE = 70, + REMOTE = 71, + NOSTR = 72, + TIME = 73, + NOSR = 74, + NOMSG = 75, + BADMSG = 76, + IDRM = 77, + DEADLK = 78, + NOLCK = 79, + NONET = 80, + RREMOTE = 81, + NOLINK = 82, + ADV = 83, + SRMNT = 84, + COMM = 85, + PROTO = 86, + MULTIHOP = 87, + DOTDOT = 88, + REMCHG = 89, + NOSYS = 90, + STRPIPE = 91, + OVERFLOW = 92, + BADFD = 93, + CHRNG = 94, + L2NSYNC = 95, + L3HLT = 96, + L3RST = 97, + LNRNG = 98, + UNATCH = 99, + NOCSI = 100, + L2HLT = 101, + BADE = 102, + BADR = 103, + XFULL = 104, + NOANO = 105, + BADRQC = 106, + BADSLT = 107, + DEADLOCK = 108, + BFONT = 109, + LIBEXEC = 110, + NODATA = 111, + LIBBAD = 112, + NOPKG = 113, + LIBACC = 114, + NOTUNIQ = 115, + RESTART = 116, + UCLEAN = 117, + NOTNAM = 118, + NAVAIL = 119, + ISNAM = 120, + REMOTEIO = 121, + ILSEQ = 122, + LIBMAX = 123, + LIBSCN = 124, + NOMEDIUM = 125, + MEDIUMTYPE = 126, + CANCELED = 127, + NOKEY = 128, + KEYEXPIRED = 129, + KEYREVOKED = 130, + KEYREJECTED = 131, + OWNERDEAD = 132, + NOTRECOVERABLE = 133, + RFKILL = 134, + HWPOISON = 135, + _, +}; diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index af04d0536b..f1bfe1b958 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -933,140 +933,144 @@ pub const ucontext_t = extern struct { ]u32, }; -pub const EPERM = 1; // Operation not permitted -pub const ENOENT = 2; // No such file or directory -pub const ESRCH = 3; // No such process -pub const EINTR = 4; // Interrupted system call -pub const EIO = 5; // Input/output error -pub const ENXIO = 6; // Device not configured -pub const E2BIG = 7; // Argument list too long -pub const ENOEXEC = 8; // Exec format error -pub const EBADF = 9; // Bad file descriptor -pub const ECHILD = 10; // No child processes -pub const EDEADLK = 11; // Resource deadlock avoided -// 11 was EAGAIN -pub const ENOMEM = 12; // Cannot allocate memory -pub const EACCES = 13; // Permission denied -pub const EFAULT = 14; // Bad address -pub const ENOTBLK = 15; // Block device required -pub const EBUSY = 16; // Device busy -pub const EEXIST = 17; // File exists -pub const EXDEV = 18; // Cross-device link -pub const ENODEV = 19; // Operation not supported by device -pub const ENOTDIR = 20; // Not a directory -pub const EISDIR = 21; // Is a directory -pub const EINVAL = 22; // Invalid argument -pub const ENFILE = 23; // Too many open files in system -pub const EMFILE = 24; // Too many open files -pub const ENOTTY = 25; // Inappropriate ioctl for device -pub const ETXTBSY = 26; // Text file busy -pub const EFBIG = 27; // File too large -pub const ENOSPC = 28; // No space left on device -pub const ESPIPE = 29; // Illegal seek -pub const EROFS = 30; // Read-only file system -pub const EMLINK = 31; // Too many links -pub const EPIPE = 32; // Broken pipe +pub const E = enum(u16) { + /// No error occurred. + SUCCESS = 0, + PERM = 1, // Operation not permitted + NOENT = 2, // No such file or directory + SRCH = 3, // No such process + INTR = 4, // Interrupted system call + IO = 5, // Input/output error + NXIO = 6, // Device not configured + @"2BIG" = 7, // Argument list too long + NOEXEC = 8, // Exec format error + BADF = 9, // Bad file descriptor + CHILD = 10, // No child processes + DEADLK = 11, // Resource deadlock avoided + // 11 was AGAIN + NOMEM = 12, // Cannot allocate memory + ACCES = 13, // Permission denied + FAULT = 14, // Bad address + NOTBLK = 15, // Block device required + BUSY = 16, // Device busy + EXIST = 17, // File exists + XDEV = 18, // Cross-device link + NODEV = 19, // Operation not supported by device + NOTDIR = 20, // Not a directory + ISDIR = 21, // Is a directory + INVAL = 22, // Invalid argument + NFILE = 23, // Too many open files in system + MFILE = 24, // Too many open files + NOTTY = 25, // Inappropriate ioctl for device + TXTBSY = 26, // Text file busy + FBIG = 27, // File too large + NOSPC = 28, // No space left on device + SPIPE = 29, // Illegal seek + ROFS = 30, // Read-only file system + MLINK = 31, // Too many links + PIPE = 32, // Broken pipe -// math software -pub const EDOM = 33; // Numerical argument out of domain -pub const ERANGE = 34; // Result too large or too small + // math software + DOM = 33, // Numerical argument out of domain + RANGE = 34, // Result too large or too small -// non-blocking and interrupt i/o -pub const EAGAIN = 35; // Resource temporarily unavailable -pub const EWOULDBLOCK = EAGAIN; // Operation would block -pub const EINPROGRESS = 36; // Operation now in progress -pub const EALREADY = 37; // Operation already in progress + // non-blocking and interrupt i/o + // also: WOULDBLOCK: operation would block + AGAIN = 35, // Resource temporarily unavailable + INPROGRESS = 36, // Operation now in progress + ALREADY = 37, // Operation already in progress -// ipc/network software -- argument errors -pub const ENOTSOCK = 38; // Socket operation on non-socket -pub const EDESTADDRREQ = 39; // Destination address required -pub const EMSGSIZE = 40; // Message too long -pub const EPROTOTYPE = 41; // Protocol wrong type for socket -pub const ENOPROTOOPT = 42; // Protocol option not available -pub const EPROTONOSUPPORT = 43; // Protocol not supported -pub const ESOCKTNOSUPPORT = 44; // Socket type not supported -pub const EOPNOTSUPP = 45; // Operation not supported -pub const EPFNOSUPPORT = 46; // Protocol family not supported -pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family -pub const EADDRINUSE = 48; // Address already in use -pub const EADDRNOTAVAIL = 49; // Can't assign requested address + // ipc/network software -- argument errors + NOTSOCK = 38, // Socket operation on non-socket + DESTADDRREQ = 39, // Destination address required + MSGSIZE = 40, // Message too long + PROTOTYPE = 41, // Protocol wrong type for socket + NOPROTOOPT = 42, // Protocol option not available + PROTONOSUPPORT = 43, // Protocol not supported + SOCKTNOSUPPORT = 44, // Socket type not supported + OPNOTSUPP = 45, // Operation not supported + PFNOSUPPORT = 46, // Protocol family not supported + AFNOSUPPORT = 47, // Address family not supported by protocol family + ADDRINUSE = 48, // Address already in use + ADDRNOTAVAIL = 49, // Can't assign requested address -// ipc/network software -- operational errors -pub const ENETDOWN = 50; // Network is down -pub const ENETUNREACH = 51; // Network is unreachable -pub const ENETRESET = 52; // Network dropped connection on reset -pub const ECONNABORTED = 53; // Software caused connection abort -pub const ECONNRESET = 54; // Connection reset by peer -pub const ENOBUFS = 55; // No buffer space available -pub const EISCONN = 56; // Socket is already connected -pub const ENOTCONN = 57; // Socket is not connected -pub const ESHUTDOWN = 58; // Can't send after socket shutdown -pub const ETOOMANYREFS = 59; // Too many references: can't splice -pub const ETIMEDOUT = 60; // Operation timed out -pub const ECONNREFUSED = 61; // Connection refused + // ipc/network software -- operational errors + NETDOWN = 50, // Network is down + NETUNREACH = 51, // Network is unreachable + NETRESET = 52, // Network dropped connection on reset + CONNABORTED = 53, // Software caused connection abort + CONNRESET = 54, // Connection reset by peer + NOBUFS = 55, // No buffer space available + ISCONN = 56, // Socket is already connected + NOTCONN = 57, // Socket is not connected + SHUTDOWN = 58, // Can't send after socket shutdown + TOOMANYREFS = 59, // Too many references: can't splice + TIMEDOUT = 60, // Operation timed out + CONNREFUSED = 61, // Connection refused -pub const ELOOP = 62; // Too many levels of symbolic links -pub const ENAMETOOLONG = 63; // File name too long + LOOP = 62, // Too many levels of symbolic links + NAMETOOLONG = 63, // File name too long -// should be rearranged -pub const EHOSTDOWN = 64; // Host is down -pub const EHOSTUNREACH = 65; // No route to host -pub const ENOTEMPTY = 66; // Directory not empty + // should be rearranged + HOSTDOWN = 64, // Host is down + HOSTUNREACH = 65, // No route to host + NOTEMPTY = 66, // Directory not empty -// quotas & mush -pub const EPROCLIM = 67; // Too many processes -pub const EUSERS = 68; // Too many users -pub const EDQUOT = 69; // Disc quota exceeded + // quotas & mush + PROCLIM = 67, // Too many processes + USERS = 68, // Too many users + DQUOT = 69, // Disc quota exceeded -// Network File System -pub const ESTALE = 70; // Stale NFS file handle -pub const EREMOTE = 71; // Too many levels of remote in path -pub const EBADRPC = 72; // RPC struct is bad -pub const ERPCMISMATCH = 73; // RPC version wrong -pub const EPROGUNAVAIL = 74; // RPC prog. not avail -pub const EPROGMISMATCH = 75; // Program version wrong -pub const EPROCUNAVAIL = 76; // Bad procedure for program + // Network File System + STALE = 70, // Stale NFS file handle + REMOTE = 71, // Too many levels of remote in path + BADRPC = 72, // RPC struct is bad + RPCMISMATCH = 73, // RPC version wrong + PROGUNAVAIL = 74, // RPC prog. not avail + PROGMISMATCH = 75, // Program version wrong + PROCUNAVAIL = 76, // Bad procedure for program -pub const ENOLCK = 77; // No locks available -pub const ENOSYS = 78; // Function not implemented + NOLCK = 77, // No locks available + NOSYS = 78, // Function not implemented -pub const EFTYPE = 79; // Inappropriate file type or format -pub const EAUTH = 80; // Authentication error -pub const ENEEDAUTH = 81; // Need authenticator + FTYPE = 79, // Inappropriate file type or format + AUTH = 80, // Authentication error + NEEDAUTH = 81, // Need authenticator -// SystemV IPC -pub const EIDRM = 82; // Identifier removed -pub const ENOMSG = 83; // No message of desired type -pub const EOVERFLOW = 84; // Value too large to be stored in data type + // SystemV IPC + IDRM = 82, // Identifier removed + NOMSG = 83, // No message of desired type + OVERFLOW = 84, // Value too large to be stored in data type -// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 -pub const EILSEQ = 85; // Illegal byte sequence + // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 + ILSEQ = 85, // Illegal byte sequence -// From IEEE Std 1003.1-2001 -// Base, Realtime, Threads or Thread Priority Scheduling option errors -pub const ENOTSUP = 86; // Not supported + // From IEEE Std 1003.1-2001 + // Base, Realtime, Threads or Thread Priority Scheduling option errors + NOTSUP = 86, // Not supported -// Realtime option errors -pub const ECANCELED = 87; // Operation canceled + // Realtime option errors + CANCELED = 87, // Operation canceled -// Realtime, XSI STREAMS option errors -pub const EBADMSG = 88; // Bad or Corrupt message + // Realtime, XSI STREAMS option errors + BADMSG = 88, // Bad or Corrupt message -// XSI STREAMS option errors -pub const ENODATA = 89; // No message available -pub const ENOSR = 90; // No STREAM resources -pub const ENOSTR = 91; // Not a STREAM -pub const ETIME = 92; // STREAM ioctl timeout + // XSI STREAMS option errors + NODATA = 89, // No message available + NOSR = 90, // No STREAM resources + NOSTR = 91, // Not a STREAM + TIME = 92, // STREAM ioctl timeout -// File system extended attribute errors -pub const ENOATTR = 93; // Attribute not found + // File system extended attribute errors + NOATTR = 93, // Attribute not found -// Realtime, XSI STREAMS option errors -pub const EMULTIHOP = 94; // Multihop attempted -pub const ENOLINK = 95; // Link has been severed -pub const EPROTO = 96; // Protocol error + // Realtime, XSI STREAMS option errors + MULTIHOP = 94, // Multihop attempted + NOLINK = 95, // Link has been severed + PROTO = 96, // Protocol error -pub const ELAST = 96; // Must equal largest errno + _, +}; pub const MINSIGSTKSZ = 8192; pub const SIGSTKSZ = MINSIGSTKSZ + 32768; diff --git a/lib/std/os/bits/openbsd.zig b/lib/std/os/bits/openbsd.zig index 233ebcbd68..5ad1f8980b 100644 --- a/lib/std/os/bits/openbsd.zig +++ b/lib/std/os/bits/openbsd.zig @@ -295,6 +295,7 @@ pub const AI_NUMERICSERV = 16; pub const AI_ADDRCONFIG = 64; pub const PATH_MAX = 1024; +pub const IOV_MAX = 1024; pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; @@ -824,125 +825,129 @@ pub usingnamespace switch (builtin.target.cpu.arch) { pub const sigset_t = c_uint; pub const empty_sigset: sigset_t = 0; -pub const EPERM = 1; // Operation not permitted -pub const ENOENT = 2; // No such file or directory -pub const ESRCH = 3; // No such process -pub const EINTR = 4; // Interrupted system call -pub const EIO = 5; // Input/output error -pub const ENXIO = 6; // Device not configured -pub const E2BIG = 7; // Argument list too long -pub const ENOEXEC = 8; // Exec format error -pub const EBADF = 9; // Bad file descriptor -pub const ECHILD = 10; // No child processes -pub const EDEADLK = 11; // Resource deadlock avoided -// 11 was EAGAIN -pub const ENOMEM = 12; // Cannot allocate memory -pub const EACCES = 13; // Permission denied -pub const EFAULT = 14; // Bad address -pub const ENOTBLK = 15; // Block device required -pub const EBUSY = 16; // Device busy -pub const EEXIST = 17; // File exists -pub const EXDEV = 18; // Cross-device link -pub const ENODEV = 19; // Operation not supported by device -pub const ENOTDIR = 20; // Not a directory -pub const EISDIR = 21; // Is a directory -pub const EINVAL = 22; // Invalid argument -pub const ENFILE = 23; // Too many open files in system -pub const EMFILE = 24; // Too many open files -pub const ENOTTY = 25; // Inappropriate ioctl for device -pub const ETXTBSY = 26; // Text file busy -pub const EFBIG = 27; // File too large -pub const ENOSPC = 28; // No space left on device -pub const ESPIPE = 29; // Illegal seek -pub const EROFS = 30; // Read-only file system -pub const EMLINK = 31; // Too many links -pub const EPIPE = 32; // Broken pipe +pub const E = enum(u16) { + /// No error occurred. + SUCCESS = 0, + PERM = 1, // Operation not permitted + NOENT = 2, // No such file or directory + SRCH = 3, // No such process + INTR = 4, // Interrupted system call + IO = 5, // Input/output error + NXIO = 6, // Device not configured + @"2BIG" = 7, // Argument list too long + NOEXEC = 8, // Exec format error + BADF = 9, // Bad file descriptor + CHILD = 10, // No child processes + DEADLK = 11, // Resource deadlock avoided + // 11 was AGAIN + NOMEM = 12, // Cannot allocate memory + ACCES = 13, // Permission denied + FAULT = 14, // Bad address + NOTBLK = 15, // Block device required + BUSY = 16, // Device busy + EXIST = 17, // File exists + XDEV = 18, // Cross-device link + NODEV = 19, // Operation not supported by device + NOTDIR = 20, // Not a directory + ISDIR = 21, // Is a directory + INVAL = 22, // Invalid argument + NFILE = 23, // Too many open files in system + MFILE = 24, // Too many open files + NOTTY = 25, // Inappropriate ioctl for device + TXTBSY = 26, // Text file busy + FBIG = 27, // File too large + NOSPC = 28, // No space left on device + SPIPE = 29, // Illegal seek + ROFS = 30, // Read-only file system + MLINK = 31, // Too many links + PIPE = 32, // Broken pipe -// math software -pub const EDOM = 33; // Numerical argument out of domain -pub const ERANGE = 34; // Result too large or too small + // math software + DOM = 33, // Numerical argument out of domain + RANGE = 34, // Result too large or too small -// non-blocking and interrupt i/o -pub const EAGAIN = 35; // Resource temporarily unavailable -pub const EWOULDBLOCK = EAGAIN; // Operation would block -pub const EINPROGRESS = 36; // Operation now in progress -pub const EALREADY = 37; // Operation already in progress + // non-blocking and interrupt i/o + // also: WOULDBLOCK: operation would block + AGAIN = 35, // Resource temporarily unavailable + INPROGRESS = 36, // Operation now in progress + ALREADY = 37, // Operation already in progress -// ipc/network software -- argument errors -pub const ENOTSOCK = 38; // Socket operation on non-socket -pub const EDESTADDRREQ = 39; // Destination address required -pub const EMSGSIZE = 40; // Message too long -pub const EPROTOTYPE = 41; // Protocol wrong type for socket -pub const ENOPROTOOPT = 42; // Protocol option not available -pub const EPROTONOSUPPORT = 43; // Protocol not supported -pub const ESOCKTNOSUPPORT = 44; // Socket type not supported -pub const EOPNOTSUPP = 45; // Operation not supported -pub const EPFNOSUPPORT = 46; // Protocol family not supported -pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family -pub const EADDRINUSE = 48; // Address already in use -pub const EADDRNOTAVAIL = 49; // Can't assign requested address + // ipc/network software -- argument errors + NOTSOCK = 38, // Socket operation on non-socket + DESTADDRREQ = 39, // Destination address required + MSGSIZE = 40, // Message too long + PROTOTYPE = 41, // Protocol wrong type for socket + NOPROTOOPT = 42, // Protocol option not available + PROTONOSUPPORT = 43, // Protocol not supported + SOCKTNOSUPPORT = 44, // Socket type not supported + OPNOTSUPP = 45, // Operation not supported + PFNOSUPPORT = 46, // Protocol family not supported + AFNOSUPPORT = 47, // Address family not supported by protocol family + ADDRINUSE = 48, // Address already in use + ADDRNOTAVAIL = 49, // Can't assign requested address -// ipc/network software -- operational errors -pub const ENETDOWN = 50; // Network is down -pub const ENETUNREACH = 51; // Network is unreachable -pub const ENETRESET = 52; // Network dropped connection on reset -pub const ECONNABORTED = 53; // Software caused connection abort -pub const ECONNRESET = 54; // Connection reset by peer -pub const ENOBUFS = 55; // No buffer space available -pub const EISCONN = 56; // Socket is already connected -pub const ENOTCONN = 57; // Socket is not connected -pub const ESHUTDOWN = 58; // Can't send after socket shutdown -pub const ETOOMANYREFS = 59; // Too many references: can't splice -pub const ETIMEDOUT = 60; // Operation timed out -pub const ECONNREFUSED = 61; // Connection refused + // ipc/network software -- operational errors + NETDOWN = 50, // Network is down + NETUNREACH = 51, // Network is unreachable + NETRESET = 52, // Network dropped connection on reset + CONNABORTED = 53, // Software caused connection abort + CONNRESET = 54, // Connection reset by peer + NOBUFS = 55, // No buffer space available + ISCONN = 56, // Socket is already connected + NOTCONN = 57, // Socket is not connected + SHUTDOWN = 58, // Can't send after socket shutdown + TOOMANYREFS = 59, // Too many references: can't splice + TIMEDOUT = 60, // Operation timed out + CONNREFUSED = 61, // Connection refused -pub const ELOOP = 62; // Too many levels of symbolic links -pub const ENAMETOOLONG = 63; // File name too long + LOOP = 62, // Too many levels of symbolic links + NAMETOOLONG = 63, // File name too long -// should be rearranged -pub const EHOSTDOWN = 64; // Host is down -pub const EHOSTUNREACH = 65; // No route to host -pub const ENOTEMPTY = 66; // Directory not empty + // should be rearranged + HOSTDOWN = 64, // Host is down + HOSTUNREACH = 65, // No route to host + NOTEMPTY = 66, // Directory not empty -// quotas & mush -pub const EPROCLIM = 67; // Too many processes -pub const EUSERS = 68; // Too many users -pub const EDQUOT = 69; // Disc quota exceeded + // quotas & mush + PROCLIM = 67, // Too many processes + USERS = 68, // Too many users + DQUOT = 69, // Disc quota exceeded -// Network File System -pub const ESTALE = 70; // Stale NFS file handle -pub const EREMOTE = 71; // Too many levels of remote in path -pub const EBADRPC = 72; // RPC struct is bad -pub const ERPCMISMATCH = 73; // RPC version wrong -pub const EPROGUNAVAIL = 74; // RPC prog. not avail -pub const EPROGMISMATCH = 75; // Program version wrong -pub const EPROCUNAVAIL = 76; // Bad procedure for program + // Network File System + STALE = 70, // Stale NFS file handle + REMOTE = 71, // Too many levels of remote in path + BADRPC = 72, // RPC struct is bad + RPCMISMATCH = 73, // RPC version wrong + PROGUNAVAIL = 74, // RPC prog. not avail + PROGMISMATCH = 75, // Program version wrong + PROCUNAVAIL = 76, // Bad procedure for program -pub const ENOLCK = 77; // No locks available -pub const ENOSYS = 78; // Function not implemented + NOLCK = 77, // No locks available + NOSYS = 78, // Function not implemented -pub const EFTYPE = 79; // Inappropriate file type or format -pub const EAUTH = 80; // Authentication error -pub const ENEEDAUTH = 81; // Need authenticator -pub const EIPSEC = 82; // IPsec processing failure -pub const ENOATTR = 83; // Attribute not found + FTYPE = 79, // Inappropriate file type or format + AUTH = 80, // Authentication error + NEEDAUTH = 81, // Need authenticator + IPSEC = 82, // IPsec processing failure + NOATTR = 83, // Attribute not found -// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 -pub const EILSEQ = 84; // Illegal byte sequence + // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 + ILSEQ = 84, // Illegal byte sequence -pub const ENOMEDIUM = 85; // No medium found -pub const EMEDIUMTYPE = 86; // Wrong medium type -pub const EOVERFLOW = 87; // Value too large to be stored in data type -pub const ECANCELED = 88; // Operation canceled -pub const EIDRM = 89; // Identifier removed -pub const ENOMSG = 90; // No message of desired type -pub const ENOTSUP = 91; // Not supported -pub const EBADMSG = 92; // Bad or Corrupt message -pub const ENOTRECOVERABLE = 93; // State not recoverable -pub const EOWNERDEAD = 94; // Previous owner died -pub const EPROTO = 95; // Protocol error + NOMEDIUM = 85, // No medium found + MEDIUMTYPE = 86, // Wrong medium type + OVERFLOW = 87, // Value too large to be stored in data type + CANCELED = 88, // Operation canceled + IDRM = 89, // Identifier removed + NOMSG = 90, // No message of desired type + NOTSUP = 91, // Not supported + BADMSG = 92, // Bad or Corrupt message + NOTRECOVERABLE = 93, // State not recoverable + OWNERDEAD = 94, // Previous owner died + PROTO = 95, // Protocol error -pub const ELAST = 95; // Must equal largest errno + _, +}; const _MAX_PAGE_SHIFT = switch (builtin.target.cpu.arch) { .i386 => 12, diff --git a/lib/std/os/bits/wasi.zig b/lib/std/os/bits/wasi.zig index ece97eacce..eb68946f05 100644 --- a/lib/std/os/bits/wasi.zig +++ b/lib/std/os/bits/wasi.zig @@ -111,86 +111,89 @@ pub const dirent_t = extern struct { d_type: filetype_t, }; -pub const errno_t = u16; -pub const ESUCCESS: errno_t = 0; -pub const E2BIG: errno_t = 1; -pub const EACCES: errno_t = 2; -pub const EADDRINUSE: errno_t = 3; -pub const EADDRNOTAVAIL: errno_t = 4; -pub const EAFNOSUPPORT: errno_t = 5; -pub const EAGAIN: errno_t = 6; -pub const EWOULDBLOCK = EAGAIN; -pub const EALREADY: errno_t = 7; -pub const EBADF: errno_t = 8; -pub const EBADMSG: errno_t = 9; -pub const EBUSY: errno_t = 10; -pub const ECANCELED: errno_t = 11; -pub const ECHILD: errno_t = 12; -pub const ECONNABORTED: errno_t = 13; -pub const ECONNREFUSED: errno_t = 14; -pub const ECONNRESET: errno_t = 15; -pub const EDEADLK: errno_t = 16; -pub const EDESTADDRREQ: errno_t = 17; -pub const EDOM: errno_t = 18; -pub const EDQUOT: errno_t = 19; -pub const EEXIST: errno_t = 20; -pub const EFAULT: errno_t = 21; -pub const EFBIG: errno_t = 22; -pub const EHOSTUNREACH: errno_t = 23; -pub const EIDRM: errno_t = 24; -pub const EILSEQ: errno_t = 25; -pub const EINPROGRESS: errno_t = 26; -pub const EINTR: errno_t = 27; -pub const EINVAL: errno_t = 28; -pub const EIO: errno_t = 29; -pub const EISCONN: errno_t = 30; -pub const EISDIR: errno_t = 31; -pub const ELOOP: errno_t = 32; -pub const EMFILE: errno_t = 33; -pub const EMLINK: errno_t = 34; -pub const EMSGSIZE: errno_t = 35; -pub const EMULTIHOP: errno_t = 36; -pub const ENAMETOOLONG: errno_t = 37; -pub const ENETDOWN: errno_t = 38; -pub const ENETRESET: errno_t = 39; -pub const ENETUNREACH: errno_t = 40; -pub const ENFILE: errno_t = 41; -pub const ENOBUFS: errno_t = 42; -pub const ENODEV: errno_t = 43; -pub const ENOENT: errno_t = 44; -pub const ENOEXEC: errno_t = 45; -pub const ENOLCK: errno_t = 46; -pub const ENOLINK: errno_t = 47; -pub const ENOMEM: errno_t = 48; -pub const ENOMSG: errno_t = 49; -pub const ENOPROTOOPT: errno_t = 50; -pub const ENOSPC: errno_t = 51; -pub const ENOSYS: errno_t = 52; -pub const ENOTCONN: errno_t = 53; -pub const ENOTDIR: errno_t = 54; -pub const ENOTEMPTY: errno_t = 55; -pub const ENOTRECOVERABLE: errno_t = 56; -pub const ENOTSOCK: errno_t = 57; -pub const ENOTSUP: errno_t = 58; -pub const EOPNOTSUPP = ENOTSUP; -pub const ENOTTY: errno_t = 59; -pub const ENXIO: errno_t = 60; -pub const EOVERFLOW: errno_t = 61; -pub const EOWNERDEAD: errno_t = 62; -pub const EPERM: errno_t = 63; -pub const EPIPE: errno_t = 64; -pub const EPROTO: errno_t = 65; -pub const EPROTONOSUPPORT: errno_t = 66; -pub const EPROTOTYPE: errno_t = 67; -pub const ERANGE: errno_t = 68; -pub const EROFS: errno_t = 69; -pub const ESPIPE: errno_t = 70; -pub const ESRCH: errno_t = 71; -pub const ESTALE: errno_t = 72; -pub const ETIMEDOUT: errno_t = 73; -pub const ETXTBSY: errno_t = 74; -pub const EXDEV: errno_t = 75; -pub const ENOTCAPABLE: errno_t = 76; +pub const errno_t = enum(u16) { + SUCCESS = 0, + @"2BIG" = 1, + ACCES = 2, + ADDRINUSE = 3, + ADDRNOTAVAIL = 4, + AFNOSUPPORT = 5, + /// This is also the error code used for `WOULDBLOCK`. + AGAIN = 6, + ALREADY = 7, + BADF = 8, + BADMSG = 9, + BUSY = 10, + CANCELED = 11, + CHILD = 12, + CONNABORTED = 13, + CONNREFUSED = 14, + CONNRESET = 15, + DEADLK = 16, + DESTADDRREQ = 17, + DOM = 18, + DQUOT = 19, + EXIST = 20, + FAULT = 21, + FBIG = 22, + HOSTUNREACH = 23, + IDRM = 24, + ILSEQ = 25, + INPROGRESS = 26, + INTR = 27, + INVAL = 28, + IO = 29, + ISCONN = 30, + ISDIR = 31, + LOOP = 32, + MFILE = 33, + MLINK = 34, + MSGSIZE = 35, + MULTIHOP = 36, + NAMETOOLONG = 37, + NETDOWN = 38, + NETRESET = 39, + NETUNREACH = 40, + NFILE = 41, + NOBUFS = 42, + NODEV = 43, + NOENT = 44, + NOEXEC = 45, + NOLCK = 46, + NOLINK = 47, + NOMEM = 48, + NOMSG = 49, + NOPROTOOPT = 50, + NOSPC = 51, + NOSYS = 52, + NOTCONN = 53, + NOTDIR = 54, + NOTEMPTY = 55, + NOTRECOVERABLE = 56, + NOTSOCK = 57, + /// This is also the code used for `NOTSUP`. + OPNOTSUPP = 58, + NOTTY = 59, + NXIO = 60, + OVERFLOW = 61, + OWNERDEAD = 62, + PERM = 63, + PIPE = 64, + PROTO = 65, + PROTONOSUPPORT = 66, + PROTOTYPE = 67, + RANGE = 68, + ROFS = 69, + SPIPE = 70, + SRCH = 71, + STALE = 72, + TIMEDOUT = 73, + TXTBSY = 74, + XDEV = 75, + NOTCAPABLE = 76, + _, +}; +pub const E = errno_t; pub const event_t = extern struct { userdata: userdata_t, diff --git a/lib/std/os/bits/windows.zig b/lib/std/os/bits/windows.zig index 05c50ffe47..3943d1fd3d 100644 --- a/lib/std/os/bits/windows.zig +++ b/lib/std/os/bits/windows.zig @@ -87,94 +87,98 @@ pub const SEEK_SET = 0; pub const SEEK_CUR = 1; pub const SEEK_END = 2; -pub const EPERM = 1; -pub const ENOENT = 2; -pub const ESRCH = 3; -pub const EINTR = 4; -pub const EIO = 5; -pub const ENXIO = 6; -pub const E2BIG = 7; -pub const ENOEXEC = 8; -pub const EBADF = 9; -pub const ECHILD = 10; -pub const EAGAIN = 11; -pub const ENOMEM = 12; -pub const EACCES = 13; -pub const EFAULT = 14; -pub const EBUSY = 16; -pub const EEXIST = 17; -pub const EXDEV = 18; -pub const ENODEV = 19; -pub const ENOTDIR = 20; -pub const EISDIR = 21; -pub const ENFILE = 23; -pub const EMFILE = 24; -pub const ENOTTY = 25; -pub const EFBIG = 27; -pub const ENOSPC = 28; -pub const ESPIPE = 29; -pub const EROFS = 30; -pub const EMLINK = 31; -pub const EPIPE = 32; -pub const EDOM = 33; -pub const EDEADLK = 36; -pub const ENAMETOOLONG = 38; -pub const ENOLCK = 39; -pub const ENOSYS = 40; -pub const ENOTEMPTY = 41; +pub const E = enum(u16) { + /// No error occurred. + SUCCESS = 0, + PERM = 1, + NOENT = 2, + SRCH = 3, + INTR = 4, + IO = 5, + NXIO = 6, + @"2BIG" = 7, + NOEXEC = 8, + BADF = 9, + CHILD = 10, + AGAIN = 11, + NOMEM = 12, + ACCES = 13, + FAULT = 14, + BUSY = 16, + EXIST = 17, + XDEV = 18, + NODEV = 19, + NOTDIR = 20, + ISDIR = 21, + NFILE = 23, + MFILE = 24, + NOTTY = 25, + FBIG = 27, + NOSPC = 28, + SPIPE = 29, + ROFS = 30, + MLINK = 31, + PIPE = 32, + DOM = 33, + /// Also means `DEADLOCK`. + DEADLK = 36, + NAMETOOLONG = 38, + NOLCK = 39, + NOSYS = 40, + NOTEMPTY = 41, + + INVAL = 22, + RANGE = 34, + ILSEQ = 42, + + // POSIX Supplement + ADDRINUSE = 100, + ADDRNOTAVAIL = 101, + AFNOSUPPORT = 102, + ALREADY = 103, + BADMSG = 104, + CANCELED = 105, + CONNABORTED = 106, + CONNREFUSED = 107, + CONNRESET = 108, + DESTADDRREQ = 109, + HOSTUNREACH = 110, + IDRM = 111, + INPROGRESS = 112, + ISCONN = 113, + LOOP = 114, + MSGSIZE = 115, + NETDOWN = 116, + NETRESET = 117, + NETUNREACH = 118, + NOBUFS = 119, + NODATA = 120, + NOLINK = 121, + NOMSG = 122, + NOPROTOOPT = 123, + NOSR = 124, + NOSTR = 125, + NOTCONN = 126, + NOTRECOVERABLE = 127, + NOTSOCK = 128, + NOTSUP = 129, + OPNOTSUPP = 130, + OTHER = 131, + OVERFLOW = 132, + OWNERDEAD = 133, + PROTO = 134, + PROTONOSUPPORT = 135, + PROTOTYPE = 136, + TIME = 137, + TIMEDOUT = 138, + TXTBSY = 139, + WOULDBLOCK = 140, + DQUOT = 10069, + _, +}; -pub const EINVAL = 22; -pub const ERANGE = 34; -pub const EILSEQ = 42; pub const STRUNCATE = 80; -// Support EDEADLOCK for compatibility with older Microsoft C versions -pub const EDEADLOCK = EDEADLK; - -// POSIX Supplement -pub const EADDRINUSE = 100; -pub const EADDRNOTAVAIL = 101; -pub const EAFNOSUPPORT = 102; -pub const EALREADY = 103; -pub const EBADMSG = 104; -pub const ECANCELED = 105; -pub const ECONNABORTED = 106; -pub const ECONNREFUSED = 107; -pub const ECONNRESET = 108; -pub const EDESTADDRREQ = 109; -pub const EHOSTUNREACH = 110; -pub const EIDRM = 111; -pub const EINPROGRESS = 112; -pub const EISCONN = 113; -pub const ELOOP = 114; -pub const EMSGSIZE = 115; -pub const ENETDOWN = 116; -pub const ENETRESET = 117; -pub const ENETUNREACH = 118; -pub const ENOBUFS = 119; -pub const ENODATA = 120; -pub const ENOLINK = 121; -pub const ENOMSG = 122; -pub const ENOPROTOOPT = 123; -pub const ENOSR = 124; -pub const ENOSTR = 125; -pub const ENOTCONN = 126; -pub const ENOTRECOVERABLE = 127; -pub const ENOTSOCK = 128; -pub const ENOTSUP = 129; -pub const EOPNOTSUPP = 130; -pub const EOTHER = 131; -pub const EOVERFLOW = 132; -pub const EOWNERDEAD = 133; -pub const EPROTO = 134; -pub const EPROTONOSUPPORT = 135; -pub const EPROTOTYPE = 136; -pub const ETIME = 137; -pub const ETIMEDOUT = 138; -pub const ETXTBSY = 139; -pub const EWOULDBLOCK = 140; -pub const EDQUOT = 10069; - pub const F_OK = 0; /// Remove directory instead of unlinking file diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index ca8f0907e1..841f77467c 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -91,9 +91,10 @@ fn splitValue64(val: i64) [2]u32 { } /// Get the errno from a syscall return value, or 0 for no error. -pub fn getErrno(r: usize) u12 { +pub fn getErrno(r: usize) E { const signed_r = @bitCast(isize, r); - return if (signed_r > -4096 and signed_r < 0) @intCast(u12, -signed_r) else 0; + const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0; + return @intToEnum(E, int); } pub fn dup(old: i32) usize { @@ -281,7 +282,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of if (@hasField(SYS, "mmap2")) { // Make sure the offset is also specified in multiples of page size if ((offset & (MMAP2_UNIT - 1)) != 0) - return @bitCast(usize, @as(isize, -EINVAL)); + return @bitCast(usize, -@as(isize, @enumToInt(E.INVAL))); return syscall6( .mmap2, @@ -746,7 +747,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); const rc = f(clk_id, tp); switch (rc) { - 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc, + 0, @bitCast(usize, -@as(isize, @enumToInt(E.INVAL))) => return rc, else => {}, } } @@ -764,7 +765,7 @@ fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize { const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); return f(clk, ts); } - return @bitCast(usize, @as(isize, -ENOSYS)); + return @bitCast(usize, -@as(isize, @enumToInt(E.NOSYS))); } pub 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 .sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size), else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size), }; - if (getErrno(result) != 0) return result; + if (getErrno(result) != .SUCCESS) return result; if (oact) |old| { old.handler.handler = oldksa.handler; @@ -1202,7 +1203,7 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S @ptrToInt(statx_buf), ); } - return @bitCast(usize, @as(isize, -ENOSYS)); + return @bitCast(usize, -@as(isize, @enumToInt(E.NOSYS))); } pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize { diff --git a/lib/std/os/linux/bpf.zig b/lib/std/os/linux/bpf.zig index 86993083e3..8afd851629 100644 --- a/lib/std/os/linux/bpf.zig +++ b/lib/std/os/linux/bpf.zig @@ -1508,13 +1508,13 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries attr.map_create.max_entries = max_entries; const rc = bpf(.map_create, &attr, @sizeOf(MapCreateAttr)); - return switch (errno(rc)) { - 0 => @intCast(fd_t, rc), - EINVAL => error.MapTypeOrAttrInvalid, - ENOMEM => error.SystemResources, - EPERM => error.AccessDenied, - else => |err| unexpectedErrno(err), - }; + switch (errno(rc)) { + .SUCCESS => return @intCast(fd_t, rc), + .INVAL => return error.MapTypeOrAttrInvalid, + .NOMEM => return error.SystemResources, + .PERM => return error.AccessDenied, + else => |err| return unexpectedErrno(err), + } } test "map_create" { @@ -1533,12 +1533,12 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void { const rc = bpf(.map_lookup_elem, &attr, @sizeOf(MapElemAttr)); switch (errno(rc)) { - 0 => return, - EBADF => return error.BadFd, - EFAULT => unreachable, - EINVAL => return error.FieldInAttrNeedsZeroing, - ENOENT => return error.NotFound, - EPERM => return error.AccessDenied, + .SUCCESS => return, + .BADF => return error.BadFd, + .FAULT => unreachable, + .INVAL => return error.FieldInAttrNeedsZeroing, + .NOENT => return error.NotFound, + .PERM => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -1555,13 +1555,13 @@ pub fn map_update_elem(fd: fd_t, key: []const u8, value: []const u8, flags: u64) const rc = bpf(.map_update_elem, &attr, @sizeOf(MapElemAttr)); switch (errno(rc)) { - 0 => return, - E2BIG => return error.ReachedMaxEntries, - EBADF => return error.BadFd, - EFAULT => unreachable, - EINVAL => return error.FieldInAttrNeedsZeroing, - ENOMEM => return error.SystemResources, - EPERM => return error.AccessDenied, + .SUCCESS => return, + .@"2BIG" => return error.ReachedMaxEntries, + .BADF => return error.BadFd, + .FAULT => unreachable, + .INVAL => return error.FieldInAttrNeedsZeroing, + .NOMEM => return error.SystemResources, + .PERM => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -1576,12 +1576,12 @@ pub fn map_delete_elem(fd: fd_t, key: []const u8) !void { const rc = bpf(.map_delete_elem, &attr, @sizeOf(MapElemAttr)); switch (errno(rc)) { - 0 => return, - EBADF => return error.BadFd, - EFAULT => unreachable, - EINVAL => return error.FieldInAttrNeedsZeroing, - ENOENT => return error.NotFound, - EPERM => return error.AccessDenied, + .SUCCESS => return, + .BADF => return error.BadFd, + .FAULT => unreachable, + .INVAL => return error.FieldInAttrNeedsZeroing, + .NOENT => return error.NotFound, + .PERM => return error.AccessDenied, else => |err| return unexpectedErrno(err), } } @@ -1639,11 +1639,11 @@ pub fn prog_load( const rc = bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr)); return switch (errno(rc)) { - 0 => @intCast(fd_t, rc), - EACCES => error.UnsafeProgram, - EFAULT => unreachable, - EINVAL => error.InvalidProgram, - EPERM => error.AccessDenied, + .SUCCESS => @intCast(fd_t, rc), + .ACCES => error.UnsafeProgram, + .FAULT => unreachable, + .INVAL => error.InvalidProgram, + .PERM => error.AccessDenied, else => |err| unexpectedErrno(err), }; } diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index b6bde34b7d..1db4c30d2a 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -54,19 +54,19 @@ pub const IO_Uring = struct { const res = linux.io_uring_setup(entries, p); switch (linux.getErrno(res)) { - 0 => {}, - linux.EFAULT => return error.ParamsOutsideAccessibleAddressSpace, + .SUCCESS => {}, + .FAULT => return error.ParamsOutsideAccessibleAddressSpace, // The resv array contains non-zero data, p.flags contains an unsupported flag, // entries out of bounds, IORING_SETUP_SQ_AFF was specified without IORING_SETUP_SQPOLL, // or IORING_SETUP_CQSIZE was specified but io_uring_params.cq_entries was invalid: - linux.EINVAL => return error.ArgumentsInvalid, - linux.EMFILE => return error.ProcessFdQuotaExceeded, - linux.ENFILE => return error.SystemFdQuotaExceeded, - linux.ENOMEM => return error.SystemResources, + .INVAL => return error.ArgumentsInvalid, + .MFILE => return error.ProcessFdQuotaExceeded, + .NFILE => return error.SystemFdQuotaExceeded, + .NOMEM => return error.SystemResources, // IORING_SETUP_SQPOLL was specified but effective user ID lacks sufficient privileges, // or a container seccomp policy prohibits io_uring syscalls: - linux.EPERM => return error.PermissionDenied, - linux.ENOSYS => return error.SystemOutdated, + .PERM => return error.PermissionDenied, + .NOSYS => return error.SystemOutdated, else => |errno| return os.unexpectedErrno(errno), } const fd = @intCast(os.fd_t, res); @@ -180,31 +180,31 @@ pub const IO_Uring = struct { assert(self.fd >= 0); const res = linux.io_uring_enter(self.fd, to_submit, min_complete, flags, null); switch (linux.getErrno(res)) { - 0 => {}, + .SUCCESS => {}, // The kernel was unable to allocate memory or ran out of resources for the request. // The application should wait for some completions and try again: - linux.EAGAIN => return error.SystemResources, + .AGAIN => return error.SystemResources, // The SQE `fd` is invalid, or IOSQE_FIXED_FILE was set but no files were registered: - linux.EBADF => return error.FileDescriptorInvalid, + .BADF => return error.FileDescriptorInvalid, // The file descriptor is valid, but the ring is not in the right state. // See io_uring_register(2) for how to enable the ring. - linux.EBADFD => return error.FileDescriptorInBadState, + .BADFD => return error.FileDescriptorInBadState, // The application attempted to overcommit the number of requests it can have pending. // The application should wait for some completions and try again: - linux.EBUSY => return error.CompletionQueueOvercommitted, + .BUSY => return error.CompletionQueueOvercommitted, // The SQE is invalid, or valid but the ring was setup with IORING_SETUP_IOPOLL: - linux.EINVAL => return error.SubmissionQueueEntryInvalid, + .INVAL => return error.SubmissionQueueEntryInvalid, // The buffer is outside the process' accessible address space, or IORING_OP_READ_FIXED // or IORING_OP_WRITE_FIXED was specified but no buffers were registered, or the range // described by `addr` and `len` is not within the buffer registered at `buf_index`: - linux.EFAULT => return error.BufferInvalid, - linux.ENXIO => return error.RingShuttingDown, + .FAULT => return error.BufferInvalid, + .NXIO => return error.RingShuttingDown, // The kernel believes our `self.fd` does not refer to an io_uring instance, // or the opcode is valid but not supported by this kernel (more likely): - linux.EOPNOTSUPP => return error.OpcodeNotSupported, + .OPNOTSUPP => return error.OpcodeNotSupported, // The operation was interrupted by a delivery of a signal before it could complete. // This can happen while waiting for events with IORING_ENTER_GETEVENTS: - linux.EINTR => return error.SignalInterrupt, + .INTR => return error.SignalInterrupt, else => |errno| return os.unexpectedErrno(errno), } return @intCast(u32, res); @@ -681,22 +681,22 @@ pub const IO_Uring = struct { fn handle_registration_result(res: usize) !void { switch (linux.getErrno(res)) { - 0 => {}, + .SUCCESS => {}, // One or more fds in the array are invalid, or the kernel does not support sparse sets: - linux.EBADF => return error.FileDescriptorInvalid, - linux.EBUSY => return error.FilesAlreadyRegistered, - linux.EINVAL => return error.FilesEmpty, + .BADF => return error.FileDescriptorInvalid, + .BUSY => return error.FilesAlreadyRegistered, + .INVAL => return error.FilesEmpty, // Adding `nr_args` file references would exceed the maximum allowed number of files the // user is allowed to have according to the per-user RLIMIT_NOFILE resource limit and // the CAP_SYS_RESOURCE capability is not set, or `nr_args` exceeds the maximum allowed // for a fixed file set (older kernels have a limit of 1024 files vs 64K files): - linux.EMFILE => return error.UserFdQuotaExceeded, + .MFILE => return error.UserFdQuotaExceeded, // Insufficient kernel resources, or the caller had a non-zero RLIMIT_MEMLOCK soft // resource limit but tried to lock more memory than the limit permitted (not enforced // when the process is privileged with CAP_IPC_LOCK): - linux.ENOMEM => return error.SystemResources, + .NOMEM => return error.SystemResources, // Attempt to register files on a ring already registering files or being torn down: - linux.ENXIO => return error.RingShuttingDownOrAlreadyRegisteringFiles, + .NXIO => return error.RingShuttingDownOrAlreadyRegisteringFiles, else => |errno| return os.unexpectedErrno(errno), } } @@ -706,8 +706,8 @@ pub const IO_Uring = struct { assert(self.fd >= 0); const res = linux.io_uring_register(self.fd, .UNREGISTER_FILES, null, 0); switch (linux.getErrno(res)) { - 0 => {}, - linux.ENXIO => return error.FilesNotRegistered, + .SUCCESS => {}, + .NXIO => return error.FilesNotRegistered, else => |errno| return os.unexpectedErrno(errno), } } @@ -1272,8 +1272,8 @@ test "write/read" { const cqe_read = try ring.copy_cqe(); // Prior to Linux Kernel 5.6 this is the only way to test for read/write support: // https://lwn.net/Articles/809820/ - if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest; - if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest; + if (cqe_write.err() == .INVAL) return error.SkipZigTest; + if (cqe_read.err() == .INVAL) return error.SkipZigTest; try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0x11111111, .res = buffer_write.len, @@ -1322,11 +1322,11 @@ test "openat" { const cqe_openat = try ring.copy_cqe(); try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data); - if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest; + if (cqe_openat.err() == .INVAL) return error.SkipZigTest; // AT_FDCWD is not fully supported before kernel 5.6: // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/ // We use IORING_FEAT_RW_CUR_POS to know if we are pre-5.6 since that feature was added in 5.6. - if (cqe_openat.res == -linux.EBADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) { + if (cqe_openat.err() == .BADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) { return error.SkipZigTest; } if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res}); @@ -1357,7 +1357,7 @@ test "close" { try testing.expectEqual(@as(u32, 1), try ring.submit()); const cqe_close = try ring.copy_cqe(); - if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest; + if (cqe_close.err() == .INVAL) return error.SkipZigTest; try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0x44444444, .res = 0, @@ -1397,9 +1397,9 @@ test "accept/connect/send/recv" { try testing.expectEqual(@as(u32, 1), try ring.submit()); var cqe_accept = try ring.copy_cqe(); - if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest; + if (cqe_accept.err() == .INVAL) return error.SkipZigTest; var cqe_connect = try ring.copy_cqe(); - if (cqe_connect.res == -linux.EINVAL) return error.SkipZigTest; + if (cqe_connect.err() == .INVAL) return error.SkipZigTest; // The accept/connect CQEs may arrive in any order, the connect CQE will sometimes come first: if (cqe_accept.user_data == 0xcccccccc and cqe_connect.user_data == 0xaaaaaaaa) { @@ -1425,7 +1425,7 @@ test "accept/connect/send/recv" { try testing.expectEqual(@as(u32, 2), try ring.submit()); const cqe_send = try ring.copy_cqe(); - if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest; + if (cqe_send.err() == .INVAL) return error.SkipZigTest; try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0xeeeeeeee, .res = buffer_send.len, @@ -1433,7 +1433,7 @@ test "accept/connect/send/recv" { }, cqe_send); const cqe_recv = try ring.copy_cqe(); - if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest; + if (cqe_recv.err() == .INVAL) return error.SkipZigTest; try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0xffffffff, .res = buffer_recv.len, @@ -1466,7 +1466,7 @@ test "timeout (after a relative time)" { try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0x55555555, - .res = -linux.ETIME, + .res = -@as(i32, @enumToInt(linux.E.TIME)), .flags = 0, }, cqe); @@ -1535,14 +1535,14 @@ test "timeout_remove" { // We use IORING_FEAT_RW_CUR_POS as a safety check here to make sure we are at least pre-5.6. // We don't want to skip this test for newer kernels. if (cqe_timeout.user_data == 0x99999999 and - cqe_timeout.res == -linux.EBADF and + cqe_timeout.err() == .BADF and (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0) { return error.SkipZigTest; } try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0x88888888, - .res = -linux.ECANCELED, + .res = -@as(i32, @enumToInt(linux.E.CANCELED)), .flags = 0, }, cqe_timeout); @@ -1578,15 +1578,15 @@ test "fallocate" { try testing.expectEqual(@as(u32, 1), try ring.submit()); const cqe = try ring.copy_cqe(); - switch (-cqe.res) { - 0 => {}, + switch (cqe.err()) { + .SUCCESS => {}, // This kernel's io_uring does not yet implement fallocate(): - linux.EINVAL => return error.SkipZigTest, + .INVAL => return error.SkipZigTest, // This kernel does not implement fallocate(): - linux.ENOSYS => return error.SkipZigTest, + .NOSYS => return error.SkipZigTest, // The filesystem containing the file referred to by fd does not support this operation; // or the mode is not supported by the filesystem containing the file referred to by fd: - linux.EOPNOTSUPP => return error.SkipZigTest, + .OPNOTSUPP => return error.SkipZigTest, else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), } try testing.expectEqual(linux.io_uring_cqe{ diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index 2e98fe359d..8efa6c754f 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -22,9 +22,9 @@ test "fallocate" { const len: i64 = 65536; switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) { - 0 => {}, - linux.ENOSYS => return error.SkipZigTest, - linux.EOPNOTSUPP => return error.SkipZigTest, + .SUCCESS => {}, + .NOSYS => return error.SkipZigTest, + .OPNOTSUPP => return error.SkipZigTest, else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), } @@ -37,11 +37,11 @@ test "getpid" { test "timer" { const epoll_fd = linux.epoll_create(); - var err: usize = linux.getErrno(epoll_fd); - try expect(err == 0); + var err: linux.E = linux.getErrno(epoll_fd); + try expect(err == .SUCCESS); const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0); - try expect(linux.getErrno(timer_fd) == 0); + try expect(linux.getErrno(timer_fd) == .SUCCESS); const time_interval = linux.timespec{ .tv_sec = 0, @@ -53,22 +53,22 @@ test "timer" { .it_value = time_interval, }; - err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null); - try expect(err == 0); + err = linux.getErrno(linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null)); + try expect(err == .SUCCESS); var event = linux.epoll_event{ .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET, .data = linux.epoll_data{ .ptr = 0 }, }; - err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event); - try expect(err == 0); + err = linux.getErrno(linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event)); + try expect(err == .SUCCESS); const events_one: linux.epoll_event = undefined; var events = [_]linux.epoll_event{events_one} ** 8; - // TODO implicit cast from *[N]T to [*]T - err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1); + err = linux.getErrno(linux.epoll_wait(@intCast(i32, epoll_fd), &events, 8, -1)); + try expect(err == .SUCCESS); } test "statx" { @@ -81,15 +81,15 @@ test "statx" { var statx_buf: linux.Statx = undefined; switch (linux.getErrno(linux.statx(file.handle, "", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) { - 0 => {}, + .SUCCESS => {}, // The statx syscall was only introduced in linux 4.11 - linux.ENOSYS => return error.SkipZigTest, + .NOSYS => return error.SkipZigTest, else => unreachable, } var stat_buf: linux.kernel_stat = undefined; switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) { - 0 => {}, + .SUCCESS => {}, else => unreachable, } diff --git a/lib/std/os/wasi.zig b/lib/std/os/wasi.zig index 3965ae77a0..e99d2b820b 100644 --- a/lib/std/os/wasi.zig +++ b/lib/std/os/wasi.zig @@ -83,6 +83,6 @@ pub extern "wasi_snapshot_preview1" fn sock_send(sock: fd_t, si_data: *const cio pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t; /// Get the errno from a syscall return value, or 0 for no error. -pub fn getErrno(r: errno_t) usize { +pub fn getErrno(r: errno_t) errno_t { return r; } diff --git a/lib/std/process.zig b/lib/std/process.zig index 47e800c124..db9f442e56 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -93,7 +93,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { var environ_buf_size: usize = undefined; const environ_sizes_get_ret = os.wasi.environ_sizes_get(&environ_count, &environ_buf_size); - if (environ_sizes_get_ret != os.wasi.ESUCCESS) { + if (environ_sizes_get_ret != .SUCCESS) { return os.unexpectedErrno(environ_sizes_get_ret); } @@ -103,7 +103,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { defer allocator.free(environ_buf); const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr); - if (environ_get_ret != os.wasi.ESUCCESS) { + if (environ_get_ret != .SUCCESS) { return os.unexpectedErrno(environ_get_ret); } @@ -255,7 +255,7 @@ pub const ArgIteratorWasi = struct { var buf_size: usize = undefined; switch (w.args_sizes_get(&count, &buf_size)) { - w.ESUCCESS => {}, + .SUCCESS => {}, else => |err| return os.unexpectedErrno(err), } @@ -265,7 +265,7 @@ pub const ArgIteratorWasi = struct { var argv_buf = try allocator.alloc(u8, buf_size); switch (w.args_get(argv.ptr, argv_buf.ptr)) { - w.ESUCCESS => {}, + .SUCCESS => {}, else => |err| return os.unexpectedErrno(err), } diff --git a/lib/std/special/compiler_rt/emutls.zig b/lib/std/special/compiler_rt/emutls.zig index 46d0dd98e8..d51550c0d5 100644 --- a/lib/std/special/compiler_rt/emutls.zig +++ b/lib/std/special/compiler_rt/emutls.zig @@ -201,7 +201,7 @@ const current_thread_storage = struct { /// Initialize pthread_key_t. fn init() void { - if (std.c.pthread_key_create(¤t_thread_storage.key, current_thread_storage.deinit) != 0) { + if (std.c.pthread_key_create(¤t_thread_storage.key, current_thread_storage.deinit) != .SUCCESS) { abort(); } } @@ -248,14 +248,14 @@ const emutls_control = extern struct { /// Simple wrapper for global lock. fn lock() void { - if (std.c.pthread_mutex_lock(&emutls_control.mutex) != 0) { + if (std.c.pthread_mutex_lock(&emutls_control.mutex) != .SUCCESS) { abort(); } } /// Simple wrapper for global unlock. fn unlock() void { - if (std.c.pthread_mutex_unlock(&emutls_control.mutex) != 0) { + if (std.c.pthread_mutex_unlock(&emutls_control.mutex) != .SUCCESS) { abort(); } } diff --git a/lib/std/time.zig b/lib/std/time.zig index 99304af46a..a0430049cf 100644 --- a/lib/std/time.zig +++ b/lib/std/time.zig @@ -92,7 +92,7 @@ pub fn nanoTimestamp() i128 { if (builtin.os.tag == .wasi and !builtin.link_libc) { var ns: os.wasi.timestamp_t = undefined; const err = os.wasi.clock_time_get(os.wasi.CLOCK_REALTIME, 1, &ns); - assert(err == os.wasi.ESUCCESS); + assert(err == .SUCCESS); return ns; } var ts: os.timespec = undefined; diff --git a/lib/std/x/os/socket_posix.zig b/lib/std/x/os/socket_posix.zig index 5deff22317..59e4b177f7 100644 --- a/lib/std/x/os/socket_posix.zig +++ b/lib/std/x/os/socket_posix.zig @@ -82,32 +82,32 @@ pub fn Mixin(comptime Socket: type) type { while (true) { const rc = os.system.sendmsg(self.fd, &msg, @intCast(c_int, flags)); return switch (os.errno(rc)) { - 0 => return @intCast(usize, rc), - os.EACCES => error.AccessDenied, - os.EAGAIN => error.WouldBlock, - os.EALREADY => error.FastOpenAlreadyInProgress, - os.EBADF => unreachable, // always a race condition - os.ECONNRESET => error.ConnectionResetByPeer, - os.EDESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set. - os.EFAULT => unreachable, // An invalid user space address was specified for an argument. - os.EINTR => continue, - os.EINVAL => unreachable, // Invalid argument passed. - os.EISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified - os.EMSGSIZE => error.MessageTooBig, - os.ENOBUFS => error.SystemResources, - os.ENOMEM => error.SystemResources, - os.ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. - os.EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type. - os.EPIPE => error.BrokenPipe, - os.EAFNOSUPPORT => error.AddressFamilyNotSupported, - os.ELOOP => error.SymLinkLoop, - os.ENAMETOOLONG => error.NameTooLong, - os.ENOENT => error.FileNotFound, - os.ENOTDIR => error.NotDir, - os.EHOSTUNREACH => error.NetworkUnreachable, - os.ENETUNREACH => error.NetworkUnreachable, - os.ENOTCONN => error.SocketNotConnected, - os.ENETDOWN => error.NetworkSubsystemFailed, + .SUCCESS => return @intCast(usize, rc), + .ACCES => error.AccessDenied, + .AGAIN => error.WouldBlock, + .ALREADY => error.FastOpenAlreadyInProgress, + .BADF => unreachable, // always a race condition + .CONNRESET => error.ConnectionResetByPeer, + .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set. + .FAULT => unreachable, // An invalid user space address was specified for an argument. + .INTR => continue, + .INVAL => unreachable, // Invalid argument passed. + .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified + .MSGSIZE => error.MessageTooBig, + .NOBUFS => error.SystemResources, + .NOMEM => error.SystemResources, + .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. + .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type. + .PIPE => error.BrokenPipe, + .AFNOSUPPORT => error.AddressFamilyNotSupported, + .LOOP => error.SymLinkLoop, + .NAMETOOLONG => error.NameTooLong, + .NOENT => error.FileNotFound, + .NOTDIR => error.NotDir, + .HOSTUNREACH => error.NetworkUnreachable, + .NETUNREACH => error.NetworkUnreachable, + .NOTCONN => error.SocketNotConnected, + .NETDOWN => error.NetworkSubsystemFailed, else => |err| os.unexpectedErrno(err), }; } @@ -120,17 +120,17 @@ pub fn Mixin(comptime Socket: type) type { while (true) { const rc = os.system.recvmsg(self.fd, msg, @intCast(c_int, flags)); return switch (os.errno(rc)) { - 0 => @intCast(usize, rc), - os.EBADF => unreachable, // always a race condition - os.EFAULT => unreachable, - os.EINVAL => unreachable, - os.ENOTCONN => unreachable, - os.ENOTSOCK => unreachable, - os.EINTR => continue, - os.EAGAIN => error.WouldBlock, - os.ENOMEM => error.SystemResources, - os.ECONNREFUSED => error.ConnectionRefused, - os.ECONNRESET => error.ConnectionResetByPeer, + .SUCCESS => @intCast(usize, rc), + .BADF => unreachable, // always a race condition + .FAULT => unreachable, + .INVAL => unreachable, + .NOTCONN => unreachable, + .NOTSOCK => unreachable, + .INTR => continue, + .AGAIN => error.WouldBlock, + .NOMEM => error.SystemResources, + .CONNREFUSED => error.ConnectionRefused, + .CONNRESET => error.ConnectionResetByPeer, else => |err| os.unexpectedErrno(err), }; } @@ -164,12 +164,12 @@ pub fn Mixin(comptime Socket: type) type { const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&value), &value_len); return switch (os.errno(rc)) { - 0 => value, - os.EBADF => error.BadFileDescriptor, - os.EFAULT => error.InvalidAddressSpace, - os.EINVAL => error.InvalidSocketOption, - os.ENOPROTOOPT => error.UnknownSocketOption, - os.ENOTSOCK => error.NotASocket, + .SUCCESS => value, + .BADF => error.BadFileDescriptor, + .FAULT => error.InvalidAddressSpace, + .INVAL => error.InvalidSocketOption, + .NOPROTOOPT => error.UnknownSocketOption, + .NOTSOCK => error.NotASocket, else => |err| os.unexpectedErrno(err), }; } @@ -181,12 +181,12 @@ pub fn Mixin(comptime Socket: type) type { const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&value), &value_len); return switch (os.errno(rc)) { - 0 => value, - os.EBADF => error.BadFileDescriptor, - os.EFAULT => error.InvalidAddressSpace, - os.EINVAL => error.InvalidSocketOption, - os.ENOPROTOOPT => error.UnknownSocketOption, - os.ENOTSOCK => error.NotASocket, + .SUCCESS => value, + .BADF => error.BadFileDescriptor, + .FAULT => error.InvalidAddressSpace, + .INVAL => error.InvalidSocketOption, + .NOPROTOOPT => error.UnknownSocketOption, + .NOTSOCK => error.NotASocket, else => |err| os.unexpectedErrno(err), }; }