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.

51 lines
1019 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. int
  23. _socketpair(int domain, int type, int protocol, int socket_vector[2])
  24. {
  25. int rc = socketpair(domain, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK), protocol, socket_vector);
  26. int flags, i;
  27. if (rc == -1)
  28. return rc;
  29. for (i = 0; i < 2; i++) {
  30. if (type & SOCK_CLOEXEC) {
  31. flags = fcntl(socket_vector[i], F_GETFD);
  32. fcntl(socket_vector[i], F_SETFD, flags | FD_CLOEXEC);
  33. }
  34. if (type & SOCK_NONBLOCK) {
  35. flags = fcntl(socket_vector[i], F_GETFL);
  36. fcntl(socket_vector[i], F_SETFL, flags | O_NONBLOCK);
  37. }
  38. }
  39. return rc;
  40. }
  41. #endif