Portable build framework for OpenNTPD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
487 B

  1. #define SOCKET_FLAGS_PRIV
  2. #include <sys/socket.h>
  3. #ifdef NEED_SOCKET_FLAGS
  4. #include <fcntl.h>
  5. int
  6. _socket(int domain, int type, int protocol)
  7. {
  8. int s = socket(domain, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK), protocol);
  9. int flags;
  10. if (s == -1)
  11. return s;
  12. if (type & SOCK_CLOEXEC) {
  13. flags = fcntl(s, F_GETFD);
  14. fcntl(s, F_SETFD, flags | FD_CLOEXEC);
  15. }
  16. if (type & SOCK_NONBLOCK) {
  17. flags = fcntl(s, F_GETFL);
  18. fcntl(s, F_SETFL, flags | O_NONBLOCK);
  19. }
  20. return s;
  21. }
  22. #endif