diff options
Diffstat (limited to 'src/lib/libc/string/__strerror.c')
-rw-r--r-- | src/lib/libc/string/__strerror.c | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c index cd604906db..15436eaab2 100644 --- a/src/lib/libc/string/__strerror.c +++ b/src/lib/libc/string/__strerror.c | |||
@@ -10,11 +10,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 13 | * 3. Neither the name of the University nor the names of its contributors |
14 | * must display the following acknowledgement: | ||
15 | * This product includes software developed by the University of | ||
16 | * California, Berkeley and its contributors. | ||
17 | * 4. Neither the name of the University nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | 14 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 15 | * without specific prior written permission. |
20 | * | 16 | * |
@@ -32,8 +28,7 @@ | |||
32 | */ | 28 | */ |
33 | 29 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ | 31 | static char *rcsid = "$OpenBSD: __strerror.c,v 1.10 2003/06/02 20:18:38 millert 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
38 | 33 | ||
39 | #ifdef NLS | 34 | #ifdef NLS |
@@ -46,9 +41,27 @@ 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 | 41 | #define sys_errlist _sys_errlist |
47 | #define sys_nerr _sys_nerr | 42 | #define sys_nerr _sys_nerr |
48 | 43 | ||
44 | #include <errno.h> | ||
45 | #include <limits.h> | ||
49 | #include <stdio.h> | 46 | #include <stdio.h> |
50 | #include <string.h> | 47 | #include <string.h> |
51 | 48 | ||
49 | static char * | ||
50 | itoa(num) | ||
51 | int num; | ||
52 | { | ||
53 | static char buffer[11]; | ||
54 | char *p; | ||
55 | |||
56 | p = buffer + 4; | ||
57 | while (num >= 10) { | ||
58 | *--p = (num % 10) + '0'; | ||
59 | num /= 10; | ||
60 | } | ||
61 | *p = (num % 10) + '0'; | ||
62 | return p; | ||
63 | } | ||
64 | |||
52 | /* | 65 | /* |
53 | * Since perror() is not allowed to change the contents of strerror()'s | 66 | * Since perror() is not allowed to change the contents of strerror()'s |
54 | * static buffer, both functions supply their own buffers to the | 67 | * static buffer, both functions supply their own buffers to the |
@@ -60,32 +73,37 @@ __strerror(num, buf) | |||
60 | int num; | 73 | int num; |
61 | char *buf; | 74 | char *buf; |
62 | { | 75 | { |
63 | #define UPREFIX "Unknown error: %u" | 76 | #define UPREFIX "Unknown error: " |
64 | register unsigned int errnum; | 77 | register unsigned int errnum; |
65 | |||
66 | #ifdef NLS | 78 | #ifdef NLS |
67 | nl_catd catd ; | 79 | int save_errno; |
80 | nl_catd catd; | ||
81 | |||
68 | catd = catopen("libc", 0); | 82 | catd = catopen("libc", 0); |
69 | #endif | 83 | #endif |
70 | 84 | ||
71 | errnum = num; /* convert to unsigned */ | 85 | errnum = num; /* convert to unsigned */ |
72 | if (errnum < sys_nerr) { | 86 | if (errnum < sys_nerr) { |
73 | #ifdef NLS | 87 | #ifdef NLS |
74 | strcpy(buf, catgets(catd, 1, errnum, | 88 | strlcpy(buf, catgets(catd, 1, errnum, |
75 | (char *)sys_errlist[errnum])); | 89 | (char *)sys_errlist[errnum]), NL_TEXTMAX); |
76 | #else | 90 | #else |
77 | return(sys_errlist[errnum]); | 91 | return(sys_errlist[errnum]); |
78 | #endif | 92 | #endif |
79 | } else { | 93 | } else { |
80 | #ifdef NLS | 94 | #ifdef NLS |
81 | sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); | 95 | strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); |
82 | #else | 96 | #else |
83 | sprintf(buf, UPREFIX, errnum); | 97 | strlcpy(buf, UPREFIX, NL_TEXTMAX); |
84 | #endif | 98 | #endif |
99 | strlcat(buf, itoa(errnum), NL_TEXTMAX); | ||
100 | errno = EINVAL; | ||
85 | } | 101 | } |
86 | 102 | ||
87 | #ifdef NLS | 103 | #ifdef NLS |
104 | save_errno = errno; | ||
88 | catclose(catd); | 105 | catclose(catd); |
106 | errno = save_errno; | ||
89 | #endif | 107 | #endif |
90 | 108 | ||
91 | return buf; | 109 | return buf; |