-// os-compatibility
-extern "C" {
-int osEpollCreateCloExec(void);
-
-static int setCloExecOrClose(int fd) {
- int flags;
-
- if (fd == -1)
- return -1;
-
- flags = fcntl(fd, F_GETFD);
- if (flags == -1)
- goto err;
-
- if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
- goto err;
-
- return fd;
-
- err:
- close(fd);
- return -1;
-}
-
-int osEpollCreateCloExec(void) {
- int fd;
-
-#ifdef EPOLL_CLOEXEC
- fd = epoll_create1(EPOLL_CLOEXEC);
- if (fd >= 0)
- return fd;
- if (errno != EINVAL)
- return -1;
-#endif
-
- fd = epoll_create(1);
- return setCloExecOrClose(fd);
-}
-} // os-compatibility