mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
std.x.os.net: make error set consistent across targets
This commit is contained in:
parent
3c1daf951c
commit
df1f401cf0
@ -9,10 +9,25 @@ const testing = std.testing;
|
||||
const native_os = builtin.os;
|
||||
const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE");
|
||||
|
||||
pub const ResolveScopeIdError = error{
|
||||
NameTooLong,
|
||||
PermissionDenied,
|
||||
AddressFamilyNotSupported,
|
||||
ProtocolFamilyNotAvailable,
|
||||
ProcessFdQuotaExceeded,
|
||||
SystemFdQuotaExceeded,
|
||||
SystemResources,
|
||||
ProtocolNotSupported,
|
||||
SocketTypeNotSupported,
|
||||
InterfaceNotFound,
|
||||
FileSystem,
|
||||
Unexpected,
|
||||
};
|
||||
|
||||
/// Resolves a network interface name into a scope/zone ID. It returns
|
||||
/// an error if either resolution fails, or if the interface name is
|
||||
/// too long.
|
||||
pub fn resolveScopeId(name: []const u8) !u32 {
|
||||
pub fn resolveScopeId(name: []const u8) ResolveScopeIdError!u32 {
|
||||
if (have_ifnamesize) {
|
||||
if (name.len >= os.IFNAMESIZE) return error.NameTooLong;
|
||||
|
||||
@ -433,7 +448,7 @@ pub const IPv6 = extern struct {
|
||||
'0'...'9' => fmt.parseInt(u32, scope_id_slice, 10),
|
||||
else => resolveScopeId(scope_id_slice) catch |err| switch (err) {
|
||||
error.InterfaceNotFound => return error.InterfaceNotFound,
|
||||
else => |e| return e,
|
||||
else => err,
|
||||
},
|
||||
} catch return error.UnknownScopeId;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user