authorgravatar for git@l4.pmLuna <git@l4.pm> 2019-11-10 14:04:52-03:00
committergravatar for git@l4.pmLuna <git@l4.pm> 2019-11-10 14:04:52-03:00
log2d02920a905e20b7f43991657cdc028e444b9df7
tree4c9a3ee6a1cdba23567890e947bbbb47a9189f79
parent25423eb453e1c0cece457f4012106dbcd97f29f3

use hasDecl instead of switch on builtin.os


1 files changed, 5 insertions(+), 4 deletions(-)

lib/std/net.zig+5-4
......@@ -10,14 +10,13 @@ test "" {
1010 _ = @import("net/test.zig");
1111}
1212
13const has_unix_sockets = @hasDecl(os, "sockaddr_un");
14
1315pub const Address = extern union {
1416 any: os.sockaddr,
1517 in: os.sockaddr_in,
1618 in6: os.sockaddr_in6,
17 un: switch (builtin.os) {
18 .linux, .macosx, .freebsd, .netbsd => os.sockaddr_un,
19 else => void,
20 },
19 un: if (has_unix_sockets) os.sockaddr_un else void,
2120
2221 // TODO this crashed the compiler
2322 //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0);
......@@ -239,6 +238,7 @@ pub const Address = extern union {
239238 }
240239
241240 /// Returns the port in native endian.
241 /// Asserts that the address is ip4 or ip6.
242242 pub fn getPort(self: Address) u16 {
243243 const big_endian_port = switch (self.any.family) {
244244 os.AF_INET => self.in.port,
......@@ -249,6 +249,7 @@ pub const Address = extern union {
249249 }
250250
251251 /// `port` is native-endian.
252 /// Asserts that the address is ip4 or ip6.
252253 pub fn setPort(self: *Address, port: u16) void {
253254 const ptr = switch (self.any.family) {
254255 os.AF_INET => &self.in.port,