Merge "Convert system/core to Result::ok()"
diff --git a/base/include/android-base/result.h b/base/include/android-base/result.h
index 52fb6e7..4a59552 100644
--- a/base/include/android-base/result.h
+++ b/base/include/android-base/result.h
@@ -156,11 +156,11 @@
Error& operator=(const Error&) = delete;
Error& operator=(Error&&) = delete;
- template <typename... Args>
- friend Error Errorf(const char* fmt, const Args&... args);
+ template <typename T, typename... Args>
+ friend Error ErrorfImpl(const T&& fmt, const Args&... args);
- template <typename... Args>
- friend Error ErrnoErrorf(const char* fmt, const Args&... args);
+ template <typename T, typename... Args>
+ friend Error ErrnoErrorfImpl(const T&& fmt, const Args&... args);
private:
Error(bool append_errno, int errno_to_append, const std::string& message)
@@ -191,16 +191,24 @@
return ErrorCode(code, args...);
}
-template <typename... Args>
-inline Error Errorf(const char* fmt, const Args&... args) {
+// TODO(tomcherry): Remove this once we've removed all `using android::base::Errorf` and `using
+// android::base::ErrnoErrorf` lines.
+enum Errorf {};
+enum ErrnoErrorf {};
+
+template <typename T, typename... Args>
+inline Error ErrorfImpl(const T&& fmt, const Args&... args) {
return Error(false, ErrorCode(0, args...), fmt::format(fmt, args...));
}
-template <typename... Args>
-inline Error ErrnoErrorf(const char* fmt, const Args&... args) {
+template <typename T, typename... Args>
+inline Error ErrnoErrorfImpl(const T&& fmt, const Args&... args) {
return Error(true, errno, fmt::format(fmt, args...));
}
+#define Errorf(fmt, ...) android::base::ErrorfImpl(FMT_STRING(fmt), ##__VA_ARGS__)
+#define ErrnoErrorf(fmt, ...) android::base::ErrnoErrorfImpl(FMT_STRING(fmt), ##__VA_ARGS__)
+
template <typename T>
using Result = android::base::expected<T, ResultError>;
diff --git a/base/result_test.cpp b/base/result_test.cpp
index 2908477..c0ac0fd 100644
--- a/base/result_test.cpp
+++ b/base/result_test.cpp
@@ -362,7 +362,7 @@
result = Errorf("{} {}!", std::string("hello"), std::string("world"));
EXPECT_EQ("hello world!", result.error().message());
- result = Errorf("{h} {w}!", fmt::arg("w", "world"), fmt::arg("h", "hello"));
+ result = Errorf("{1} {0}!", "world", "hello");
EXPECT_EQ("hello world!", result.error().message());
result = Errorf("hello world!");
diff --git a/fastboot/constants.h b/fastboot/constants.h
index aefd448..ba43ca5 100644
--- a/fastboot/constants.h
+++ b/fastboot/constants.h
@@ -42,7 +42,7 @@
#define RESPONSE_INFO "INFO"
#define FB_COMMAND_SZ 64
-#define FB_RESPONSE_SZ 64
+#define FB_RESPONSE_SZ 256
#define FB_VAR_VERSION "version"
#define FB_VAR_VERSION_BOOTLOADER "version-bootloader"
diff --git a/init/result.h b/init/result.h
index b70dd1b..8c1f91e 100644
--- a/init/result.h
+++ b/init/result.h
@@ -22,8 +22,6 @@
#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_utils.cpp b/init/service_utils.cpp
index d33145a..484c2c8 100644
--- a/init/service_utils.cpp
+++ b/init/service_utils.cpp
@@ -249,9 +249,8 @@
for (const auto& rlimit : attr.rlimits) {
if (setrlimit(rlimit.first, &rlimit.second) == -1) {
- return ErrnoError() << StringPrintf(
- "setrlimit(%d, {rlim_cur=%ld, rlim_max=%ld}) failed", rlimit.first,
- rlimit.second.rlim_cur, rlimit.second.rlim_max);
+ return ErrnoErrorf("setrlimit({}, {{rlim_cur={}, rlim_max={}}}) failed", rlimit.first,
+ rlimit.second.rlim_cur, rlimit.second.rlim_max);
}
}