diff options
Diffstat (limited to 'src/lib/libc/string/__strerror.c')
-rw-r--r-- | src/lib/libc/string/__strerror.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c index cd604906db..9c023f8a53 100644 --- a/src/lib/libc/string/__strerror.c +++ b/src/lib/libc/string/__strerror.c | |||
@@ -32,8 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 35 | static char *rcsid = "$OpenBSD: __strerror.c,v 1.6 1996/09/25 08:17:30 deraadt Exp $"; |
36 | static char *rcsid = "$Id: __strerror.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
38 | 37 | ||
39 | #ifdef NLS | 38 | #ifdef NLS |
@@ -46,9 +45,26 @@ static char *rcsid = "$Id: __strerror.c,v 1.1.1.1 1995/10/18 08:42:20 deraadt Ex | |||
46 | #define sys_errlist _sys_errlist | 45 | #define sys_errlist _sys_errlist |
47 | #define sys_nerr _sys_nerr | 46 | #define sys_nerr _sys_nerr |
48 | 47 | ||
48 | #include <errno.h> | ||
49 | #include <limits.h> | ||
49 | #include <stdio.h> | 50 | #include <stdio.h> |
50 | #include <string.h> | 51 | #include <string.h> |
51 | 52 | ||
53 | static char *itoa(num) | ||
54 | int num; | ||
55 | { | ||
56 | static char buffer[11]; | ||
57 | char *p; | ||
58 | |||
59 | p = buffer + 4; | ||
60 | while (num >= 10) { | ||
61 | *--p = (num % 10) + '0'; | ||
62 | num /= 10; | ||
63 | } | ||
64 | *p = (num % 10) + '0'; | ||
65 | return p; | ||
66 | } | ||
67 | |||
52 | /* | 68 | /* |
53 | * Since perror() is not allowed to change the contents of strerror()'s | 69 | * Since perror() is not allowed to change the contents of strerror()'s |
54 | * static buffer, both functions supply their own buffers to the | 70 | * static buffer, both functions supply their own buffers to the |
@@ -60,28 +76,31 @@ __strerror(num, buf) | |||
60 | int num; | 76 | int num; |
61 | char *buf; | 77 | char *buf; |
62 | { | 78 | { |
63 | #define UPREFIX "Unknown error: %u" | 79 | #define UPREFIX "Unknown error: " |
64 | register unsigned int errnum; | 80 | register unsigned int errnum; |
65 | 81 | ||
66 | #ifdef NLS | 82 | #ifdef NLS |
67 | nl_catd catd ; | 83 | nl_catd catd; |
68 | catd = catopen("libc", 0); | 84 | catd = catopen("libc", 0); |
69 | #endif | 85 | #endif |
70 | 86 | ||
71 | errnum = num; /* convert to unsigned */ | 87 | errnum = num; /* convert to unsigned */ |
72 | if (errnum < sys_nerr) { | 88 | if (errnum < sys_nerr) { |
73 | #ifdef NLS | 89 | #ifdef NLS |
74 | strcpy(buf, catgets(catd, 1, errnum, | 90 | strncpy(buf, catgets(catd, 1, errnum, |
75 | (char *)sys_errlist[errnum])); | 91 | (char *)sys_errlist[errnum]), NL_TEXTMAX-1); |
92 | buf[NL_TEXTMAX - 1] = '\0'; | ||
76 | #else | 93 | #else |
77 | return(sys_errlist[errnum]); | 94 | return(sys_errlist[errnum]); |
78 | #endif | 95 | #endif |
79 | } else { | 96 | } else { |
80 | #ifdef NLS | 97 | #ifdef NLS |
81 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); | 98 | strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1); |
99 | buf[NL_TEXTMAX - 1] = '\0'; | ||
82 | #else | 100 | #else |
83 | sprintf(buf, UPREFIX, errnum); | 101 | strcpy(buf, UPREFIX); |
84 | #endif | 102 | #endif |
103 | strncat(buf, itoa(errnum), NL_TEXTMAX-strlen(buf)-1); | ||
85 | } | 104 | } |
86 | 105 | ||
87 | #ifdef NLS | 106 | #ifdef NLS |