diff options
author | Barry Wardell <rockbox@barrywardell.net> | 2007-03-19 10:57:23 +0000 |
---|---|---|
committer | Barry Wardell <rockbox@barrywardell.net> | 2007-03-19 10:57:23 +0000 |
commit | 58038d86f19174258f22ace959cc35438d3e6616 (patch) | |
tree | 0a7d85bb89212cdcbd7a0d332dd1f00fb37dca9c | |
parent | 15638dec2e65ca4f02772379930ace0b4fe53520 (diff) | |
download | rockbox-58038d86f19174258f22ace959cc35438d3e6616.tar.gz rockbox-58038d86f19174258f22ace959cc35438d3e6616.zip |
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
-rw-r--r-- | firmware/common/sprintf.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/firmware/common/sprintf.c b/firmware/common/sprintf.c index 79db758a4b..bbd4db5bb4 100644 --- a/firmware/common/sprintf.c +++ b/firmware/common/sprintf.c | |||
@@ -42,7 +42,7 @@ static int format( | |||
42 | { | 42 | { |
43 | char *str; | 43 | char *str; |
44 | char tmpbuf[12], pad; | 44 | char tmpbuf[12], pad; |
45 | int ch, width, val, sign; | 45 | int ch, width, val, sign, precision; |
46 | long lval, lsign; | 46 | long lval, lsign; |
47 | unsigned int uval; | 47 | unsigned int uval; |
48 | unsigned long ulval; | 48 | unsigned long ulval; |
@@ -65,6 +65,17 @@ static int format( | |||
65 | width = 10*width + ch - '0'; | 65 | width = 10*width + ch - '0'; |
66 | ch = *fmt++; | 66 | ch = *fmt++; |
67 | } | 67 | } |
68 | |||
69 | precision = 0; | ||
70 | if(ch == '.') | ||
71 | { | ||
72 | ch = *fmt++; | ||
73 | while (ch >= '0' && ch <= '9') | ||
74 | { | ||
75 | precision = 10*precision + ch - '0'; | ||
76 | ch = *fmt++; | ||
77 | } | ||
78 | } | ||
68 | 79 | ||
69 | str = tmpbuf + sizeof tmpbuf - 1; | 80 | str = tmpbuf + sizeof tmpbuf - 1; |
70 | switch (ch) | 81 | switch (ch) |
@@ -75,6 +86,8 @@ static int format( | |||
75 | 86 | ||
76 | case 's': | 87 | case 's': |
77 | str = va_arg (ap, char*); | 88 | str = va_arg (ap, char*); |
89 | if(precision > 0) | ||
90 | str[precision] = '\0'; | ||
78 | break; | 91 | break; |
79 | 92 | ||
80 | case 'd': | 93 | case 'd': |