authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-27 18:26:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-27 18:26:50-07:00
logdf1f401cf0e997ed289e14f69ab1114e839b56ee
treec31efb1ef0e857ac7a61e27401db36763c798fc7
parent3c1daf951cf72e454de18e70f84b9a896aa17dd0

std.x.os.net: make error set consistent across targets


1 files changed, 17 insertions(+), 2 deletions(-)

lib/std/x/os/net.zig+17-2
...@@ -9,10 +9,25 @@ const testing = std.testing;...@@ -9,10 +9,25 @@ const testing = std.testing;
9const native_os = builtin.os;9const native_os = builtin.os;
10const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE");10const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE");
1111
12pub const ResolveScopeIdError = error{
13 NameTooLong,
14 PermissionDenied,
15 AddressFamilyNotSupported,
16 ProtocolFamilyNotAvailable,
17 ProcessFdQuotaExceeded,
18 SystemFdQuotaExceeded,
19 SystemResources,
20 ProtocolNotSupported,
21 SocketTypeNotSupported,
22 InterfaceNotFound,
23 FileSystem,
24 Unexpected,
25};
26
12/// Resolves a network interface name into a scope/zone ID. It returns27/// Resolves a network interface name into a scope/zone ID. It returns
13/// an error if either resolution fails, or if the interface name is28/// an error if either resolution fails, or if the interface name is
14/// too long.29/// too long.
15pub fn resolveScopeId(name: []const u8) !u32 {30pub fn resolveScopeId(name: []const u8) ResolveScopeIdError!u32 {
16 if (have_ifnamesize) {31 if (have_ifnamesize) {
17 if (name.len >= os.IFNAMESIZE) return error.NameTooLong;32 if (name.len >= os.IFNAMESIZE) return error.NameTooLong;
1833
...@@ -433,7 +448,7 @@ pub const IPv6 = extern struct {...@@ -433,7 +448,7 @@ pub const IPv6 = extern struct {
433 '0'...'9' => fmt.parseInt(u32, scope_id_slice, 10),448 '0'...'9' => fmt.parseInt(u32, scope_id_slice, 10),
434 else => resolveScopeId(scope_id_slice) catch |err| switch (err) {449 else => resolveScopeId(scope_id_slice) catch |err| switch (err) {
435 error.InterfaceNotFound => return error.InterfaceNotFound,450 error.InterfaceNotFound => return error.InterfaceNotFound,
436 else => |e| return e,451 else => err,
437 },452 },
438 } catch return error.UnknownScopeId;453 } catch return error.UnknownScopeId;
439454