authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-27 17:31:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-28 15:29:50-04:00
logd5865f5319305b6d06502b64772f8207bae2d6a5
tree962d737a10e8d43582bbdbc4a8faec433b618f7d
parent845be4ea3e3bd27ace45e9435004b1eddf46d7de
signaturelock-open Commit is signed but in an unrecognized format.

move libc/linux bits around


3 files changed, 100 insertions(+), 47 deletions(-)

lib/std/c/linux.zig+35
...@@ -17,6 +17,41 @@ pub const _errno = switch (builtin.abi) {...@@ -17,6 +17,41 @@ pub const _errno = switch (builtin.abi) {
1717
18pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));18pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
1919
20pub const AI_PASSIVE = 0x01;
21pub const AI_CANONNAME = 0x02;
22pub const AI_NUMERICHOST = 0x04;
23pub const AI_V4MAPPED = 0x08;
24pub const AI_ALL = 0x10;
25pub const AI_ADDRCONFIG = 0x20;
26pub const AI_NUMERICSERV = 0x400;
27
28pub const NI_NUMERICHOST = 0x01;
29pub const NI_NUMERICSERV = 0x02;
30pub const NI_NOFQDN = 0x04;
31pub const NI_NAMEREQD = 0x08;
32pub const NI_DGRAM = 0x10;
33pub const NI_NUMERICSCOPE = 0x100;
34
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;
45
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;
54
20pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;55pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
21pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;56pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
22pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;57pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
lib/std/net.zig+65-12
...@@ -347,6 +347,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -347,6 +347,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
347 errdefer result.arena.deinit();347 errdefer result.arena.deinit();
348348
349 if (builtin.link_libc) {349 if (builtin.link_libc) {
350 const c = std.c;
350 const name_c = try std.cstr.addNullByte(allocator, name);351 const name_c = try std.cstr.addNullByte(allocator, name);
351 defer allocator.free(name_c);352 defer allocator.free(name_c);
352353
...@@ -354,7 +355,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -354,7 +355,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
354 defer allocator.free(port_c);355 defer allocator.free(port_c);
355356
356 const hints = os.addrinfo{357 const hints = os.addrinfo{
357 .flags = os.AI_NUMERICSERV,358 .flags = c.AI_NUMERICSERV,
358 .family = os.AF_UNSPEC,359 .family = os.AF_UNSPEC,
359 .socktype = os.SOCK_STREAM,360 .socktype = os.SOCK_STREAM,
360 .protocol = os.IPPROTO_TCP,361 .protocol = os.IPPROTO_TCP,
...@@ -366,17 +367,17 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -366,17 +367,17 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
366 var res: *os.addrinfo = undefined;367 var res: *os.addrinfo = undefined;
367 switch (os.system.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res)) {368 switch (os.system.getaddrinfo(name_c.ptr, port_c.ptr, &hints, &res)) {
368 0 => {},369 0 => {},
369 os.EAI_ADDRFAMILY => return error.HostLacksNetworkAddresses,370 c.EAI_ADDRFAMILY => return error.HostLacksNetworkAddresses,
370 os.EAI_AGAIN => return error.TemporaryNameServerFailure,371 c.EAI_AGAIN => return error.TemporaryNameServerFailure,
371 os.EAI_BADFLAGS => unreachable, // Invalid hints372 c.EAI_BADFLAGS => unreachable, // Invalid hints
372 os.EAI_FAIL => return error.NameServerFailure,373 c.EAI_FAIL => return error.NameServerFailure,
373 os.EAI_FAMILY => return error.AddressFamilyNotSupported,374 c.EAI_FAMILY => return error.AddressFamilyNotSupported,
374 os.EAI_MEMORY => return error.OutOfMemory,375 c.EAI_MEMORY => return error.OutOfMemory,
375 os.EAI_NODATA => return error.HostLacksNetworkAddresses,376 c.EAI_NODATA => return error.HostLacksNetworkAddresses,
376 os.EAI_NONAME => return error.UnknownName,377 c.EAI_NONAME => return error.UnknownName,
377 os.EAI_SERVICE => return error.ServiceUnavailable,378 c.EAI_SERVICE => return error.ServiceUnavailable,
378 os.EAI_SOCKTYPE => unreachable, // Invalid socket type requested in hints379 c.EAI_SOCKTYPE => unreachable, // Invalid socket type requested in hints
379 os.EAI_SYSTEM => switch (os.errno(-1)) {380 c.EAI_SYSTEM => switch (os.errno(-1)) {
380 else => |e| return os.unexpectedErrno(e),381 else => |e| return os.unexpectedErrno(e),
381 },382 },
382 else => unreachable,383 else => unreachable,
...@@ -485,6 +486,9 @@ fn linuxLookupName(...@@ -485,6 +486,9 @@ fn linuxLookupName(
485 });486 });
486 if (cnt == 0 and (flags & os.AI_NUMERICHOST) == 0) {487 if (cnt == 0 and (flags & os.AI_NUMERICHOST) == 0) {
487 cnt = try linuxLookupNameFromHosts(buf, canon_buf, canon_len, name, family);488 cnt = try linuxLookupNameFromHosts(buf, canon_buf, canon_len, name, family);
489 if (cnt == 0) {
490 cnt = try linuxLookupNameFromDnsSearch(buf, canon_buf, canon_len, name, family);
491 }
488 }492 }
489 } else {493 } else {
490 canon_len.* = 0;494 canon_len.* = 0;
...@@ -641,3 +645,52 @@ pub fn isValidHostName(hostname: []const u8) bool {...@@ -641,3 +645,52 @@ pub fn isValidHostName(hostname: []const u8) bool {
641 }645 }
642 return true;646 return true;
643}647}
648
649fn linuxLookupNameFromDnsSearch(
650 buf: []LookupAddr,
651 canon_buf: []u8,
652 canon_len: *usize,
653 name: []const u8,
654 family: i32,
655) !usize {
656 var search: [256]u8 = undefined;
657 const resolv_conf = try getResolvConf(&search);
658
659 // Count dots, suppress search when >=ndots or name ends in
660 // a dot, which is an explicit request for global scope.
661 //var dots: usize = 0;
662 //for (name) |byte| {
663 // if (byte == '.') dots += 1;
664 //}
665
666 //if (dots >= conf.ndots || name[l-1]=='.') *search = 0;
667
668 //// Strip final dot for canon, fail if multiple trailing dots.
669 //if (name[l-1]=='.') l--;
670 //if (!l || name[l-1]=='.') return EAI_NONAME;
671
672 //// This can never happen; the caller already checked length.
673 //if (l >= 256) return EAI_NONAME;
674
675 //// Name with search domain appended is setup in canon[]. This both
676 //// provides the desired default canonical name (if the requested
677 //// name is not a CNAME record) and serves as a buffer for passing
678 //// the full requested name to name_from_dns.
679 //memcpy(canon, name, l);
680 //canon[l] = '.';
681
682 //for (p=search; *p; p=z) {
683 // for (; isspace(*p); p++);
684 // for (z=p; *z && !isspace(*z); z++);
685 // if (z==p) break;
686 // if (z-p < 256 - l - 1) {
687 // memcpy(canon+l+1, p, z-p);
688 // canon[z-p+1+l] = 0;
689 // int cnt = name_from_dns(buf, canon, canon, family, &conf);
690 // if (cnt) return cnt;
691 // }
692 //}
693
694 //canon[l] = 0;
695 //return name_from_dns(buf, canon, name, family, &conf);
696}
lib/std/os/bits/linux.zig-35
...@@ -1396,41 +1396,6 @@ pub const addrinfo = extern struct {...@@ -1396,41 +1396,6 @@ pub const addrinfo = extern struct {
1396 next: ?*addrinfo,1396 next: ?*addrinfo,
1397};1397};
13981398
1399pub const AI_PASSIVE = 0x01;
1400pub const AI_CANONNAME = 0x02;
1401pub const AI_NUMERICHOST = 0x04;
1402pub const AI_V4MAPPED = 0x08;
1403pub const AI_ALL = 0x10;
1404pub const AI_ADDRCONFIG = 0x20;
1405pub const AI_NUMERICSERV = 0x400;
1406
1407pub const NI_NUMERICHOST = 0x01;
1408pub const NI_NUMERICSERV = 0x02;
1409pub const NI_NOFQDN = 0x04;
1410pub const NI_NAMEREQD = 0x08;
1411pub const NI_DGRAM = 0x10;
1412pub const NI_NUMERICSCOPE = 0x100;
1413
1414pub const EAI_BADFLAGS = -1;
1415pub const EAI_NONAME = -2;
1416pub const EAI_AGAIN = -3;
1417pub const EAI_FAIL = -4;
1418pub const EAI_FAMILY = -6;
1419pub const EAI_SOCKTYPE = -7;
1420pub const EAI_SERVICE = -8;
1421pub const EAI_MEMORY = -10;
1422pub const EAI_SYSTEM = -11;
1423pub const EAI_OVERFLOW = -12;
1424
1425pub const EAI_NODATA = -5;
1426pub const EAI_ADDRFAMILY = -9;
1427pub const EAI_INPROGRESS = -100;
1428pub const EAI_CANCELED = -101;
1429pub const EAI_NOTCANCELED = -102;
1430pub const EAI_ALLDONE = -103;
1431pub const EAI_INTR = -104;
1432pub const EAI_IDN_ENCODE = -105;
1433
1434pub const IPPORT_RESERVED = 1024;1399pub const IPPORT_RESERVED = 1024;
14351400
1436pub const IPPROTO_IP = 0;1401pub const IPPROTO_IP = 0;