Use strerrorname_np() in ASSERT_ERRNO().
Hopefully this is totally unambiguous and non-confusing output:
```
Expected equality of these values:
Errno(22)
Which is: EINVAL
Errno((*__errno()))
Which is: ENOSYS
```
Test: treehugger
Change-Id: Iefe6a8a6447e76681c18256d2713e2c527081c75
diff --git a/tests/utils.cpp b/tests/utils.cpp
index e470724..0c7c552 100644
--- a/tests/utils.cpp
+++ b/tests/utils.cpp
@@ -28,7 +28,9 @@
#include "utils.h"
+#include <string.h>
#include <syscall.h>
+
#include <string>
#include <android-base/properties.h>
@@ -72,8 +74,19 @@
#endif
void PrintTo(const Errno& e, std::ostream* os) {
- // TODO: strerrorname_np() might be more useful here, but we'd need to implement it first!
- *os << strerror(e.errno_);
+ // Prefer EINVAL or whatever, but fall back to strerror() to print
+ // "Unknown error 666" for bogus values. Not that I've ever seen one,
+ // but we shouldn't be looking at an assertion failure unless something
+ // weird has happened!
+#if defined(__BIONIC__)
+ const char* errno_name = strerrorname_np(e.errno_);
+ if (errno_name != nullptr) {
+ *os << errno_name;
+ } else
+#endif
+ {
+ *os << strerror(e.errno_);
+ }
}
bool operator==(const Errno& lhs, const Errno& rhs) {