diff options
author | Josh Gao <jmgao@google.com> | 2018-12-12 16:12:28 -0800 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2018-12-21 01:43:31 -0800 |
commit | 0f29cbc7500311264ee8e6f551e7ca10b58d0d1a (patch) | |
tree | 08b04f17ab2b565bb90ec79316a20dd8642237cd | |
parent | db2ffaa0f0537a11957ae4f4b93cc41b9fa6fd30 (diff) | |
download | system_core-0f29cbc7500311264ee8e6f551e7ca10b58d0d1a.tar.gz system_core-0f29cbc7500311264ee8e6f551e7ca10b58d0d1a.tar.bz2 system_core-0f29cbc7500311264ee8e6f551e7ca10b58d0d1a.zip |
adb: switch unix_open to string_view.
Test: test_adb.py
Test: test_device.py
Test: $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test
Test: adb shell /data/nativetest64/adbd_test/adbd_test
Change-Id: Ieecc9b1b7f2111f4da45d4bbd1b7703535fe7d4d
-rw-r--r-- | adb/adb.cpp | 2 | ||||
-rw-r--r-- | adb/adb_trace.cpp | 3 | ||||
-rw-r--r-- | adb/client/main.cpp | 2 | ||||
-rw-r--r-- | adb/client/usb_linux.cpp | 6 | ||||
-rw-r--r-- | adb/daemon/remount_service.cpp | 2 | ||||
-rw-r--r-- | adb/sysdeps.h | 28 | ||||
-rw-r--r-- | adb/sysdeps_win32.cpp | 7 |
7 files changed, 24 insertions, 26 deletions
diff --git a/adb/adb.cpp b/adb/adb.cpp index 9c0eecafc..c78b96b6d 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -600,7 +600,7 @@ static void ReportServerStartupFailure(pid_t pid) { fprintf(stderr, "Full server startup log: %s\n", GetLogFilePath().c_str()); fprintf(stderr, "Server had pid: %d\n", pid); - android::base::unique_fd fd(unix_open(GetLogFilePath().c_str(), O_RDONLY)); + android::base::unique_fd fd(unix_open(GetLogFilePath(), O_RDONLY)); if (fd == -1) return; // Let's not show more than 128KiB of log... diff --git a/adb/adb_trace.cpp b/adb/adb_trace.cpp index a024a89bf..2bd6a3ea1 100644 --- a/adb/adb_trace.cpp +++ b/adb/adb_trace.cpp @@ -72,8 +72,7 @@ static std::string get_log_file_name() { } void start_device_log(void) { - int fd = unix_open(get_log_file_name().c_str(), - O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0640); + int fd = unix_open(get_log_file_name(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0640); if (fd == -1) { return; } diff --git a/adb/client/main.cpp b/adb/client/main.cpp index fb581a6a6..2ee81a994 100644 --- a/adb/client/main.cpp +++ b/adb/client/main.cpp @@ -40,7 +40,7 @@ static void setup_daemon_logging() { const std::string log_file_path(GetLogFilePath()); - int fd = unix_open(log_file_path.c_str(), O_WRONLY | O_CREAT | O_APPEND, 0640); + int fd = unix_open(log_file_path, O_WRONLY | O_CREAT | O_APPEND, 0640); if (fd == -1) { PLOG(FATAL) << "cannot open " << log_file_path; } diff --git a/adb/client/usb_linux.cpp b/adb/client/usb_linux.cpp index f1bf559a9..6b6e3e3f2 100644 --- a/adb/client/usb_linux.cpp +++ b/adb/client/usb_linux.cpp @@ -156,7 +156,7 @@ static void find_usb_device(const std::string& base, continue; } - int fd = unix_open(dev_name.c_str(), O_RDONLY | O_CLOEXEC); + int fd = unix_open(dev_name, O_RDONLY | O_CLOEXEC); if (fd == -1) { continue; } @@ -535,10 +535,10 @@ static void register_device(const char* dev_name, const char* dev_path, unsigned // Initialize mark so we don't get garbage collected after the device scan. usb->mark = true; - usb->fd = unix_open(usb->path.c_str(), O_RDWR | O_CLOEXEC); + usb->fd = unix_open(usb->path, O_RDWR | O_CLOEXEC); if (usb->fd == -1) { // Opening RW failed, so see if we have RO access. - usb->fd = unix_open(usb->path.c_str(), O_RDONLY | O_CLOEXEC); + usb->fd = unix_open(usb->path, O_RDONLY | O_CLOEXEC); if (usb->fd == -1) { D("[ usb open %s failed: %s]", usb->path.c_str(), strerror(errno)); return; diff --git a/adb/daemon/remount_service.cpp b/adb/daemon/remount_service.cpp index 1a923173d..80b3e06e6 100644 --- a/adb/daemon/remount_service.cpp +++ b/adb/daemon/remount_service.cpp @@ -103,7 +103,7 @@ bool dev_is_overlayfs(const std::string& dev) { bool make_block_device_writable(const std::string& dev) { if (dev_is_overlayfs(dev)) return true; - int fd = unix_open(dev.c_str(), O_RDONLY | O_CLOEXEC); + int fd = unix_open(dev, O_RDONLY | O_CLOEXEC); if (fd == -1) { return false; } diff --git a/adb/sysdeps.h b/adb/sysdeps.h index b8d7e06b0..15247e722 100644 --- a/adb/sysdeps.h +++ b/adb/sysdeps.h @@ -27,6 +27,7 @@ #include <errno.h> #include <string> +#include <string_view> #include <vector> // Include this before open/close/unlink are defined as macros below. @@ -139,7 +140,7 @@ static __inline__ int adb_open_mode(const char* path, int options, int mode) } // See the comments for the !defined(_WIN32) version of unix_open(). -extern int unix_open(const char* path, int options, ...); +extern int unix_open(std::string_view path, int options, ...); #define open ___xxx_unix_open // Checks if |fd| corresponds to a console. @@ -357,20 +358,17 @@ static __inline__ void close_on_exec(int fd) // by unix_read(), unix_write(), unix_close()). Also, the C Runtime has // configurable CR/LF translation which defaults to text mode, but is settable // with _setmode(). -static __inline__ int unix_open(const char* path, int options,...) -{ - if ((options & O_CREAT) == 0) - { - return TEMP_FAILURE_RETRY( open(path, options) ); - } - else - { - int mode; - va_list args; - va_start( args, options ); - mode = va_arg( args, int ); - va_end( args ); - return TEMP_FAILURE_RETRY( open( path, options, mode ) ); +static __inline__ int unix_open(std::string_view path, int options, ...) { + std::string zero_terminated(path.begin(), path.end()); + if ((options & O_CREAT) == 0) { + return TEMP_FAILURE_RETRY(open(zero_terminated.c_str(), options)); + } else { + int mode; + va_list args; + va_start(args, options); + mode = va_arg(args, int); + va_end(args); + return TEMP_FAILURE_RETRY(open(zero_terminated.c_str(), options, mode)); } } diff --git a/adb/sysdeps_win32.cpp b/adb/sysdeps_win32.cpp index 8a6541d60..dbc892064 100644 --- a/adb/sysdeps_win32.cpp +++ b/adb/sysdeps_win32.cpp @@ -29,6 +29,7 @@ #include <memory> #include <mutex> #include <string> +#include <string_view> #include <unordered_map> #include <vector> @@ -2203,15 +2204,15 @@ NarrowArgs::~NarrowArgs() { } } -int unix_open(const char* path, int options, ...) { +int unix_open(std::string_view path, int options, ...) { std::wstring path_wide; - if (!android::base::UTF8ToWide(path, &path_wide)) { + if (!android::base::UTF8ToWide(path.data(), path.size(), &path_wide)) { return -1; } if ((options & O_CREAT) == 0) { return _wopen(path_wide.c_str(), options); } else { - int mode; + int mode; va_list args; va_start(args, options); mode = va_arg(args, int); |