X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fnetwork%2Faccept4.c;h=765a38edc37d832c9930e5cd56af347cddf3d051;hb=c499c1084eaccd83e4b6e60883a5d92df0202c5e;hp=6b5c16cebe53cb772bf8e7933c5bcc09463e046d;hpb=dc62790deec183697489d5fddea03c82f725e7fd;p=musl diff --git a/src/network/accept4.c b/src/network/accept4.c index 6b5c16ce..765a38ed 100644 --- a/src/network/accept4.c +++ b/src/network/accept4.c @@ -1,9 +1,23 @@ #define _GNU_SOURCE #include +#include +#include #include "syscall.h" -#include "libc.h" int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int flg) { - return socketcall_cp(accept4, fd, addr, len, flg, 0, 0); + if (!flg) return accept(fd, addr, len); + int ret = socketcall_cp(accept4, fd, addr, len, flg, 0, 0); + if (ret>=0 || (errno != ENOSYS && errno != EINVAL)) return ret; + if (flg & ~(SOCK_CLOEXEC|SOCK_NONBLOCK)) { + errno = EINVAL; + return -1; + } + ret = accept(fd, addr, len); + if (ret<0) return ret; + if (flg & SOCK_CLOEXEC) + __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); + if (flg & SOCK_NONBLOCK) + __syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK); + return ret; }