mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-16 11:31:00 +08:00
7c10a76dec
* 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.
26 lines
455 B
C
26 lines
455 B
C
/* POSIX variant of strerror_r. */
|
|
#undef __STRICT_ANSI__
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
|
|
int
|
|
_DEFUN (__xpg_strerror_r, (errnum, buffer, n),
|
|
int errnum _AND
|
|
char *buffer _AND
|
|
size_t n)
|
|
{
|
|
char *error;
|
|
|
|
if (!n)
|
|
return ERANGE;
|
|
error = strerror (errnum);
|
|
if (strlen (error) >= n)
|
|
{
|
|
memcpy (buffer, error, n - 1);
|
|
buffer[n - 1] = '\0';
|
|
return ERANGE;
|
|
}
|
|
strcpy (buffer, error);
|
|
return *error ? 0 : EINVAL;
|
|
}
|