1 /* Copyright (c) 2011 Eric Blake <eblake@redhat.com> */ 2 /* POSIX variant of strerror_r. */ 3 #undef __STRICT_ANSI__ 4 #include <errno.h> 5 #include <string.h> 6 7 int __xpg_strerror_r(int errnum,char * buffer,size_t n)8__xpg_strerror_r (int errnum, 9 char *buffer, 10 size_t n) 11 { 12 char *error; 13 int result = 0; 14 15 if (!n) 16 return ERANGE; 17 error = _strerror_r (errnum, 1, &result); 18 if (strlen (error) >= n) 19 { 20 memcpy (buffer, error, n - 1); 21 buffer[n - 1] = '\0'; 22 return ERANGE; 23 } 24 strcpy (buffer, error); 25 return (result || *error) ? result : EINVAL; 26 } 27