Skip to content

Commit 104b62f

Browse files
committed
std: turn errno into an enum
1 parent 0097766 commit 104b62f

File tree

11 files changed

+1347
-1337
lines changed

11 files changed

+1347
-1337
lines changed

lib/std/c.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ pub usingnamespace switch (builtin.os) {
2121
else => struct {},
2222
};
2323

24-
pub fn getErrno(rc: var) u16 {
25-
if (rc == -1) {
26-
return @intCast(u16, _errno().*);
27-
} else {
28-
return 0;
29-
}
24+
pub fn getErrno(rc: var) Errno {
25+
const errno = if (rc == -1)
26+
_errno().*
27+
else
28+
0;
29+
return @intToEnum(Errno, errno);
3030
}
3131

3232
/// The return type is `type` to force comptime function call execution.

lib/std/event/loop.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ pub const Loop = struct {
817817
@atomicStore(i32, &self.os_data.fs_queue_item, 1, AtomicOrder.SeqCst);
818818
const rc = os.linux.futex_wake(&self.os_data.fs_queue_item, os.linux.FUTEX_WAKE, 1);
819819
switch (os.linux.getErrno(rc)) {
820-
0 => {},
821-
os.EINVAL => unreachable,
820+
@enumToInt(os.linux.Errno, 0) => {},
821+
.EINVAL => unreachable,
822822
else => unreachable,
823823
}
824824
},
@@ -880,7 +880,7 @@ pub const Loop = struct {
880880
.linux => {
881881
const rc = os.linux.futex_wait(&self.os_data.fs_queue_item, os.linux.FUTEX_WAIT, 0, null);
882882
switch (os.linux.getErrno(rc)) {
883-
0, os.EINTR, os.EAGAIN => continue,
883+
@enumToInt(os.linux.Errno, 0), .EINTR, .EAGAIN => continue,
884884
else => unreachable,
885885
}
886886
},

lib/std/fs.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,11 @@ pub const Dir = struct {
524524
if (self.index >= self.end_index) {
525525
const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
526526
switch (os.linux.getErrno(rc)) {
527-
0 => {},
528-
os.EBADF => unreachable,
529-
os.EFAULT => unreachable,
530-
os.ENOTDIR => unreachable,
531-
os.EINVAL => unreachable,
527+
@enumToInt(os.linux.Errno, 0) => {},
528+
.EBADF => unreachable,
529+
.EFAULT => unreachable,
530+
.ENOTDIR => unreachable,
531+
.EINVAL => unreachable,
532532
else => |err| return os.unexpectedErrno(err),
533533
}
534534
if (rc == 0) return null;

0 commit comments

Comments
 (0)