summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'adb/adb_unique_fd.h')
-rw-r--r--adb/adb_unique_fd.h41
1 files changed, 1 insertions, 40 deletions
diff --git a/adb/adb_unique_fd.h b/adb/adb_unique_fd.h
index d1dc9d10e..be6326255 100644
--- a/adb/adb_unique_fd.h
+++ b/adb/adb_unique_fd.h
@@ -29,44 +29,5 @@ struct AdbCloser {
29using unique_fd = android::base::unique_fd_impl<AdbCloser>; 29using unique_fd = android::base::unique_fd_impl<AdbCloser>;
30 30
31#if !defined(_WIN32) 31#if !defined(_WIN32)
32inline bool Pipe(unique_fd* read, unique_fd* write, int flags = 0) { 32bool Pipe(unique_fd* read, unique_fd* write, int flags = 0);
33 int pipefd[2];
34#if !defined(__APPLE__)
35 if (pipe2(pipefd, flags) != 0) {
36 return false;
37 }
38#else
39 // Darwin doesn't have pipe2. Implement it ourselves.
40 if (flags != 0 && (flags & ~(O_CLOEXEC | O_NONBLOCK)) != 0) {
41 errno = EINVAL;
42 return false;
43 }
44
45 if (pipe(pipefd) != 0) {
46 return false;
47 }
48
49 if (flags & O_CLOEXEC) {
50 if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) != 0 ||
51 fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) != 0) {
52 close(pipefd[0]);
53 close(pipefd[1]);
54 return false;
55 }
56 }
57
58 if (flags & O_NONBLOCK) {
59 if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) != 0 ||
60 fcntl(pipefd[1], F_SETFL, O_NONBLOCK) != 0) {
61 close(pipefd[0]);
62 close(pipefd[1]);
63 return false;
64 }
65 }
66#endif
67
68 read->reset(pipefd[0]);
69 write->reset(pipefd[1]);
70 return true;
71}
72#endif 33#endif