summaryrefslogtreecommitdiffstats
path: root/adb/commandline.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-05-01 17:04:38 -0700
committerElliott Hughes <enh@google.com>2015-05-01 17:37:28 -0700
commite1a55004e9fa46055c59f86e952e9e457c36c3f2 (patch)
tree7641d408bf403954720299492240fb4690674214 /adb/commandline.cpp
parent92af733ee202caa3b5475fe27fcc81582f11e7c8 (diff)
downloadsystem_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/commandline.cpp')
-rw-r--r--adb/commandline.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index 7964cd3..b385517 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -929,9 +929,7 @@ static int adb_query_command(const std::string& command) {
return 0;
}
-int adb_commandline(int argc, const char **argv)
-{
- char buf[4096];
+int adb_commandline(int argc, const char **argv) {
int no_daemon = 0;
int is_daemon = 0;
int is_server = 0;
@@ -1266,6 +1264,7 @@ int adb_commandline(int argc, const char **argv)
}
/* adb_command() wrapper commands */
else if (!strcmp(argv[0], "forward") || !strcmp(argv[0], "reverse")) {
+ std::string cmd;
char host_prefix[64];
char reverse = (char) !strcmp(argv[0], "reverse");
char remove = 0;
@@ -1323,31 +1322,27 @@ int adb_commandline(int argc, const char **argv)
// Implement forward --remove-all
else if (remove_all) {
- if (argc != 1)
- return usage();
- snprintf(buf, sizeof buf, "%s:killforward-all", host_prefix);
+ if (argc != 1) return usage();
+ cmd = android::base::StringPrintf("%s:killforward-all", host_prefix);
}
// Implement forward --remove <local>
else if (remove) {
- if (argc != 2)
- return usage();
- snprintf(buf, sizeof buf, "%s:killforward:%s", host_prefix, argv[1]);
+ if (argc != 2) return usage();
+ cmd = android::base::StringPrintf("%s:killforward:%s", host_prefix, argv[1]);
}
// Or implement one of:
// forward <local> <remote>
// forward --no-rebind <local> <remote>
- else
- {
- if (argc != 3)
- return usage();
- const char* command = no_rebind ? "forward:norebind" : "forward";
- snprintf(buf, sizeof buf, "%s:%s:%s;%s", host_prefix, command, argv[1], argv[2]);
+ else {
+ if (argc != 3) return usage();
+ const char* command = no_rebind ? "forward:norebind" : "forward";
+ cmd = android::base::StringPrintf("%s:%s:%s;%s", host_prefix, command, argv[1], argv[2]);
}
std::string error;
- if (adb_command(buf, &error)) {
- fprintf(stderr,"error: %s\n", error.c_str());
+ if (adb_command(cmd, &error)) {
+ fprintf(stderr, "error: %s\n", error.c_str());
return 1;
}
return 0;