Files
zig/lib/libc/musl/src/network/socketpair.c
Andrew Kelley 49d1a4c562 move lib dirs to lib subdir
also start prefering NtDll API. so far:
 * NtQueryInformationFile
 * NtClose

adds a performance workaround for windows unicode conversion. but that
should probably be removed before merging
2019-07-15 17:54:50 -04:00

26 lines
736 B
C
Vendored

#include <sys/socket.h>
#include <fcntl.h>
#include <errno.h>
#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;
}