Browse Source

let __strerror fill precisely the part of the buffer it can.

okay millert@
OPENBSD_3_6
espie 20 years ago
parent
commit
5d22c77bac
1 changed files with 18 additions and 17 deletions
  1. +18
    -17
      src/lib/libc/string/__strerror.c

+ 18
- 17
src/lib/libc/string/__strerror.c View File

@ -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;
}


Loading…
Cancel
Save