Import LibreSSL v2.4.2 to vendor branch
[dragonfly.git] / crypto / libressl / apps / nc / compat / socket.c
blobfd699f9fd7dab4f38f382de97246dc5e00b38b27
1 #define SOCKET_FLAGS_PRIV
3 #include <sys/socket.h>
5 #ifdef NEED_SOCKET_FLAGS
7 #include <fcntl.h>
9 int
10 _socket(int domain, int type, int protocol)
12 int s = socket(domain, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK), protocol);
13 int flags;
14 if (s == -1)
15 return s;
17 if (type & SOCK_CLOEXEC) {
18 flags = fcntl(s, F_GETFD);
19 fcntl(s, F_SETFD, flags | FD_CLOEXEC);
22 if (type & SOCK_NONBLOCK) {
23 flags = fcntl(s, F_GETFL);
24 fcntl(s, F_SETFL, flags | O_NONBLOCK);
26 return s;
29 #endif