diff options
author | Yurii Zubrytskyi <zyy@google.com> | 2016-05-26 09:46:10 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-05-27 14:43:26 -0700 |
commit | dace01526996ee221796c4627a615d393eee205b (patch) | |
tree | 0c10e33d6686be551d8c5327515e97f5998fbecb | |
parent | 7c0835f66b6881d342f9b23de7e355db4e63a7f2 (diff) | |
download | core-dace01526996ee221796c4627a615d393eee205b.tar.gz core-dace01526996ee221796c4627a615d393eee205b.tar.bz2 core-dace01526996ee221796c4627a615d393eee205b.zip |
[adb] Followup CL to clean up adb_auth_host.cpp
Get rid of unused includes + replace a fixed-size buffer with an
std::string
(cherry-pick of 049ebb810f466d916ec9e73cdf28624b57a8c25d.)
Change-Id: I4f9927b900a79a012b5d52908b9d22ac3d2a401c
-rw-r--r-- | adb/adb_auth_host.cpp | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/adb/adb_auth_host.cpp b/adb/adb_auth_host.cpp index 207b6a4bd..07356947d 100644 --- a/adb/adb_auth_host.cpp +++ b/adb/adb_auth_host.cpp @@ -24,15 +24,10 @@ #include <stdlib.h> #include <string.h> -#ifndef _WIN32 -# include <sys/types.h> -# include <sys/stat.h> -# include <unistd.h> -#endif - #include "adb.h" #include <android-base/errors.h> +#include <android-base/stringprintf.h> #include <android-base/strings.h> #include <crypto_utils/android_pubkey.h> #include <cutils/list.h> @@ -242,25 +237,23 @@ static int read_key(const char *file, struct listnode *list) static int get_user_keyfilepath(char *filename, size_t len) { - char android_dir[PATH_MAX]; - struct stat buf; - - std::string home = adb_get_homedir_path(true); + const std::string home = adb_get_homedir_path(true); D("home '%s'", home.c_str()); - if (snprintf(android_dir, sizeof(android_dir), "%s%c%s", home.c_str(), - OS_PATH_SEPARATOR, ANDROID_PATH) >= (int)sizeof(android_dir)) - return -1; + const std::string android_dir = + android::base::StringPrintf("%s%c%s", home.c_str(), + OS_PATH_SEPARATOR, ANDROID_PATH); - if (stat(android_dir, &buf)) { - if (adb_mkdir(android_dir, 0750) < 0) { - D("Cannot mkdir '%s'", android_dir); + struct stat buf; + if (stat(android_dir.c_str(), &buf)) { + if (adb_mkdir(android_dir.c_str(), 0750) < 0) { + D("Cannot mkdir '%s'", android_dir.c_str()); return -1; } } - return snprintf(filename, len, "%s%c%s", android_dir, OS_PATH_SEPARATOR, - ADB_KEY_FILE); + return snprintf(filename, len, "%s%c%s", + android_dir.c_str(), OS_PATH_SEPARATOR, ADB_KEY_FILE); } static int get_user_key(struct listnode *list) |