Fixed number()/snprintf(): the buffer length was completely ignored when

printing numbers.
Removed unused code.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7887 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-06-10 05:27:48 +00:00
parent fab1cad1b8
commit 9b1718cc6c
@@ -13,41 +13,6 @@
#include <stdio.h> #include <stdio.h>
#if 0
static unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
{
unsigned long result = 0,value;
if (!base) {
base = 10;
if (*cp == '0') {
base = 8;
cp++;
if ((*cp == 'x') && isxdigit(cp[1])) {
cp++;
base = 16;
}
}
}
while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
? toupper(*cp) : *cp)-'A'+10) < base) {
result = result*base + value;
cp++;
}
if (endp)
*endp = (char *)cp;
return result;
}
static long simple_strtol(const char *cp,char **endp,unsigned int base)
{
if(*cp=='-')
return -simple_strtoul(cp+1,endp,base);
return simple_strtoul(cp,endp,base);
}
#endif
static int static int
skip_atoi(const char **s) skip_atoi(const char **s)
{ {
@@ -161,8 +126,9 @@ put_character(char **_buffer, int32 *_bytesLeft, char c)
} }
static char * static void
number(char *str, long long num, unsigned base, int size, int precision, int type) number(char **_string, int32 *_bytesLeft, int64 num, uint32 base, int size,
int precision, int type)
{ {
const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
char c, sign, tmp[66]; char c, sign, tmp[66];
@@ -173,7 +139,7 @@ number(char *str, long long num, unsigned base, int size, int precision, int typ
if (type & LEFT) if (type & LEFT)
type &= ~ZEROPAD; type &= ~ZEROPAD;
if (base < 2 || base > 36) if (base < 2 || base > 36)
return 0; return;
c = (type & ZEROPAD) ? '0' : ' '; c = (type & ZEROPAD) ? '0' : ' ';
sign = 0; sign = 0;
@@ -207,32 +173,31 @@ number(char *str, long long num, unsigned base, int size, int precision, int typ
size -= precision; size -= precision;
if (!(type & (ZEROPAD + LEFT))) { if (!(type & (ZEROPAD + LEFT))) {
while (size-- > 0) put_padding(_string, _bytesLeft, size);
*str++ = ' '; size = 0;
} }
if (sign) if (sign)
*str++ = sign; put_character(_string, _bytesLeft, sign);
if (type & SPECIAL) { if (type & SPECIAL) {
if (base == 8) if (base == 8)
*str++ = '0'; put_character(_string, _bytesLeft, '0');
else if (base == 16) { else if (base == 16) {
*str++ = '0'; put_character(_string, _bytesLeft, '0');
*str++ = digits[33]; put_character(_string, _bytesLeft, digits[33]);
} }
} }
if (!(type & LEFT)) if (!(type & LEFT)) {
while (size-- > 0) while (size-- > 0)
*str++ = c; put_character(_string, _bytesLeft, c);
}
while (i < precision--) while (i < precision--)
*str++ = '0'; put_character(_string, _bytesLeft, '0');
while (i-- > 0) while (i-- > 0)
*str++ = tmp[i]; put_character(_string, _bytesLeft, tmp[i]);
while (size-- > 0)
*str++ = ' ';
return str; put_padding(_string, _bytesLeft, size);
} }
@@ -356,10 +321,9 @@ vsnprintf(char *buffer, size_t bufferSize, const char *format, va_list args)
flags |= ZEROPAD; flags |= ZEROPAD;
} }
// ToDo: fix me! if (!put_string(&string, &bytesLeft, "0x", 2))
string[0] = '0'; goto out;
string[1] = 'x'; number(&string, &bytesLeft, (uint32)va_arg(args, void *), 16,
string = number(string + 2, (uint32)va_arg(args, void *), 16,
fieldWidth, precision, flags); fieldWidth, precision, flags);
continue; continue;
@@ -416,8 +380,7 @@ vsnprintf(char *buffer, size_t bufferSize, const char *format, va_list args)
else else
num = va_arg(args, unsigned int); num = va_arg(args, unsigned int);
// ToDo: fix me! number(&string, &bytesLeft, num, base, fieldWidth, precision, flags);
string = number(string, num, base, fieldWidth, precision, flags);
} }
out: out: