summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Bernardy <jeanphilippe.bernardy@gmail.com>2005-01-23 23:08:07 +0000
committerJean-Philippe Bernardy <jeanphilippe.bernardy@gmail.com>2005-01-23 23:08:07 +0000
commitfc0372b209d21cb6317078f63774aa4bef6dff29 (patch)
treec63574bd1073fcd16e003ed0d014e5a272f859bf
parent2e41950fcf98b4f5eee95e2e5e72681557eca585 (diff)
downloadrockbox-fc0372b209d21cb6317078f63774aa4bef6dff29.tar.gz
rockbox-fc0372b209d21cb6317078f63774aa4bef6dff29.tar.bz2
rockbox-fc0372b209d21cb6317078f63774aa4bef6dff29.zip
Support for %l* plus __attribute__ printf support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5641 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/sprintf.c38
-rw-r--r--firmware/include/sprintf.h13
2 files changed, 48 insertions, 3 deletions
diff --git a/firmware/common/sprintf.c b/firmware/common/sprintf.c
index 6542c9d993..a92681e736 100644
--- a/firmware/common/sprintf.c
+++ b/firmware/common/sprintf.c
@@ -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;
diff --git a/firmware/include/sprintf.h b/firmware/include/sprintf.h
index 61a5f5139f..d68647ee72 100644
--- a/firmware/include/sprintf.h
+++ b/firmware/include/sprintf.h
@@ -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__ */