diff options
author | 2004-05-01 10:52:59 +0000 | |
---|---|---|
committer | 2004-05-01 10:52:59 +0000 | |
commit | 3e28ea61bc15e48cc168953c665c7cd9639b02c3 (patch) | |
tree | bcc28a52a4c56784304a77917184235c759ed144 /lib/libc | |
parent | priv revoking; tested by millert (diff) | |
download | wireguard-openbsd-3e28ea61bc15e48cc168953c665c7cd9639b02c3.tar.xz wireguard-openbsd-3e28ea61bc15e48cc168953c665c7cd9639b02c3.zip |
let __strerror fill precisely the part of the buffer it can.
okay millert@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/string/__strerror.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/lib/libc/string/__strerror.c b/lib/libc/string/__strerror.c index ccb430247e1..87b47b68e40 100644 --- a/lib/libc/string/__strerror.c +++ b/lib/libc/string/__strerror.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: __strerror.c,v 1.11 2004/04/30 17:13:02 espie Exp $"; +static char *rcsid = "$OpenBSD: __strerror.c,v 1.12 2004/05/01 10:52:59 espie Exp $"; #endif /* LIBC_SCCS and not lint */ #ifdef NLS @@ -59,11 +59,10 @@ __digits10(unsigned int num) return i; } -static char * -__itoa(int num, char *buffer, size_t maxlen) +void +__itoa(int num, char *buffer, size_t start, size_t end) { - char *p; - size_t len; + size_t pos; unsigned int a; int neg; @@ -76,22 +75,25 @@ __itoa(int num, char *buffer, size_t maxlen) neg = 0; } - len = __digits10(a); + pos = start + __digits10(a); if (neg) - len++; + pos++; - if (len >= maxlen) - return NULL; - - buffer[len--] = '\0'; + if (pos < end) + buffer[pos] = '\0'; + else + buffer[end-1] = '\0'; + pos--; do { - buffer[len--] = (a % 10) + '0'; + + if (pos < end) + buffer[pos] = (a % 10) + '0'; + pos--; a /= 10; } while (a != 0); if (neg) - *buffer = '-'; - - return buffer; + if (pos < end) + buffer[pos] = '-'; } /* @@ -125,8 +127,7 @@ __strerror(int num, char *buf) #else len = strlcpy(buf, UPREFIX, NL_TEXTMAX); #endif - if (len < NL_TEXTMAX) - __itoa(num, buf + len, NL_TEXTMAX - len); + __itoa(num, buf, len, NL_TEXTMAX); errno = EINVAL; } |