Inline functions, so that they can be used header-only.
| 99 | |
| 100 | // Inline functions, so that they can be used header-only. |
| 101 | inline bool Pipe(unique_fd* read, unique_fd* write) { |
| 102 | int pipefd[2]; |
| 103 | |
| 104 | #if defined(__linux__) |
| 105 | if (pipe2(pipefd, O_CLOEXEC) != 0) { |
| 106 | return false; |
| 107 | } |
| 108 | #else // defined(__APPLE__) |
| 109 | if (pipe(pipefd) != 0) { |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) != 0 || fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) != 0) { |
| 114 | close(pipefd[0]); |
| 115 | close(pipefd[1]); |
| 116 | return false; |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | read->reset(pipefd[0]); |
| 121 | write->reset(pipefd[1]); |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | inline bool Socketpair(int domain, int type, int protocol, unique_fd* left, unique_fd* right) { |
| 126 | int sockfd[2]; |