summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2018-05-25 00:59:58 -0500
committerGerrit Code Review2018-05-25 00:59:58 -0500
commite82401e592c6c45eca854525c91530ef8422db40 (patch)
treed48a98b4e800a88a3da46e45a31ca6dbca0a8b66
parent6c9bb058c5801bd2fd52ceabd0aecd96776f0e71 (diff)
parent6e1246c234bdfc41ff80b6d23599c56284d297ad (diff)
downloadplatform-system-core-e82401e592c6c45eca854525c91530ef8422db40.tar.gz
platform-system-core-e82401e592c6c45eca854525c91530ef8422db40.tar.xz
platform-system-core-e82401e592c6c45eca854525c91530ef8422db40.zip
Merge "adb: really fix the mac build."
-rw-r--r--adb/Android.bp1
-rw-r--r--adb/adb_unique_fd.cpp65
-rw-r--r--adb/adb_unique_fd.h41
3 files changed, 67 insertions, 40 deletions
diff --git a/adb/Android.bp b/adb/Android.bp
index ee1bdaa29..553473f19 100644
--- a/adb/Android.bp
+++ b/adb/Android.bp
@@ -96,6 +96,7 @@ libadb_srcs = [
96 "adb_io.cpp", 96 "adb_io.cpp",
97 "adb_listeners.cpp", 97 "adb_listeners.cpp",
98 "adb_trace.cpp", 98 "adb_trace.cpp",
99 "adb_unique_fd.cpp",
99 "adb_utils.cpp", 100 "adb_utils.cpp",
100 "fdevent.cpp", 101 "fdevent.cpp",
101 "services.cpp", 102 "services.cpp",
diff --git a/adb/adb_unique_fd.cpp b/adb/adb_unique_fd.cpp
new file mode 100644
index 000000000..2079be152
--- /dev/null
+++ b/adb/adb_unique_fd.cpp
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "adb_unique_fd.h"
18
19#include <errno.h>
20#include <unistd.h>
21
22#include "sysdeps.h"
23
24#if !defined(_WIN32)
25bool Pipe(unique_fd* read, unique_fd* write, int flags) {
26 int pipefd[2];
27#if !defined(__APPLE__)
28 if (pipe2(pipefd, flags) != 0) {
29 return false;
30 }
31#else
32 // Darwin doesn't have pipe2. Implement it ourselves.
33 if (flags != 0 && (flags & ~(O_CLOEXEC | O_NONBLOCK)) != 0) {
34 errno = EINVAL;
35 return false;
36 }
37
38 if (pipe(pipefd) != 0) {
39 return false;
40 }
41
42 if (flags & O_CLOEXEC) {
43 if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) != 0 ||
44 fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) != 0) {
45 adb_close(pipefd[0]);
46 adb_close(pipefd[1]);
47 return false;
48 }
49 }
50
51 if (flags & O_NONBLOCK) {
52 if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) != 0 ||
53 fcntl(pipefd[1], F_SETFL, O_NONBLOCK) != 0) {
54 adb_close(pipefd[0]);
55 adb_close(pipefd[1]);
56 return false;
57 }
58 }
59#endif
60
61 read->reset(pipefd[0]);
62 write->reset(pipefd[1]);
63 return true;
64}
65#endif
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