Loading base/include/android-base/unique_fd.h +19 −6 Original line number Diff line number Diff line Loading @@ -161,23 +161,36 @@ using unique_fd = unique_fd_impl<DefaultCloser>; // Inline functions, so that they can be used header-only. template <typename Closer> inline bool Pipe(unique_fd_impl<Closer>* read, unique_fd_impl<Closer>* write) { inline bool Pipe(unique_fd_impl<Closer>* read, unique_fd_impl<Closer>* write, int flags = O_CLOEXEC) { int pipefd[2]; #if defined(__linux__) if (pipe2(pipefd, O_CLOEXEC) != 0) { if (pipe2(pipefd, flags) != 0) { return false; } #else // defined(__APPLE__) if (flags & ~(O_CLOEXEC | O_NONBLOCK)) { return false; } if (pipe(pipefd) != 0) { return false; } if (flags & O_CLOEXEC) { if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) != 0 || fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) != 0) { close(pipefd[0]); close(pipefd[1]); return false; } } if (flags & O_NONBLOCK) { if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) != 0 || fcntl(pipefd[1], F_SETFL, O_NONBLOCK) != 0) { close(pipefd[0]); close(pipefd[1]); return false; } } #endif read->reset(pipefd[0]); Loading Loading
base/include/android-base/unique_fd.h +19 −6 Original line number Diff line number Diff line Loading @@ -161,23 +161,36 @@ using unique_fd = unique_fd_impl<DefaultCloser>; // Inline functions, so that they can be used header-only. template <typename Closer> inline bool Pipe(unique_fd_impl<Closer>* read, unique_fd_impl<Closer>* write) { inline bool Pipe(unique_fd_impl<Closer>* read, unique_fd_impl<Closer>* write, int flags = O_CLOEXEC) { int pipefd[2]; #if defined(__linux__) if (pipe2(pipefd, O_CLOEXEC) != 0) { if (pipe2(pipefd, flags) != 0) { return false; } #else // defined(__APPLE__) if (flags & ~(O_CLOEXEC | O_NONBLOCK)) { return false; } if (pipe(pipefd) != 0) { return false; } if (flags & O_CLOEXEC) { if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) != 0 || fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) != 0) { close(pipefd[0]); close(pipefd[1]); return false; } } if (flags & O_NONBLOCK) { if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) != 0 || fcntl(pipefd[1], F_SETFL, O_NONBLOCK) != 0) { close(pipefd[0]); close(pipefd[1]); return false; } } #endif read->reset(pipefd[0]); Loading