summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libc/string/strerror_r.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/lib/libc/string/strerror_r.c b/src/lib/libc/string/strerror_r.c
index c0ca434cbd..28bfd00a47 100644
--- a/src/lib/libc/string/strerror_r.c
+++ b/src/lib/libc/string/strerror_r.c
@@ -1,8 +1,8 @@
1/* $OpenBSD: strerror_r.c,v 1.3 2005/04/20 23:38:15 beck Exp $ */ 1/* $OpenBSD: strerror_r.c,v 1.4 2005/05/08 06:25:44 otto Exp $ */
2/* Public Domain <marc@snafu.org> */ 2/* Public Domain <marc@snafu.org> */
3 3
4#if defined(LIBC_SCCS) && !defined(lint) 4#if defined(LIBC_SCCS) && !defined(lint)
5static char *rcsid = "$OpenBSD: strerror_r.c,v 1.3 2005/04/20 23:38:15 beck Exp $"; 5static char *rcsid = "$OpenBSD: strerror_r.c,v 1.4 2005/05/08 06:25:44 otto Exp $";
6#endif /* LIBC_SCCS and not lint */ 6#endif /* LIBC_SCCS and not lint */
7 7
8#ifdef NLS 8#ifdef NLS
@@ -32,7 +32,7 @@ __digits10(unsigned int num)
32 return i; 32 return i;
33} 33}
34 34
35static void 35static int
36__itoa(int num, char *buffer, size_t start, size_t end) 36__itoa(int num, char *buffer, size_t start, size_t end)
37{ 37{
38 size_t pos; 38 size_t pos;
@@ -54,21 +54,17 @@ __itoa(int num, char *buffer, size_t start, size_t end)
54 54
55 if (pos < end) 55 if (pos < end)
56 buffer[pos] = '\0'; 56 buffer[pos] = '\0';
57 else { 57 else
58 if (end) 58 return ERANGE;
59 buffer[--end] = '\0'; /* XXX */
60 }
61 pos--; 59 pos--;
62 do { 60 do {
63 61 buffer[pos] = (a % 10) + '0';
64 if (pos < end)
65 buffer[pos] = (a % 10) + '0';
66 pos--; 62 pos--;
67 a /= 10; 63 a /= 10;
68 } while (a != 0); 64 } while (a != 0);
69 if (neg) 65 if (neg)
70 if (pos < end) 66 buffer[pos] = '-';
71 buffer[pos] = '-'; 67 return 0;
72} 68}
73 69
74 70
@@ -110,8 +106,9 @@ strerror_r(int errnum, char *strerrbuf, size_t buflen)
110 if (len >= buflen) 106 if (len >= buflen)
111 ret_errno = ERANGE; 107 ret_errno = ERANGE;
112 else { 108 else {
113 __itoa(errnum, strerrbuf, len, buflen); 109 ret_errno = __itoa(errnum, strerrbuf, len, buflen);
114 ret_errno = EINVAL; 110 if (ret_errno == 0)
111 ret_errno = EINVAL;
115 } 112 }
116 } 113 }
117 114