diff options
author | Elliott Hughes <enh@google.com> | 2015-05-01 17:04:38 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-05-01 17:37:28 -0700 |
commit | e1a55004e9fa46055c59f86e952e9e457c36c3f2 (patch) | |
tree | 7641d408bf403954720299492240fb4690674214 /adb/adb_io.cpp | |
parent | 92af733ee202caa3b5475fe27fcc81582f11e7c8 (diff) | |
download | system_core-e1a55004e9fa46055c59f86e952e9e457c36c3f2.zip system_core-e1a55004e9fa46055c59f86e952e9e457c36c3f2.tar.gz system_core-e1a55004e9fa46055c59f86e952e9e457c36c3f2.tar.bz2 |
Add WriteFdFmt and clean up more code.
Also say *which* device wasn't found.
Bug: http://b/20666660
Change-Id: I50e234ad89e39ae0a8995083c0b642c61275c5a3
(cherry picked from commit ab52c181fa4c1c9891644635dc5653cda5b90e2b)
Diffstat (limited to 'adb/adb_io.cpp')
-rw-r--r-- | adb/adb_io.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/adb/adb_io.cpp b/adb/adb_io.cpp index c34daf9..5ae6ec3 100644 --- a/adb/adb_io.cpp +++ b/adb/adb_io.cpp @@ -16,13 +16,15 @@ #define TRACE_TAG TRACE_RWX -#include "sysdeps.h" #include "adb_io.h" #include <unistd.h> +#include <base/stringprintf.h> + #include "adb_trace.h" #include "adb_utils.h" +#include "sysdeps.h" bool SendProtocolString(int fd, const std::string& s) { int length = s.size(); @@ -30,9 +32,7 @@ bool SendProtocolString(int fd, const std::string& s) { length = 0xffff; } - char buf[5]; - snprintf(buf, sizeof(buf), "%04x", length); - return WriteFdExactly(fd, buf, 4) && WriteFdExactly(fd, s); + return WriteFdFmt(fd, "%04x", length) && WriteFdExactly(fd, s); } bool SendOkay(int fd) { @@ -111,6 +111,13 @@ bool WriteFdExactly(int fd, const std::string& str) { return WriteFdExactly(fd, str.c_str(), str.size()); } -bool WriteStringFully(int fd, const char* str) { - return WriteFdExactly(fd, str, strlen(str)); +bool WriteFdFmt(int fd, const char* fmt, ...) { + std::string str; + + va_list ap; + va_start(ap, fmt); + android::base::StringAppendV(&str, fmt, ap); + va_end(ap); + + return WriteFdExactly(fd, str); } |