authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-01-18 12:12:18+10:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-18 17:46:44-05:00
log72ec4456779839d3df4b41055fbaf47a57b69ac8
treec25be280bd8dd99e4623532490d001a913040df1
parent9e6e1e58bb163868db51832e54c323a9ab893329

std: turn EAI_ constants into a non-exhaustive enum


5 files changed, 102 insertions(+), 89 deletions(-)

lib/std/c.zig+3-3
......@@ -185,7 +185,7 @@ pub extern "c" fn getaddrinfo(
185185 noalias service: [*:0]const u8,
186186 noalias hints: *const addrinfo,
187187 noalias res: **addrinfo,
188) c_int;
188) EAI;
189189
190190pub extern "c" fn freeaddrinfo(res: *addrinfo) void;
191191
......@@ -197,9 +197,9 @@ pub extern "c" fn getnameinfo(
197197 noalias serv: [*]u8,
198198 servlen: socklen_t,
199199 flags: u32,
200) c_int;
200) EAI;
201201
202pub extern "c" fn gai_strerror(errcode: c_int) [*:0]const u8;
202pub extern "c" fn gai_strerror(errcode: EAI) [*:0]const u8;
203203
204204pub extern "c" fn poll(fds: [*]pollfd, nfds: nfds_t, timeout: c_int) c_int;
205205
lib/std/c/darwin.zig+33-28
......@@ -70,47 +70,52 @@ pub const AI_NUMERICHOST = 0x00000004;
7070/// prevent service name resolution
7171pub const AI_NUMERICSERV = 0x00001000;
7272
73/// address family for hostname not supported
74pub const EAI_ADDRFAMILY = 1;
73pub const EAI = extern enum(c_int) {
74 /// address family for hostname not supported
75 ADDRFAMILY = 1,
7576
76/// temporary failure in name resolution
77pub const EAI_AGAIN = 2;
77 /// temporary failure in name resolution
78 AGAIN = 2,
7879
79/// invalid value for ai_flags
80pub const EAI_BADFLAGS = 3;
80 /// invalid value for ai_flags
81 BADFLAGS = 3,
8182
82/// non-recoverable failure in name resolution
83pub const EAI_FAIL = 4;
83 /// non-recoverable failure in name resolution
84 FAIL = 4,
8485
85/// ai_family not supported
86pub const EAI_FAMILY = 5;
86 /// ai_family not supported
87 FAMILY = 5,
8788
88/// memory allocation failure
89pub const EAI_MEMORY = 6;
89 /// memory allocation failure
90 MEMORY = 6,
9091
91/// no address associated with hostname
92pub const EAI_NODATA = 7;
92 /// no address associated with hostname
93 NODATA = 7,
9394
94/// hostname nor servname provided, or not known
95pub const EAI_NONAME = 8;
95 /// hostname nor servname provided, or not known
96 NONAME = 8,
9697
97/// servname not supported for ai_socktype
98pub const EAI_SERVICE = 9;
98 /// servname not supported for ai_socktype
99 SERVICE = 9,
99100
100/// ai_socktype not supported
101pub const EAI_SOCKTYPE = 10;
101 /// ai_socktype not supported
102 SOCKTYPE = 10,
102103
103/// system error returned in errno
104pub const EAI_SYSTEM = 11;
104 /// system error returned in errno
105 SYSTEM = 11,
105106
106/// invalid value for hints
107pub const EAI_BADHINTS = 12;
107 /// invalid value for hints
108 BADHINTS = 12,
108109
109/// resolved protocol is unknown
110pub const EAI_PROTOCOL = 13;
110 /// resolved protocol is unknown
111 PROTOCOL = 13,
112
113 /// argument buffer overflow
114 OVERFLOW = 14,
115
116 _,
117};
111118
112/// argument buffer overflow
113pub const EAI_OVERFLOW = 14;
114119pub const EAI_MAX = 15;
115120
116121pub const pthread_mutex_t = extern struct {
lib/std/c/freebsd.zig+32-28
......@@ -23,47 +23,51 @@ pub const pthread_attr_t = extern struct {
2323 __align: c_long,
2424};
2525
26/// address family for hostname not supported
27pub const EAI_ADDRFAMILY = 1;
26pub const EAI = extern enum(c_int) {
27 /// address family for hostname not supported
28 ADDRFAMILY = 1,
2829
29/// name could not be resolved at this time
30pub const EAI_AGAIN = 2;
30 /// name could not be resolved at this time
31 AGAIN = 2,
3132
32/// flags parameter had an invalid value
33pub const EAI_BADFLAGS = 3;
33 /// flags parameter had an invalid value
34 BADFLAGS = 3,
3435
35/// non-recoverable failure in name resolution
36pub const EAI_FAIL = 4;
36 /// non-recoverable failure in name resolution
37 FAIL = 4,
3738
38/// address family not recognized
39pub const EAI_FAMILY = 5;
39 /// address family not recognized
40 FAMILY = 5,
4041
41/// memory allocation failure
42pub const EAI_MEMORY = 6;
42 /// memory allocation failure
43 MEMORY = 6,
4344
44/// no address associated with hostname
45pub const EAI_NODATA = 7;
45 /// no address associated with hostname
46 NODATA = 7,
4647
47/// name does not resolve
48pub const EAI_NONAME = 8;
48 /// name does not resolve
49 NONAME = 8,
4950
50/// service not recognized for socket type
51pub const EAI_SERVICE = 9;
51 /// service not recognized for socket type
52 SERVICE = 9,
5253
53/// intended socket type was not recognized
54pub const EAI_SOCKTYPE = 10;
54 /// intended socket type was not recognized
55 SOCKTYPE = 10,
5556
56/// system error returned in errno
57pub const EAI_SYSTEM = 11;
57 /// system error returned in errno
58 SYSTEM = 11,
5859
59/// invalid value for hints
60pub const EAI_BADHINTS = 12;
60 /// invalid value for hints
61 BADHINTS = 12,
6162
62/// resolved protocol is unknown
63pub const EAI_PROTOCOL = 13;
63 /// resolved protocol is unknown
64 PROTOCOL = 13,
6465
65/// argument buffer overflow
66pub const EAI_OVERFLOW = 14;
66 /// argument buffer overflow
67 OVERFLOW = 14,
68
69 _,
70};
6771
6872pub const EAI_MAX = 15;
6973
lib/std/c/linux.zig+22-18
......@@ -32,25 +32,29 @@ pub const NI_NAMEREQD = 0x08;
3232pub const NI_DGRAM = 0x10;
3333pub const NI_NUMERICSCOPE = 0x100;
3434
35pub const EAI_BADFLAGS = -1;
36pub const EAI_NONAME = -2;
37pub const EAI_AGAIN = -3;
38pub const EAI_FAIL = -4;
39pub const EAI_FAMILY = -6;
40pub const EAI_SOCKTYPE = -7;
41pub const EAI_SERVICE = -8;
42pub const EAI_MEMORY = -10;
43pub const EAI_SYSTEM = -11;
44pub const EAI_OVERFLOW = -12;
35pub const EAI = extern enum(c_int) {
36 BADFLAGS = -1,
37 NONAME = -2,
38 AGAIN = -3,
39 FAIL = -4,
40 FAMILY = -6,
41 SOCKTYPE = -7,
42 SERVICE = -8,
43 MEMORY = -10,
44 SYSTEM = -11,
45 OVERFLOW = -12,
4546
46pub const EAI_NODATA = -5;
47pub const EAI_ADDRFAMILY = -9;
48pub const EAI_INPROGRESS = -100;
49pub const EAI_CANCELED = -101;
50pub const EAI_NOTCANCELED = -102;
51pub const EAI_ALLDONE = -103;
52pub const EAI_INTR = -104;
53pub const EAI_IDN_ENCODE = -105;
47 NODATA = -5,
48 ADDRFAMILY = -9,
49 INPROGRESS = -100,
50 CANCELED = -101,
51 NOTCANCELED = -102,
52 ALLDONE = -103,
53 INTR = -104,
54 IDN_ENCODE = -105,
55
56 _,
57};
5458
5559pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
5660pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
lib/std/net.zig+12-12
......@@ -452,18 +452,18 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
452452 };
453453 var res: *os.addrinfo = undefined;
454454 switch (os.system.getaddrinfo(name_c.ptr, @ptrCast([*:0]const u8, port_c.ptr), &hints, &res)) {
455 0 => {},
456 c.EAI_ADDRFAMILY => return error.HostLacksNetworkAddresses,
457 c.EAI_AGAIN => return error.TemporaryNameServerFailure,
458 c.EAI_BADFLAGS => unreachable, // Invalid hints
459 c.EAI_FAIL => return error.NameServerFailure,
460 c.EAI_FAMILY => return error.AddressFamilyNotSupported,
461 c.EAI_MEMORY => return error.OutOfMemory,
462 c.EAI_NODATA => return error.HostLacksNetworkAddresses,
463 c.EAI_NONAME => return error.UnknownHostName,
464 c.EAI_SERVICE => return error.ServiceUnavailable,
465 c.EAI_SOCKTYPE => unreachable, // Invalid socket type requested in hints
466 c.EAI_SYSTEM => switch (os.errno(-1)) {
455 @intToEnum(os.system.EAI, 0) => {},
456 .ADDRFAMILY => return error.HostLacksNetworkAddresses,
457 .AGAIN => return error.TemporaryNameServerFailure,
458 .BADFLAGS => unreachable, // Invalid hints
459 .FAIL => return error.NameServerFailure,
460 .FAMILY => return error.AddressFamilyNotSupported,
461 .MEMORY => return error.OutOfMemory,
462 .NODATA => return error.HostLacksNetworkAddresses,
463 .NONAME => return error.UnknownHostName,
464 .SERVICE => return error.ServiceUnavailable,
465 .SOCKTYPE => unreachable, // Invalid socket type requested in hints
466 .SYSTEM => switch (os.errno(-1)) {
467467 else => |e| return os.unexpectedErrno(e),
468468 },
469469 else => unreachable,