From 4805b60ccfeee32a4ac3547e680c917f9e5c1d39 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 25 May 2011 18:41:10 +0000 Subject: strerror: allow user hook to comply with POSIX rules * libc/string/strerror.c (strerror): Split body into... (_strerror_r): ...new reentrant function. * libc/string/u_strerr.c (_user_strerror): Update signature. * libc/include/stdio.h (_strerror_r): New prototype. * libc/posix/collate.c (__collate_err): Adjust callers. * libc/stdio/perror.c (_perror_r): Likewise. * libc/string/strerror_r.c (strerror_r): Likewise. * libc/string/xpg_strerror_r.c (__xpg_strerror_r): Likewise. --- newlib/libc/string/strerror_r.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'newlib/libc/string/strerror_r.c') diff --git a/newlib/libc/string/strerror_r.c b/newlib/libc/string/strerror_r.c index c2057b7f0..d26a412a5 100644 --- a/newlib/libc/string/strerror_r.c +++ b/newlib/libc/string/strerror_r.c @@ -43,7 +43,9 @@ PORTABILITY <> with a <[char *]> result is a GNU extension. <> with an <[int]> result is required by POSIX 2001. This function is compliant only if <<_user_strerror>> is not provided, -or if it is thread-safe and does not modify <>. +or if it is thread-safe and uses separate storage according to whether +the second argument of that function is non-zero. For more details +on <<_user_strerror>>, see the <> documentation. POSIX states that the contents of <[buf]> are unspecified on error, although this implementation guarantees a NUL-terminated string for @@ -55,7 +57,7 @@ provides only an empty string (unless you provide <<_user_strerror>>). POSIX also recommends that unknown <[errnum]> fail with EINVAL even when providing such a message, however it is not a requirement and this implementation will return success if <<_user_strerror>> provided -a non-empty alternate string. +a non-empty alternate string without assigning into its third argument. <> requires no supporting OS subroutines. @@ -75,7 +77,7 @@ _DEFUN (strerror_r, (errnum, buffer, n), char *buffer _AND size_t n) { - char *error = strerror (errnum); + char *error = _strerror_r (_REENT, errnum, 1, NULL); if (strlen (error) >= n) return error; -- cgit v1.2.3