diff options
author | 2023-01-09 03:25:06 -0800 | |
---|---|---|
committer | 2023-01-09 03:25:06 -0800 | |
commit | ced6201cb0433c11d8b7ca9e60de61b133cc8fab (patch) | |
tree | 008c125e683009824b2a5cd01fbc51fd1d10e3e1 /src/linux_c.zig | |
parent | 905a3313b5dfc491756b5295bcabe9fab92fbda9 (diff) | |
download | bun-ced6201cb0433c11d8b7ca9e60de61b133cc8fab.tar.gz bun-ced6201cb0433c11d8b7ca9e60de61b133cc8fab.tar.zst bun-ced6201cb0433c11d8b7ca9e60de61b133cc8fab.zip |
Cleanup error handling in Bun.listen
Diffstat (limited to 'src/linux_c.zig')
-rw-r--r-- | src/linux_c.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/linux_c.zig b/src/linux_c.zig index 2ff96c966..b652a6490 100644 --- a/src/linux_c.zig +++ b/src/linux_c.zig @@ -141,6 +141,20 @@ pub const SystemErrno = enum(u8) { pub const max = 134; + pub fn init(code: anytype) ?SystemErrno { + if (comptime std.meta.trait.isSignedInt(@TypeOf(code))) { + if (code < 0) + return init(-code); + } + + if (code >= max) return null; + return @intToEnum(SystemErrno, code); + } + + pub fn label(this: SystemErrno) ?[]const u8 { + return labels.get(this) orelse null; + } + const LabelMap = std.EnumMap(SystemErrno, []const u8); pub const labels: LabelMap = brk: { var map: LabelMap = LabelMap.initFull(""); |