Merge "init: use Errorf() now that we have it"
diff --git a/init/keychords_test.cpp b/init/keychords_test.cpp
index a3baeb1..33373d4 100644
--- a/init/keychords_test.cpp
+++ b/init/keychords_test.cpp
@@ -29,7 +29,6 @@
#include <vector>
#include <android-base/properties.h>
-#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <gtest/gtest.h>
diff --git a/init/keyword_map.h b/init/keyword_map.h
index c95fc73..7837bb3 100644
--- a/init/keyword_map.h
+++ b/init/keyword_map.h
@@ -14,14 +14,11 @@
* limitations under the License.
*/
-#ifndef _INIT_KEYWORD_MAP_H_
-#define _INIT_KEYWORD_MAP_H_
+#pragma once
#include <map>
#include <string>
-#include <android-base/stringprintf.h>
-
#include "result.h"
namespace android {
@@ -37,8 +34,6 @@
}
const Result<Function> FindFunction(const std::vector<std::string>& args) const {
- using android::base::StringPrintf;
-
if (args.empty()) return Error() << "Keyword needed, but not provided";
auto& keyword = args[0];
@@ -46,7 +41,7 @@
auto function_info_it = map().find(keyword);
if (function_info_it == map().end()) {
- return Error() << StringPrintf("Invalid keyword '%s'", keyword.c_str());
+ return Errorf("Invalid keyword '{}'", keyword);
}
auto function_info = function_info_it->second;
@@ -54,17 +49,17 @@
auto min_args = std::get<0>(function_info);
auto max_args = std::get<1>(function_info);
if (min_args == max_args && num_args != min_args) {
- return Error() << StringPrintf("%s requires %zu argument%s", keyword.c_str(), min_args,
- (min_args > 1 || min_args == 0) ? "s" : "");
+ return Errorf("{} requires {} argument{}", keyword, min_args,
+ (min_args > 1 || min_args == 0) ? "s" : "");
}
if (num_args < min_args || num_args > max_args) {
if (max_args == std::numeric_limits<decltype(max_args)>::max()) {
- return Error() << StringPrintf("%s requires at least %zu argument%s",
- keyword.c_str(), min_args, min_args > 1 ? "s" : "");
+ return Errorf("{} requires at least {} argument{}", keyword, min_args,
+ min_args > 1 ? "s" : "");
} else {
- return Error() << StringPrintf("%s requires between %zu and %zu arguments",
- keyword.c_str(), min_args, max_args);
+ return Errorf("{} requires between {} and {} arguments", keyword, min_args,
+ max_args);
}
}
@@ -79,5 +74,3 @@
} // namespace init
} // namespace android
-
-#endif
diff --git a/init/reboot.cpp b/init/reboot.cpp
index fbc03c2..eaba3cc 100644
--- a/init/reboot.cpp
+++ b/init/reboot.cpp
@@ -41,7 +41,6 @@
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/properties.h>
-#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <bootloader_message/bootloader_message.h>
@@ -62,7 +61,6 @@
using android::base::GetBoolProperty;
using android::base::Split;
-using android::base::StringPrintf;
using android::base::Timer;
using android::base::unique_fd;
using android::base::WriteStringToFile;
diff --git a/init/result.h b/init/result.h
index 8c1f91e..b70dd1b 100644
--- a/init/result.h
+++ b/init/result.h
@@ -22,6 +22,8 @@
#include <android-base/result.h>
using android::base::ErrnoError;
+using android::base::ErrnoErrorf;
using android::base::Error;
+using android::base::Errorf;
using android::base::Result;
using android::base::ResultError;
diff --git a/init/service.cpp b/init/service.cpp
index b6a7c33..4fe374c 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -332,12 +332,11 @@
const std::string& arg = args[i];
int res = LookupCap(arg);
if (res < 0) {
- return Error() << StringPrintf("invalid capability '%s'", arg.c_str());
+ return Errorf("invalid capability '{}'", arg);
}
unsigned int cap = static_cast<unsigned int>(res); // |res| is >= 0.
if (cap > last_valid_cap) {
- return Error() << StringPrintf("capability '%s' not supported by the kernel",
- arg.c_str());
+ return Errorf("capability '{}' not supported by the kernel", arg);
}
(*capabilities_)[cap] = true;
}
@@ -402,8 +401,8 @@
if (!ParseInt(args[1], &proc_attr_.priority,
static_cast<int>(ANDROID_PRIORITY_HIGHEST), // highest is negative
static_cast<int>(ANDROID_PRIORITY_LOWEST))) {
- return Error() << StringPrintf("process priority value must be range %d - %d",
- ANDROID_PRIORITY_HIGHEST, ANDROID_PRIORITY_LOWEST);
+ return Errorf("process priority value must be range {} - {}", ANDROID_PRIORITY_HIGHEST,
+ ANDROID_PRIORITY_LOWEST);
}
return {};
}