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
This commit is contained in:
parent
db2ffaa0f0
commit
0f29cbc750
7 changed files with 24 additions and 26 deletions
|
@ -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...
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue