1
0
Fork 0
forked from len0rd/rockbox

Support for %l* plus __attribute__ printf support

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5641 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jean-Philippe Bernardy 2005-01-23 23:08:07 +00:00
parent 2e41950fcf
commit fc0372b209
2 changed files with 48 additions and 3 deletions

View file

@ -43,7 +43,9 @@ static int format(
char *str;
char tmpbuf[12], pad;
int ch, width, val, sign;
long lval;
unsigned int uval;
unsigned long ulval;
bool ok = true;
tmpbuf[sizeof tmpbuf - 1] = '\0';
@ -99,7 +101,41 @@ static int format(
}
while (uval);
break;
case 'l':
ch = *fmt++;
switch(ch) {
case 'x':
case 'X':
ulval = va_arg (ap, long);
do
{
*--str = hexdigit[ulval & 0xf];
ulval >>= 4;
}
while (ulval);
break;
case 'd':
lval = sign = va_arg (ap, long);
if (lval < 0)
lval = -lval;
do
{
*--str = (lval % 10) + '0';
lval /= 10;
}
while (lval > 0);
if (sign < 0)
*--str = '-';
break;
default:
*--str = 'l';
*--str = ch;
}
break;
default:
*--str = ch;
break;

View file

@ -23,8 +23,17 @@
#include <stddef.h>
#include <stdarg.h>
int snprintf (char *buf, size_t size, const char *fmt, ...);
#ifdef __GNUC__
#define ATTRIBUTE_PRINTF(fmt, arg1) __attribute__ ( ( format( printf, fmt, arg1 ) ) )
#else
#define ATTRIBUTE_PRINTF(fmt, arg1)
#endif
int snprintf (char *buf, size_t size, const char *fmt, ...)
ATTRIBUTE_PRINTF(3, 4);
int vsnprintf (char *buf, int size, const char *fmt, va_list ap);
int fprintf (int fd, const char *fmt, ...);
int fprintf (int fd, const char *fmt, ...)
ATTRIBUTE_PRINTF(2, 3);
#endif /* __SPRINTF_H__ */