summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/network/accept4.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-top-half/musl/src/network/accept4.c')
-rw-r--r--libc-top-half/musl/src/network/accept4.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/network/accept4.c b/libc-top-half/musl/src/network/accept4.c
new file mode 100644
index 0000000..59ab172
--- /dev/null
+++ b/libc-top-half/musl/src/network/accept4.c
@@ -0,0 +1,19 @@
+#define _GNU_SOURCE
+#include <sys/socket.h>
+#include <errno.h>
+#include <fcntl.h>
+#include "syscall.h"
+
+int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int flg)
+{
+ 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;
+ 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;
+}