1
0
mirror of git://git.suckless.org/sbase synced 2024-12-21 22:50:16 +00:00

printf: allow flags for the %s format string aswell

This is useful for example to left-align strings and pad them with spaces.

printf '%-12.12s: %s\n' 'user' "$USER"
This commit is contained in:
Hiltjo Posthuma 2021-07-25 14:24:41 +02:00
parent 61be841f5c
commit 1cc5a57fd7

View File

@ -127,7 +127,11 @@ main(int argc, char *argv[])
free(rarg);
break;
case 's':
printf("%*.*s", width, precision, arg);
fmt = estrdup(flag ? "%#*.*s" : "%*.*s");
if (flag)
fmt[1] = flag;
printf(fmt, width, precision, arg);
free(fmt);
break;
case 'd': case 'i': case 'o': case 'u': case 'x': case 'X':
for (j = 0; isspace(arg[j]); j++);