xref: /original-bsd/lib/libc/string/strerror.c (revision a1c2194a)
1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)strerror.c	5.6 (Berkeley) 05/04/91";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <string.h>
13 
14 char *
15 strerror(num)
16 	int num;
17 {
18 	extern int sys_nerr;
19 	extern char *sys_errlist[];
20 #define	UPREFIX	"Unknown error: "
21 	static char ebuf[40] = UPREFIX;		/* 64-bit number + slop */
22 	register unsigned int errnum;
23 	register char *p, *t;
24 	char tmp[40];
25 
26 	errnum = num;				/* convert to unsigned */
27 	if (errnum < sys_nerr)
28 		return(sys_errlist[errnum]);
29 
30 	/* Do this by hand, so we don't include stdio(3). */
31 	t = tmp;
32 	do {
33 		*t++ = "0123456789"[errnum % 10];
34 	} while (errnum /= 10);
35 	for (p = ebuf + sizeof(UPREFIX) - 1;;) {
36 		*p++ = *--t;
37 		if (t <= tmp)
38 			break;
39 	}
40 	return(ebuf);
41 }
42