diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-12-23 15:01:07 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-12-23 15:02:50 +0100 |
commit | 9702a7901e18460e8ffc5f56a493d41294a8e936 (patch) | |
tree | 0e7147c9c7e3d4cb14d3474c9dd947dcf64b38a9 /stdio-common/vfprintf-internal.c | |
parent | cd0c333d2ea82d0ae14719bdbef86d99615bdb00 (diff) | |
download | glibc-9702a7901e18460e8ffc5f56a493d41294a8e936.tar.gz glibc-9702a7901e18460e8ffc5f56a493d41294a8e936.tar.xz glibc-9702a7901e18460e8ffc5f56a493d41294a8e936.zip |
stdio: Implement %#m for vfprintf and related functions
%#m prints errno as an error constant if one is available, or a decimal number as a fallback. This intends to address the gap that strerrorname_np does not work well with printf for unknown error codes due to its NULL return values in those cases. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'stdio-common/vfprintf-internal.c')
-rw-r--r-- | stdio-common/vfprintf-internal.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c index e717f50073..8547090d45 100644 --- a/stdio-common/vfprintf-internal.c +++ b/stdio-common/vfprintf-internal.c @@ -950,11 +950,26 @@ static const uint8_t jump_table[] = \ LABEL (form_strerror): \ /* Print description of error ERRNO. */ \ - string = \ - (CHAR_T *) __strerror_r (save_errno, (char *) work_buffer, \ - WORK_BUFFER_SIZE * sizeof (CHAR_T)); \ - is_long = 0; /* This is no wide-char string. */ \ - goto LABEL (print_string) + if (alt) \ + string = (CHAR_T *) __get_errname (save_errno); \ + else \ + string = (CHAR_T *) __strerror_r (save_errno, (char *) work_buffer, \ + WORK_BUFFER_SIZE * sizeof (CHAR_T));\ + if (string == NULL) \ + { \ + /* Print as a decimal number. */ \ + base = 10; \ + is_negative = save_errno < 0; \ + number.word = save_errno; \ + if (is_negative) \ + number.word = -number.word; \ + goto LABEL (number); \ + } \ + else \ + { \ + is_long = 0; /* This is no wide-char string. */ \ + goto LABEL (print_string); \ + } #ifdef COMPILE_WPRINTF # define process_string_arg() \ |