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