Add support for the .precision format in the sprintf()-like functions to allow limiting the maximum length of a string.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12838 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Barry Wardell 2007-03-19 10:57:23 +00:00
parent 15638dec2e
commit 58038d86f1

View file

@ -42,7 +42,7 @@ static int format(
{
char *str;
char tmpbuf[12], pad;
int ch, width, val, sign;
int ch, width, val, sign, precision;
long lval, lsign;
unsigned int uval;
unsigned long ulval;
@ -65,6 +65,17 @@ static int format(
width = 10*width + ch - '0';
ch = *fmt++;
}
precision = 0;
if(ch == '.')
{
ch = *fmt++;
while (ch >= '0' && ch <= '9')
{
precision = 10*precision + ch - '0';
ch = *fmt++;
}
}
str = tmpbuf + sizeof tmpbuf - 1;
switch (ch)
@ -75,6 +86,8 @@ static int format(
case 's':
str = va_arg (ap, char*);
if(precision > 0)
str[precision] = '\0';
break;
case 'd':