From 23c28c72b7a5d9a3df3fc96ac9ab419fafeae819 Mon Sep 17 00:00:00 2001 From: johnLate Date: Tue, 27 Oct 2020 08:00:35 +0100 Subject: [PATCH] std.os.linux.accept/accept4: allow null for addr and len MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit std.os.accept already wants to allow null, which matches `man 3p accept`: > address Either a null pointer, or a pointer to a sockaddr structure > where the address of the connecting socket shall be re‐ > turned. > > address_len Either a null pointer, if address is a null pointer, or a > pointer to a socklen_t object which on input specifies the > length of the supplied sockaddr structure, and on output > specifies the length of the stored address. Fixes ziglang#6832. --- lib/std/os/linux.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 357660a05a..6d05d3b920 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1003,14 +1003,14 @@ pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usiz return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0])); } -pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { +pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize { if (builtin.arch == .i386) { return socketcall(SC_accept, &[4]usize{ fd, addr, len, 0 }); } return accept4(fd, addr, len, 0); } -pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize { +pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize { if (builtin.arch == .i386) { return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags }); }