diff options
| author | Elliott Hughes <enh@google.com> | 2015-02-03 15:31:07 -0800 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2015-02-03 15:31:07 -0800 |
| commit | be95c1599783ffd4cf0661db263c2e6783e27d6e (patch) | |
| tree | 51b8c053ac48836c16a08be06f5d68d5fff8ab7a /server/InterfaceController.cpp | |
| parent | c9692899c936d2d45f9c52f94b9847bd9de86bae (diff) | |
Use StringPrintf.
This doesn't replace every asprintf in netd, but it replaces the ones in code
I touched.
Change-Id: I2de5c7772523372bb36145e66e885aa8132ad58e
Diffstat (limited to 'server/InterfaceController.cpp')
| -rw-r--r-- | server/InterfaceController.cpp | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/server/InterfaceController.cpp b/server/InterfaceController.cpp index 64b8453a..5bca4133 100644 --- a/server/InterfaceController.cpp +++ b/server/InterfaceController.cpp @@ -21,6 +21,7 @@ #define LOG_TAG "InterfaceController" #include <cutils/log.h> #include <utils/file.h> +#include <utils/stringprintf.h> #include "InterfaceController.h" #include "RouteController.h" @@ -44,15 +45,12 @@ InterfaceController::~InterfaceController() { } int InterfaceController::writeIPv6ProcPath(const char *interface, const char *setting, const char *value) { - char *path; if (!isIfaceName(interface)) { errno = ENOENT; return -1; } - asprintf(&path, "%s/%s/%s", ipv6_proc_path, interface, setting); - bool success = android::WriteStringToFile(value, path); - free(path); - return success; + std::string path(android::StringPrintf("%s/%s/%s", ipv6_proc_path, interface, setting)); + return android::WriteStringToFile(value, path); } int InterfaceController::setEnableIPv6(const char *interface, const int on) { @@ -106,21 +104,16 @@ void InterfaceController::setAcceptRA(const char *value) { // ID to get the table. If it's set to -1000, routes from interface ID 5 will go into // table 1005, etc. void InterfaceController::setAcceptRARouteTable(int tableOrOffset) { - char* value; - asprintf(&value, "%d", tableOrOffset); - setOnAllInterfaces("accept_ra_rt_table", value); - free(value); + std::string value(android::StringPrintf("%d", tableOrOffset)); + setOnAllInterfaces("accept_ra_rt_table", value.c_str()); } int InterfaceController::setMtu(const char *interface, const char *mtu) { - char *path; if (!isIfaceName(interface)) { errno = ENOENT; return -1; } - asprintf(&path, "%s/%s/mtu", sys_net_path, interface); - bool success = android::WriteStringToFile(mtu, path); - free(path); - return success; + std::string path(android::StringPrintf("%s/%s/mtu", sys_net_path, interface)); + return android::WriteStringToFile(mtu, path); } |
