summaryrefslogtreecommitdiff
path: root/libcutils/android_get_control_file.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-03-21 14:42:55 -0700
committerElliott Hughes <enh@google.com>2019-03-21 14:59:45 -0700
commit7acb0d39e858c2f4251298e722ffe42ca7924156 (patch)
tree14aa480ba26fbbef606a2c48e9bce504ea3325bc /libcutils/android_get_control_file.cpp
parentee3cce8b7bd1e0fdb19a0146322030a34ad3c452 (diff)
Clean up some mess by only building Android-specific code for the device.
Test: treehugger Change-Id: Id44721ccd1817d8c537b226f60a58b7cb691fb01
Diffstat (limited to 'libcutils/android_get_control_file.cpp')
-rw-r--r--libcutils/android_get_control_file.cpp20
1 files changed, 2 insertions, 18 deletions
diff --git a/libcutils/android_get_control_file.cpp b/libcutils/android_get_control_file.cpp
index d8121f5cd..f9964d2b0 100644
--- a/libcutils/android_get_control_file.cpp
+++ b/libcutils/android_get_control_file.cpp
@@ -41,12 +41,7 @@
#include "android_get_control_env.h"
-#ifndef TEMP_FAILURE_RETRY
-#define TEMP_FAILURE_RETRY(exp) (exp) // KISS implementation
-#endif
-
-LIBCUTILS_HIDDEN int __android_get_control_from_env(const char* prefix,
- const char* name) {
+int __android_get_control_from_env(const char* prefix, const char* name) {
if (!prefix || !name) return -1;
char *key = NULL;
@@ -67,20 +62,11 @@ LIBCUTILS_HIDDEN int __android_get_control_from_env(const char* prefix,
long fd = strtol(val, NULL, 10);
if (errno) return -1;
- // validity checking
- if ((fd < 0) || (fd > INT_MAX)) return -1;
-
// Since we are inheriting an fd, it could legitimately exceed _SC_OPEN_MAX
+ if ((fd < 0) || (fd > INT_MAX)) return -1;
// Still open?
-#if defined(F_GETFD) // Lowest overhead
if (TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD)) < 0) return -1;
-#elif defined(F_GETFL) // Alternate lowest overhead
- if (TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)) < 0) return -1;
-#else // Hail Mary pass
- struct stat s;
- if (TEMP_FAILURE_RETRY(fstat(fd, &s)) < 0) return -1;
-#endif
return static_cast<int>(fd);
}
@@ -88,7 +74,6 @@ LIBCUTILS_HIDDEN int __android_get_control_from_env(const char* prefix,
int android_get_control_file(const char* path) {
int fd = __android_get_control_from_env(ANDROID_FILE_ENV_PREFIX, path);
-#if defined(__linux__)
// Find file path from /proc and make sure it is correct
char *proc = NULL;
if (asprintf(&proc, "/proc/self/fd/%d", fd) < 0) return -1;
@@ -108,7 +93,6 @@ int android_get_control_file(const char* path) {
if (ret < 0) return -1;
if (cmp != 0) return -1;
// It is what we think it is
-#endif
return fd;
}