Check for isDarwin() instead of linked libc

This commit is contained in:
John Schmidt 2022-01-12 18:37:18 +01:00
parent 66fe5bb0d8
commit c992164dc7
3 changed files with 4 additions and 4 deletions

View File

@ -650,7 +650,7 @@ fn if_nametoindex(name: []const u8) !u32 {
return @bitCast(u32, ifr.ifru.ivalue); return @bitCast(u32, ifr.ifru.ivalue);
} }
if (builtin.link_libc) { if (comptime builtin.target.os.tag.isDarwin()) {
if (name.len >= os.IFNAMESIZE) if (name.len >= os.IFNAMESIZE)
return error.NameTooLong; return error.NameTooLong;

View File

@ -49,7 +49,7 @@ test "parse and render IPv6 addresses" {
try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0)); try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0)); try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
// TODO Make this test pass on other operating systems. // TODO Make this test pass on other operating systems.
if (builtin.os.tag == .linux or builtin.link_libc) { if (builtin.os.tag == .linux or comptime builtin.os.tag.isDarwin()) {
try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0)); try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0)); try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0)); try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
@ -57,7 +57,7 @@ test "parse and render IPv6 addresses" {
} }
test "invalid but parseable IPv6 scope ids" { test "invalid but parseable IPv6 scope ids" {
if (builtin.os.tag != .linux or !builtin.link_libc) { if (builtin.os.tag != .linux or comptime !builtin.os.tag.isDarwin()) {
// Currently, resolveIp6 with alphanumerical scope IDs only works on Linux. // Currently, resolveIp6 with alphanumerical scope IDs only works on Linux.
// TODO Make this test pass on other operating systems. // TODO Make this test pass on other operating systems.
return error.SkipZigTest; return error.SkipZigTest;

View File

@ -16,7 +16,7 @@ pub fn resolveScopeId(name: []const u8) !u32 {
if (have_ifnamesize) { if (have_ifnamesize) {
if (name.len >= os.IFNAMESIZE) return error.NameTooLong; if (name.len >= os.IFNAMESIZE) return error.NameTooLong;
if (native_os.tag == .windows or builtin.link_libc) { if (native_os.tag == .windows or comptime native_os.tag.isDarwin()) {
var interface_name: [os.IFNAMESIZE:0]u8 = undefined; var interface_name: [os.IFNAMESIZE:0]u8 = undefined;
mem.copy(u8, &interface_name, name); mem.copy(u8, &interface_name, name);
interface_name[name.len] = 0; interface_name[name.len] = 0;