Merge branch 'vendor/LIBRESSL'
[dragonfly.git] / crypto / libressl / apps / nc / compat / socket.c
1 #define SOCKET_FLAGS_PRIV
2
3 #include <sys/socket.h>
4
5 #ifdef NEED_SOCKET_FLAGS
6
7 #include <fcntl.h>
8
9 int
10 _socket(int domain, int type, int protocol)
11 {
12         int s = socket(domain, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK), protocol);
13         int flags;
14         if (s == -1)
15                 return s;
16
17         if (type & SOCK_CLOEXEC) {
18                 flags = fcntl(s, F_GETFD);
19                 fcntl(s, F_SETFD, flags | FD_CLOEXEC);
20         }
21
22         if (type & SOCK_NONBLOCK) {
23                 flags = fcntl(s, F_GETFL);
24                 fcntl(s, F_SETFL, flags | O_NONBLOCK);
25         }
26         return s;
27 }
28
29 #endif