aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/string/strerror_r.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-05-25 18:41:10 +0000
committerEric Blake <eblake@redhat.com>2011-05-25 18:41:10 +0000
commit4805b60ccfeee32a4ac3547e680c917f9e5c1d39 (patch)
tree7035ae20768510551b6abb65549b1e51acd18e09 /newlib/libc/string/strerror_r.c
parent6215837523703c2c0b58200341ae3861d8b7a28d (diff)
downloadnewlib-4805b60ccfeee32a4ac3547e680c917f9e5c1d39.zip
newlib-4805b60ccfeee32a4ac3547e680c917f9e5c1d39.tar.gz
newlib-4805b60ccfeee32a4ac3547e680c917f9e5c1d39.tar.bz2
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.
Diffstat (limited to 'newlib/libc/string/strerror_r.c')
-rw-r--r--newlib/libc/string/strerror_r.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/newlib/libc/string/strerror_r.c b/newlib/libc/string/strerror_r.c
index c2057b7..d26a412 100644
--- a/newlib/libc/string/strerror_r.c
+++ b/newlib/libc/string/strerror_r.c
@@ -43,7 +43,9 @@ PORTABILITY
<<strerror_r>> with a <[char *]> result is a GNU extension.
<<strerror_r>> 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 <<errno>>.
+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 <<strerror>> 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.
<<strerror_r>> 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;