aboutsummaryrefslogtreecommitdiff
path: root/coreutils/printf.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-08-28 10:43:12 +0100
committerRon Yorston <rmy@pobox.com>2020-08-28 10:48:01 +0100
commit5f696450596f34c80edb1bf866a876fcc8692334 (patch)
tree6ab22e6184b4ccd54072c24d4c9d35ca739861f3 /coreutils/printf.c
parente1a7b5a4c98d5fabf5d318850950a42db27f3d44 (diff)
downloadbusybox-w32-5f696450596f34c80edb1bf866a876fcc8692334.tar.gz
busybox-w32-5f696450596f34c80edb1bf866a876fcc8692334.tar.bz2
busybox-w32-5f696450596f34c80edb1bf866a876fcc8692334.zip
printf: ensure '\045' is printed as '%'
Using printf() instead of fputs() to save a few bytes was a false economy. printf() eats percent signs. See GitHub issue #199. Adds 32 bytes.
Diffstat (limited to 'coreutils/printf.c')
-rw-r--r--coreutils/printf.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c
index d2b715406..aabc51e0d 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -151,6 +151,11 @@ static double my_xstrtod(const char *arg)
151 return result; 151 return result;
152} 152}
153 153
154static int fputs_stdout(const char *s)
155{
156 return fputs(s, stdout);
157}
158
154/* Handles %b; return 1 if output is to be short-circuited by \c */ 159/* Handles %b; return 1 if output is to be short-circuited by \c */
155static int print_esc_string(const char *str) 160static int print_esc_string(const char *str)
156{ 161{
@@ -196,7 +201,7 @@ static int print_esc_string(const char *str)
196#if ENABLE_PLATFORM_MINGW32 201#if ENABLE_PLATFORM_MINGW32
197 finish: 202 finish:
198 *t = '\0'; 203 *t = '\0';
199 printf(s); 204 fputs_stdout(s);
200 free(s); 205 free(s);
201 return ret; 206 return ret;
202#else 207#else
@@ -325,7 +330,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
325 case '%': 330 case '%':
326#if ENABLE_PLATFORM_MINGW32 331#if ENABLE_PLATFORM_MINGW32
327 *t = '\0'; 332 *t = '\0';
328 printf(s); 333 fputs_stdout(s);
329 t = s; 334 t = s;
330#endif 335#endif
331 direc_start = f++; 336 direc_start = f++;
@@ -420,12 +425,12 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
420 case '\\': 425 case '\\':
421 if (*++f == 'c') { 426 if (*++f == 'c') {
422 *t = '\0'; 427 *t = '\0';
423 printf(s); 428 fputs_stdout(s);
424 return saved_argv; /* causes main() to exit */ 429 return saved_argv; /* causes main() to exit */
425 } 430 }
426 *t = bb_process_escape_sequence((const char **)&f); 431 *t = bb_process_escape_sequence((const char **)&f);
427 if (*t == '\0') { 432 if (*t == '\0') {
428 printf(s); 433 fputs_stdout(s);
429 bb_putchar(*t); 434 bb_putchar(*t);
430 t = s; 435 t = s;
431 } 436 }
@@ -451,7 +456,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
451 } 456 }
452#if ENABLE_PLATFORM_MINGW32 457#if ENABLE_PLATFORM_MINGW32
453 *t = '\0'; 458 *t = '\0';
454 printf(s); 459 fputs_stdout(s);
455#endif 460#endif
456 461
457 return argv; 462 return argv;