printk: Add padding support to string format specifiers

The numeric format specifiers already have this support, but strings
didn't. This makes it possible to add padding after strings, using
format specifiers such as %-10s.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-14 14:11:42 +02:00 committed by Johan Hedberg
parent 75250f4747
commit 7d71c0656f

View file

@ -190,9 +190,17 @@ void _vprintk(out_func_t out, void *ctx, const char *fmt, va_list ap)
} }
case 's': { case 's': {
char *s = va_arg(ap, char *); char *s = va_arg(ap, char *);
char *start = s;
while (*s) while (*s)
out((int)(*s++), ctx); out((int)(*s++), ctx);
if (padding == PAD_SPACE_AFTER) {
int remaining = min_width - (s - start);
while (remaining-- > 0) {
out(' ', ctx);
}
}
break; break;
} }
case 'c': { case 'c': {