From 18ffd48b60aacf3cf1ea387f513848818731dbea Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sun, 9 Feb 2025 14:07:35 +0100 Subject: [PATCH 1/2] std.c: Support optional addr and host arguments in getnameinfo The POSIX spec allows passing null here https://pubs.opengroup.org/onlinepubs/9799919799/functions/getnameinfo.html --- lib/std/c.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index a366c0ca63..72668ba3da 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -9770,9 +9770,9 @@ pub extern "c" fn freeaddrinfo(res: *addrinfo) void; pub extern "c" fn getnameinfo( noalias addr: *const sockaddr, addrlen: socklen_t, - noalias host: [*]u8, + noalias host: ?[*]u8, hostlen: socklen_t, - noalias serv: [*]u8, + noalias serv: ?[*]u8, servlen: socklen_t, flags: u32, ) EAI; From 2ccfb1dafd03c906c5ca22f4eaaf07feaff758e5 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sun, 9 Feb 2025 14:17:04 +0100 Subject: [PATCH 2/2] std.c: Use std.c.NI as the flags type in getnameinfo std.c.NI was never used in the source, so let's finally use it and make the function more clear! This is a breaking change, although a minor one: If you previously passed 0 here (meaning no flags), then now you have to pass an empty struct (.{}) instead. Otherwise, you probably used @bitCast() shenanigans here (like @bitCast(c.NI { .NUMERICHOST = true }) and that will still work, but you can also get rid of the @bitCast() now! --- lib/std/c.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 72668ba3da..cd2298be6b 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -9774,7 +9774,7 @@ pub extern "c" fn getnameinfo( hostlen: socklen_t, noalias serv: ?[*]u8, servlen: socklen_t, - flags: u32, + flags: NI, ) EAI; pub extern "c" fn gai_strerror(errcode: EAI) [*:0]const u8;