git: a8ae94b9e2cb - stable/13 - libc: make strerror_rl() usable for libc

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 30 Apr 2024 00:50:20 UTC
The branch stable/13 has been updated by kib:

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

commit a8ae94b9e2cbb5ddee2ba6c4fcdda508dc295b5d
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-04-23 17:04:29 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-04-30 00:49:52 +0000

    libc: make strerror_rl() usable for libc
    
    (cherry picked from commit 92771bc00ad0f567b27876c34450bef7a0ee61d0)
---
 lib/libc/include/libc_private.h |  2 ++
 lib/libc/string/strerror.c      | 10 +++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index 593d106f3af6..34aa50d0f12d 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -453,5 +453,7 @@ struct __nl_cat_d;
 struct _xlocale;
 struct __nl_cat_d *__catopen_l(const char *name, int type,
 	    struct _xlocale *locale);
+int __strerror_rl(int errnum, char *strerrbuf, size_t buflen,
+	    struct _xlocale *locale);
 
 #endif /* _LIBC_PRIVATE_H_ */
diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c
index 673ccbf37ef7..a43b53ed59b5 100644
--- a/lib/libc/string/strerror.c
+++ b/lib/libc/string/strerror.c
@@ -78,8 +78,8 @@ errstr(int num, const char *uprefix, char *buf, size_t len)
 	strlcat(buf, t, len);
 }
 
-static int
-strerror_rl(int errnum, char *strerrbuf, size_t buflen, locale_t locale)
+int
+__strerror_rl(int errnum, char *strerrbuf, size_t buflen, locale_t locale)
 {
 	int retval = 0;
 #if defined(NLS)
@@ -120,7 +120,7 @@ strerror_rl(int errnum, char *strerrbuf, size_t buflen, locale_t locale)
 int
 strerror_r(int errnum, char *strerrbuf, size_t buflen)
 {
-	return (strerror_rl(errnum, strerrbuf, buflen, __get_locale()));
+	return (__strerror_rl(errnum, strerrbuf, buflen, __get_locale()));
 }
 
 char *
@@ -128,7 +128,7 @@ strerror_l(int num, locale_t locale)
 {
 	static _Thread_local char ebuf[NL_TEXTMAX];
 
-	if (strerror_rl(num, ebuf, sizeof(ebuf), locale) != 0)
+	if (__strerror_rl(num, ebuf, sizeof(ebuf), locale) != 0)
 		errno = EINVAL;
 	return (ebuf);
 }
@@ -138,7 +138,7 @@ strerror(int num)
 {
 	static char ebuf[NL_TEXTMAX];
 
-	if (strerror_rl(num, ebuf, sizeof(ebuf), __get_locale()) != 0)
+	if (__strerror_rl(num, ebuf, sizeof(ebuf), __get_locale()) != 0)
 		errno = EINVAL;
 	return (ebuf);
 }