unix: add NetBSD support in core.c

NetBSD supports:
 - O_CLOEXEC
 - accept4(2) like API with paccept(2)
   NetBSD 8.0 will get compat accept4(2)
 - SOCK_NONBLOCK
 - SOCK_CLOEXEC
 - dup3(2)

PR-URL: https://github.com/libuv/libuv/pull/1534
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Kamil Rytarowski 2017-09-10 00:16:36 +02:00 committed by cjihrig
parent fbb8132d90
commit c0504885ea
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5

View File

@ -58,13 +58,19 @@
#if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__)
defined(__FreeBSD_kernel__) || \
defined(__NetBSD__)
# include <sys/sysctl.h>
# include <sys/filio.h>
# include <sys/wait.h>
# define UV__O_CLOEXEC O_CLOEXEC
# if defined(__FreeBSD__) && __FreeBSD__ >= 10
# define uv__accept4 accept4
# endif
# if defined(__NetBSD__)
# define uv__accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d))
# endif
# if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__)
# define UV__SOCK_NONBLOCK SOCK_NONBLOCK
# define UV__SOCK_CLOEXEC SOCK_CLOEXEC
# endif
@ -462,7 +468,9 @@ int uv__accept(int sockfd) {
assert(sockfd >= 0);
while (1) {
#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 10)
#if defined(__linux__) || \
(defined(__FreeBSD__) && __FreeBSD__ >= 10) || \
defined(__NetBSD__)
static int no_accept4;
if (no_accept4)
@ -988,7 +996,7 @@ int uv__open_cloexec(const char* path, int flags) {
int uv__dup2_cloexec(int oldfd, int newfd) {
int r;
#if defined(__FreeBSD__) && __FreeBSD__ >= 10
#if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__)
r = dup3(oldfd, newfd, O_CLOEXEC);
if (r == -1)
return -errno;