summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1994-09-05 13:37:43 +0000
committerbde <bde@FreeBSD.org>1994-09-05 13:37:43 +0000
commited0e48f6c02e14af37f292052c91b653fa08fedc (patch)
tree9973d4d5b59f305697a9fb989e1f6d3ab40dfd47 /lib
parent5a325be3b5db0971698df1547c1ac0e6048d71cd (diff)
downloadFreeBSD-src-ed0e48f6c02e14af37f292052c91b653fa08fedc.zip
FreeBSD-src-ed0e48f6c02e14af37f292052c91b653fa08fedc.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/string/strerror.c14
1 files changed, 9 insertions, 5 deletions
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 <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);
}
OpenPOWER on IntegriCloud