2011-02-11 00:48:18 +08:00
|
|
|
/* POSIX variant of strerror_r. */
|
|
|
|
#undef __STRICT_ANSI__
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
int
|
2017-12-04 11:43:30 +08:00
|
|
|
__xpg_strerror_r (int errnum,
|
2017-12-04 09:31:41 +08:00
|
|
|
char *buffer,
|
2011-02-11 00:48:18 +08:00
|
|
|
size_t n)
|
|
|
|
{
|
|
|
|
char *error;
|
2011-05-26 02:41:10 +08:00
|
|
|
int result = 0;
|
2011-02-11 00:48:18 +08:00
|
|
|
|
|
|
|
if (!n)
|
|
|
|
return ERANGE;
|
2011-05-26 02:41:10 +08:00
|
|
|
error = _strerror_r (_REENT, errnum, 1, &result);
|
2011-02-11 00:48:18 +08:00
|
|
|
if (strlen (error) >= n)
|
|
|
|
{
|
|
|
|
memcpy (buffer, error, n - 1);
|
|
|
|
buffer[n - 1] = '\0';
|
|
|
|
return ERANGE;
|
|
|
|
}
|
|
|
|
strcpy (buffer, error);
|
2011-05-26 02:41:10 +08:00
|
|
|
return (result || *error) ? result : EINVAL;
|
2011-02-11 00:48:18 +08:00
|
|
|
}
|