From d72f654c65891ad9a91e012d15e13e266c0238fb Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Tue, 1 Oct 1996 04:56:59 +0000 Subject: [PATCH] When used as a shell builtin, this program decoded a subset of arguments known to printf(3) and then used printf() to format it... The only problem what the #define printf out1fmt. The code was behaving differently when run as a shell builtin since out1fmt() isn't printf(3). Simple hack. Print to a buffer and fputs (also #defined for sh) the result. This should fix the printf builtin problem in PR#1673, rather than leaving the call commented out. (printf.o was being statically linked in anyway, we might as well use it) --- usr.bin/printf/printf.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c index d370d98270a1..90e8c4501002 100644 --- a/usr.bin/printf/printf.c +++ b/usr.bin/printf/printf.c @@ -58,15 +58,20 @@ static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 7/20/93"; #endif #define PF(f, func) { \ + char *b = NULL; \ if (fieldwidth) \ if (precision) \ - (void)printf(f, fieldwidth, precision, func); \ + (void)asprintf(&b, f, fieldwidth, precision, func); \ else \ - (void)printf(f, fieldwidth, func); \ + (void)asprintf(&b, f, fieldwidth, func); \ else if (precision) \ - (void)printf(f, precision, func); \ + (void)asprintf(&b, f, precision, func); \ else \ - (void)printf(f, func); \ + (void)asprintf(&b, f, func); \ + if (b) { \ + (void)fputs(b, stdout); \ + free(b); \ + } \ } static int asciicode __P((void));