Home | History | Annotate | Download | only in lib
      1 /*
      2  * strerror.c
      3  */
      4 
      5 #include <string.h>
      6 
      7 char *strerror(int errnum)
      8 {
      9 	static char message[32] = "error ";	/* enough for error 2^63-1 */
     10 	char numbuf[32];
     11 	char *p;
     12 	unsigned int e = (unsigned int)errnum;
     13 
     14 	extern const int sys_nerr;
     15 	extern const char *const sys_errlist[];
     16 
     17 	if (e < (unsigned int)sys_nerr && sys_errlist[e])
     18 		return (char *)sys_errlist[e];
     19 
     20 	p = numbuf + sizeof numbuf;
     21 	*--p = '\0';
     22 
     23 	do {
     24 		*--p = (e % 10) + '0';
     25 		e /= 10;
     26 	} while (e);
     27 
     28 	memcpy(message + 6, p, (numbuf + sizeof numbuf) - p);
     29 
     30 	return message;
     31 }
     32