summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authordzwdz2022-09-15 22:43:39 +0200
committerdzwdz2022-09-15 22:43:39 +0200
commit6c7c19e4378b9b9640dc0b250d09264f5cd99572 (patch)
treec8bd8738cc9429becc18b263d3bd21cc4f7247ff /src/shared
parent9cf3079b95ad7e995880ec5553372191c73efb0e (diff)
shared/printf: string precision
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/printf.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/shared/printf.c b/src/shared/printf.c
index 9ab4606..a9cd355 100644
--- a/src/shared/printf.c
+++ b/src/shared/printf.c
@@ -131,7 +131,11 @@ int __printf_internal(const char *fmt, va_list argp,
if (c == '.') {
c = *fmt++;
- while ('0' <= c && c <= '9') {
+ if (c == '*') {
+ // TODO handle negative precision
+ m.precision = va_arg(argp, int);
+ c = *fmt++;
+ } else while ('0' <= c && c <= '9') {
m.precision *= 10;
m.precision += c - '0';
c = *fmt++;
@@ -166,6 +170,8 @@ int __printf_internal(const char *fmt, va_list argp,
const char *s = va_arg(argp, char*);
if (s == NULL) s = "(null)";
len = strlen(s);
+ if (len > m.precision && m.precision != 0)
+ len = m.precision;
pad(&os, &m, len);
output(&os, s, len);
break;