zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2d02920a905e20b7f43991657cdc028e444b9df7 (tree)
parent 25423eb453e1c0cece457f4012106dbcd97f29f3
Author: Luna <git@l4.pm>
Date:   Sun, 10 Nov 2019 14:04:52 -0300

use hasDecl instead of switch on builtin.os

Diffstat:
Mlib/std/net.zig | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/std/net.zig b/lib/std/net.zig @@ -10,14 +10,13 @@ test "" { _ = @import("net/test.zig"); } +const has_unix_sockets = @hasDecl(os, "sockaddr_un"); + pub const Address = extern union { any: os.sockaddr, in: os.sockaddr_in, in6: os.sockaddr_in6, - un: switch (builtin.os) { - .linux, .macosx, .freebsd, .netbsd => os.sockaddr_un, - else => void, - }, + un: if (has_unix_sockets) os.sockaddr_un else void, // TODO this crashed the compiler //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0); @@ -239,6 +238,7 @@ pub const Address = extern union { } /// Returns the port in native endian. + /// Asserts that the address is ip4 or ip6. pub fn getPort(self: Address) u16 { const big_endian_port = switch (self.any.family) { os.AF_INET => self.in.port, @@ -249,6 +249,7 @@ pub const Address = extern union { } /// `port` is native-endian. + /// Asserts that the address is ip4 or ip6. pub fn setPort(self: *Address, port: u16) void { const ptr = switch (self.any.family) { os.AF_INET => &self.in.port,