sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 1cc5a57fd7f0c72d9e4c383cfb5c7decf39fa346
parent 61be841f5cc4019890c769cec33744616614ea10
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 25 Jul 2021 14:24:41 +0200

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"

Diffstat:
Mprintf.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/printf.c b/printf.c @@ -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++);