diff options
| author | Bruce Evans <bde@FreeBSD.org> | 1994-09-05 13:37:43 +0000 | 
|---|---|---|
| committer | Bruce Evans <bde@FreeBSD.org> | 1994-09-05 13:37:43 +0000 | 
| commit | 5ec11cf0bb5c7df74b072ed321243ec613015eb5 (patch) | |
| tree | 9973d4d5b59f305697a9fb989e1f6d3ab40dfd47 /lib/libc | |
| parent | 7e80dad5c633682428312239a6a33acd0c7fa451 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/string/strerror.c | 14 | 
1 files changed, 9 insertions, 5 deletions
| diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index 53f374bdf796..5acefd95ee21 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -35,14 +35,13 @@  static char sccsid[] = "@(#)strerror.c	8.1 (Berkeley) 6/4/93";  #endif /* LIBC_SCCS and not lint */ +#include <stdio.h>  #include <string.h>  char *  strerror(num)  	int num;  { -	extern int sys_nerr; -	extern char *sys_errlist[];  #define	UPREFIX	"Unknown error: "  	static char ebuf[40] = UPREFIX;		/* 64-bit number + slop */  	register unsigned int errnum; @@ -51,17 +50,22 @@ strerror(num)  	errnum = num;				/* convert to unsigned */  	if (errnum < sys_nerr) -		return(sys_errlist[errnum]); +		return ((char *)sys_errlist[errnum]); -	/* Do this by hand, so we don't include stdio(3). */ +	/* Do this by hand, so we don't link to stdio(3). */  	t = tmp; +	if (num < 0) +		errnum = -errnum;  	do {  		*t++ = "0123456789"[errnum % 10];  	} while (errnum /= 10); +	if (num < 0) +		*t++ = '-';  	for (p = ebuf + sizeof(UPREFIX) - 1;;) {  		*p++ = *--t;  		if (t <= tmp)  			break;  	} -	return(ebuf); +	*p = '\0'; +	return (ebuf);  } | 
