From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/network/socketpair.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/network/socketpair.c (limited to 'src/network/socketpair.c') diff --git a/src/network/socketpair.c b/src/network/socketpair.c new file mode 100644 index 0000000..f348962 --- /dev/null +++ b/src/network/socketpair.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include "syscall.h" + +int socketpair(int domain, int type, int protocol, int fd[2]) +{ + int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0); + if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT) + && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) { + r = socketcall(socketpair, domain, + type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK), + protocol, fd, 0, 0); + if (r < 0) return r; + if (type & SOCK_CLOEXEC) { + __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); + __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); + } + if (type & SOCK_NONBLOCK) { + __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); + __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); + } + } + return r; +} -- cgit v1.2.3