The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f887667694632c829b0599b54ff86a072e93df87

commit f887667694632c829b0599b54ff86a072e93df87
Author:     Konstantin Belousov <k...@freebsd.org>
AuthorDate: 2024-04-23 17:10:30 +0000
Commit:     Konstantin Belousov <k...@freebsd.org>
CommitDate: 2024-04-23 19:43:01 +0000

    __vprintf(): switch from strerror() to strerror_rl()
    
    This eliminates the use of non-thread-safe function in printf*() family,
    and make the call locale-aware.  Also, it stops obliterating the
    strerror() static buffer, which aligns with the POSIX requirement that
    implementations must behave as if no standard-mandated functions call
    strerror().
    
    PR:     278556
    Reported by:    Jonathan Gruber <jonathan.gruber...@gmail.com>
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D44916
---
 lib/libc/stdio/vfprintf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 6c7c6982c8dc..7048315a8d78 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -312,6 +312,8 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0, 
va_list ap)
        int width;              /* width from format (%8d), or 0 */
        int prec;               /* precision from format; <0 for N/A */
        int saved_errno;
+       int error;
+       char errnomsg[NL_TEXTMAX];
        char sign;              /* sign prefix (' ', '+', '-', or \0) */
        struct grouping_state gs; /* thousands' grouping info */
 
@@ -829,7 +831,9 @@ fp_common:
                        break;
 #endif /* !NO_FLOATING_POINT */
                case 'm':
-                       cp = strerror(saved_errno);
+                       error = __strerror_rl(saved_errno, errnomsg,
+                           sizeof(errnomsg), locale);
+                       cp = error == 0 ? errnomsg : "<strerror failure>";
                        size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp);
                        sign = '\0';
                        break;

Reply via email to