From 4221e2cc038a6f6ca9b67e6e7fae019a3a601c11 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 29 Aug 2017 21:28:06 -0700 Subject: [PATCH] base: hopefully fix the mac build. Test: none Change-Id: Idd4f353a158a0c096d16ecf87e239c50aba79cf7 --- base/include/android-base/unique_fd.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/base/include/android-base/unique_fd.h b/base/include/android-base/unique_fd.h index fb3ddedaa..5d8927198 100644 --- a/base/include/android-base/unique_fd.h +++ b/base/include/android-base/unique_fd.h @@ -100,9 +100,23 @@ using unique_fd = unique_fd_impl; // Inline functions, so that they can be used header-only. inline bool Pipe(unique_fd* read, unique_fd* write) { int pipefd[2]; + +#if defined(__linux__) if (pipe2(pipefd, O_CLOEXEC) != 0) { return false; } +#else // defined(__APPLE__) + if (pipe(pipefd) != 0) { + return false; + } + + 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; + } +#endif + read->reset(pipefd[0]); write->reset(pipefd[1]); return true;