Add strerrordesc_np() and strerrorname_np().
strerrordesc_np() isn't very useful (being just another name for
strerror()), but strerrorname_np() lets you get "ENOSYS" for ENOSYS,
which will make some of our test assertion messages clearer when we
switch over from strerror().
This also adds `%#m` formatting to all the relevant functions.
Test: treehugger
Change-Id: Icfe07a39a307d591c3f4f2a09d008dc021643062
diff --git a/libc/stdio/vfprintf.cpp b/libc/stdio/vfprintf.cpp
index 12cceeb..e0509aa 100644
--- a/libc/stdio/vfprintf.cpp
+++ b/libc/stdio/vfprintf.cpp
@@ -340,6 +340,7 @@
case 'd':
case 'i':
_umax = SARG();
+signed_decimal:
if ((intmax_t)_umax < 0) {
_umax = -_umax;
sign = '-';
@@ -468,7 +469,15 @@
case 'n':
__fortify_fatal("%%n not allowed on Android");
case 'm':
- cp = strerror_r(caller_errno, buf, sizeof(buf));
+ if (flags & ALT) {
+ cp = const_cast<char*>(strerrorname_np(caller_errno));
+ if (cp == nullptr) {
+ _umax = caller_errno;
+ goto signed_decimal;
+ }
+ } else {
+ cp = strerror_r(caller_errno, buf, sizeof(buf));
+ }
goto string;
case 'O':
flags |= LONGINT;