From ed0e48f6c02e14af37f292052c91b653fa08fedc Mon Sep 17 00:00:00 2001 From: bde Date: Mon, 5 Sep 1994 13:37:43 +0000 Subject: Fix printing of weird errno's: negative values were printed as large unsigned's; null termination was only guaranteed for the first call. Fix lint: don't declare externs internally; they were both out of date. --- lib/libc/string/strerror.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/libc/string/strerror.c') diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index 53f374b..5acefd9 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 #include 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); } -- cgit v1.1