summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/__strerror.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/__strerror.c')
-rw-r--r--src/lib/libc/string/__strerror.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/lib/libc/string/__strerror.c b/src/lib/libc/string/__strerror.c
index cd604906db..ae19ab3365 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";*/ 35static char *rcsid = "$OpenBSD: __strerror.c,v 1.8 2001/12/08 20:37:32 deraadt Exp $";
36static 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,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 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
53static char *
54itoa(num)
55 int num;
56{
57 static char buffer[11];
58 char *p;
59
60 p = buffer + 4;
61 while (num >= 10) {
62 *--p = (num % 10) + '0';
63 num /= 10;
64 }
65 *p = (num % 10) + '0';
66 return p;
67}
68
52/* 69/*
53 * Since perror() is not allowed to change the contents of strerror()'s 70 * Since perror() is not allowed to change the contents of strerror()'s
54 * static buffer, both functions supply their own buffers to the 71 * static buffer, both functions supply their own buffers to the
@@ -60,32 +77,37 @@ __strerror(num, buf)
60 int num; 77 int num;
61 char *buf; 78 char *buf;
62{ 79{
63#define UPREFIX "Unknown error: %u" 80#define UPREFIX "Unknown error: "
64 register unsigned int errnum; 81 register unsigned int errnum;
65
66#ifdef NLS 82#ifdef NLS
67 nl_catd catd ; 83 int save_errno;
84 nl_catd catd;
85
68 catd = catopen("libc", 0); 86 catd = catopen("libc", 0);
69#endif 87#endif
70 88
71 errnum = num; /* convert to unsigned */ 89 errnum = num; /* convert to unsigned */
72 if (errnum < sys_nerr) { 90 if (errnum < sys_nerr) {
73#ifdef NLS 91#ifdef NLS
74 strcpy(buf, catgets(catd, 1, errnum, 92 strlcpy(buf, catgets(catd, 1, errnum,
75 (char *)sys_errlist[errnum])); 93 (char *)sys_errlist[errnum]), NL_TEXTMAX);
76#else 94#else
77 return(sys_errlist[errnum]); 95 return(sys_errlist[errnum]);
78#endif 96#endif
79 } else { 97 } else {
80#ifdef NLS 98#ifdef NLS
81 sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); 99 strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX);
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);
104 errno = EINVAL;
85 } 105 }
86 106
87#ifdef NLS 107#ifdef NLS
108 save_errno = errno;
88 catclose(catd); 109 catclose(catd);
110 errno = save_errno;
89#endif 111#endif
90 112
91 return buf; 113 return buf;