From 7c10a76dec8afaf548bf14453ebd689e3457518e Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 10 Feb 2011 16:48:18 +0000 Subject: strerror_r: provide POSIX implementation * libc/include/string.h (strerror_r): Update declaration. * libc/string/strerror.c (strerror): Update documentation. * libc/string/strerror_r.c (strerror_r): Always return NUL-terminated string; don't overwrite too-short buf. * libc/string/xpg_strerror_r.c (__xpg_strerror_r): Implement POSIX variant. * libc/string/Makefile.am (GENERAL_SOURCES): Build new file. * libc/string/Makefile.in: Regenerate. --- newlib/libc/string/strerror.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'newlib/libc/string/strerror.c') diff --git a/newlib/libc/string/strerror.c b/newlib/libc/string/strerror.c index 043763141..61e40ab7a 100644 --- a/newlib/libc/string/strerror.c +++ b/newlib/libc/string/strerror.c @@ -301,6 +301,17 @@ declares that subsequent calls to <> may overwrite the result string; therefore portable code cannot depend on the reentrancy of this subroutine. +Although this implementation of <> guarantees a non-null +result with a NUL-terminator, some implementations return <> +on failure. Although POSIX allows <> to set <> +to EINVAL on failure, this implementation does not do so (unless +you provide <<_user_strerror>>). + +POSIX recommends that unknown <[errnum]> result in a message +including that value, however it is not a requirement and this +implementation does not provide that information (unless you +provide <<_user_strerror>>). + This implementation of <> provides for user-defined extensibility. <> defines <[__ELASTERROR]>, which can be used as a base for user-defined error values. If the user supplies a @@ -313,6 +324,9 @@ character pointer. If <[errnum]> is unknown to <<_user_strerror>>, <<_user_strerror>> returns <[NULL]>. The default <<_user_strerror>> returns <[NULL]> for all input values. +Note that <<_user_sterror>> must be thread-safe and not alter <> +if <> is to comply with POSIX. + <> requires no supporting OS subroutines. QUICKREF -- cgit v1.2.3