base: add SystemErrorCodeToString() function.
Pulls the Windows error string generation out of adb into libbase so
that it can be used by fastboot as well. Also makes a Unix equivalent
that just wraps strerror() so that upcoming fastboot error reporting
code can be platform-independent.
The intent here is just to provide a portable way to report an error to
the user. More general cross-platform error handling is out of scope.
Bug: http://b/26236380
Change-Id: I5a784a844775949562d069bb41dcb0ebd13a32bc
diff --git a/adb/client/main.cpp b/adb/client/main.cpp
index b37d04d..b7b30c5 100644
--- a/adb/client/main.cpp
+++ b/adb/client/main.cpp
@@ -27,6 +27,7 @@
#include <sched.h>
#endif
+#include <android-base/errors.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
@@ -54,7 +55,7 @@
if ((nchars >= arraysize(temp_path)) || (nchars == 0)) {
// If string truncation or some other error.
fatal("cannot retrieve temporary file path: %s\n",
- SystemErrorCodeToString(GetLastError()).c_str());
+ android::base::SystemErrorCodeToString(GetLastError()).c_str());
}
std::string temp_path_utf8;
@@ -134,7 +135,7 @@
DWORD written = 0;
if (!WriteFile(ack_reply_handle, ack, bytes_to_write, &written, NULL)) {
fatal("adb: cannot write ACK to handle 0x%p: %s", ack_reply_handle,
- SystemErrorCodeToString(GetLastError()).c_str());
+ android::base::SystemErrorCodeToString(GetLastError()).c_str());
}
if (written != bytes_to_write) {
fatal("adb: cannot write %lu bytes of ACK: only wrote %lu bytes",