aboutsummaryrefslogtreecommitdiff
path: root/coreutils/printf.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'busybox' into mergeRon Yorston2023-04-091-1/+1
|\
| * hush: printf builtin with no arguments should not exitDenys Vlasenko2023-04-031-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge busybox into mergeRon Yorston2021-12-271-1/+1
|\| | | | | | | Fix merge conflict in coreutils/timeout.c.
| * printf: allow 0 as a flag and allow multiple flagsRon Yorston2021-12-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The '%' character in a format specification may be followed by one or more flags from the list "+- #0". BusyBox printf didn't support the '0' flag or allow multiple flags to be provided. As a result the formats '%0*d' and '%0 d' were considered to be invalid. The lack of support for '0' was pointed out by Andrew Snyder on the musl mailing list: https://www.openwall.com/lists/musl/2021/12/14/2 function old new delta printf_main 860 891 +31 .rodata 99281 99282 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 32/0) Total: 32 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | printf: improved error handlingRon Yorston2021-08-151-19/+23
| | | | | | | | | | | | | | | | | | | | | | | | The printf applet is NOFORK and is used to implement the printf command in ash. It should therefore be careful about handling memory allocation failures. If vasprintf() or realloc() fail the applet now carries on as best it can. This may result in some lost output but at least the shell will survive. Saves 32 bytes.
* | Merge branch 'busybox' into mergeRon Yorston2021-05-141-0/+1
|\|
| * timeout,top,watch,ping: parse NN.N fractional duration in locales with other ↵Denys Vlasenko2021-03-231-0/+1
| | | | | | | | | | | | separators Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | printf: better support for escape sequencesRon Yorston2021-02-031-48/+60
| | | | | | | | | | | | | | | | | | | | | | | | Upstream printf outputs one character at a time which doesn't play well with emulation of ANSI escape sequences. Previous workarounds for this only applied in limited circumstances. Try a different approach: replace putchar() and printf() calls in the printf applet with custom routines which store the output in memory. It's only really output at the end of the program or when a newline is detected and a non-trivial amount has been collected.
* | printf: code shrinkRon Yorston2021-01-271-19/+7
| | | | | | | | | | | | | | | | | | | | Instead of constructing null-terminated strings to print, output the characters between the 's' and 't' pointers using fwrite(). This avoids having to output two separate strings when an escaped literal NUL character is encountered in the format string. Saves 32 bytes.
* | tls: avoid unnecessary changes to POSIX build, part 2Ron Yorston2021-01-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | On reflection, the previous commit may have been ill-advised. There are many calls to open_read_close() and most shouldn't be able to access special devices. (Though in practice only a few are enabled in busybox-w32.) Nonetheless, I've implemented a new mechanism which uses the macro MINGW_SPECIAL() to mark calls to functions that are allowed to access special devices. An unrelated change is to avoid compiling fputs_stdout() in coreutils/printf.c for the POSIX build.
* | printf: ensure '\045' is printed as '%'Ron Yorston2020-08-281-5/+10
| | | | | | | | | | | | | | | | | | 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.
* | printf: prevent '\0' in format string from truncating outputFRP-3578-g359211429Ron Yorston2020-08-241-1/+9
| | | | | | | | | | | | | | | | | | Commit 4a2af48e6 (printf: emit more contiguous text to improve escape sequences) didn't treat an escaped null byte in the format string correctly. The output string was truncated at the null byte. Detect this case, output the partial string and the null byte and carry on.
* | printf: emit more contiguous text to improve escape sequencesRon Yorston2020-06-041-1/+50
|/ | | | | | | | | | | | | | | | Users have a reasonable expectation that printf should be able to construct ANSI escape sequences and have them take effect. This expectation isn't met because printf tends to output one character at a time whereas busybox-w32 needs escape sequences to be output contiguously Force printf to output contiguous text in two cases: - literal text in the format string - string arguments output using the '%b' format specifier (See GitHub issue #189.)
* libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne2019-07-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* config: update size informationDenys Vlasenko2018-12-281-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: fix printf "%u\n" +18446744073709551614Denys Vlasenko2018-10-301-0/+8
| | | | | | | | | | | function old new delta conv_strtoll 19 32 +13 conv_strtoull 49 61 +12 bb_strtoll 89 84 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 25/-5) Total: 20 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: fix printing +-prefixed numbersBernhard Reutner-Fischer2018-10-191-2/+3
| | | | | | | | | | | | | | Thanks to Cristian Ionescu-Idbohrn for noticing. Also fix "%d" ' 42' to skip leading whitespace. function old new delta print_direc 435 454 +19 bb_strtoll 99 103 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 23/0) Total: 23 bytes Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* whitespace and comment format fixes, no code changesDenys Vlasenko2017-10-051-1/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* whitespace and comment format fixes, no code changesDenys Vlasenko2017-10-051-35/+33
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* regularize format of source file headers, no code changesDenys Vlasenko2017-09-181-1/+0
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* config: do not use `a' quoting in help textsDenys Vlasenko2017-08-021-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* config: deindent all help textsDenys Vlasenko2017-07-211-2/+2
| | | | | | Those two spaces after tab have no effect, and always a nuisance when editing. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Update menuconfig items with approximate applet sizesDenys Vlasenko2017-07-181-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: fix format string sanity checkRon Yorston2017-07-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | One of the tests for printf checks for an invalid bare '%' in the format string: $ busybox printf '%' a b c printf: %: invalid format On x86_64 a slightly different test doesn't work correctly: $ busybox printf '%' d e f printf: invalid number 'd' printf: invalid number 'e' printf: invalid number 'f' On other platforms the test fails randomly depending on how the arguments are laid out in memory. There are two places in the code where strchr is used to determine if a character in the format string is valid. However, strchr also returns a valid pointer if the character being searched for is the null terminator thus causing the code to incorrectly suppose that a valid character has been found. Add explicit checks for the null terminator. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shells: make hush test optional, rename ASH_BUILTIN_foo -> ASH_fooDenys Vlasenko2017-01-101-1/+4
| | | | | | | This makes hash and ash more symmetrical wrt config menu and config options. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Convert all coreutils/* applets to "new style" applet definitionsDenys Vlasenko2016-11-231-0/+11
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: short-circuit output when argument to %b includes \cRon Yorston2016-01-311-3/+9
| | | | | | | | | | | | | | | printf wasn't correctly handling \c in an argument to the %b format specifier. printf %bXX OK\\c returned 'OK\cXX' rather than the expected 'OK'. function old new delta printf_main 886 899 +13 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: fix this case: printf "%b" '\0057usr\0057bin\n'Denys Vlasenko2012-03-071-2/+17
| | | | | | | | | It was not accepting \0NNN. Standard printf tool does. function old new delta printf_main 869 886 +17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: trim help textDenys Vlasenko2012-03-071-4/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* move help text from include/usage.src.h to coreutils/*.cPere Orga2011-03-311-0/+10
| | | | | Signed-off-by: Pere Orga <gotrunks@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: introduce and use strcpy_and_process_escape_sequencesDenys Vlasenko2010-10-231-10/+8
| | | | | | | | | | | | function old new delta strcpy_and_process_escape_sequences - 50 +50 bb_process_escape_sequence 148 138 -10 printf_main 789 776 -13 getty_main 1897 1831 -66 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 50/-89) Total: -39 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* nandwrite: complain on malformed -s NUMDenys Vlasenko2010-08-291-2/+2
| | | | | | Elsewhere: use common error message. -30 bytes net size change Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* *: make GNU licensing statement forms more regularDenys Vlasenko2010-08-161-1/+1
| | | | | | | This change retains "or later" state! No licensing _changes_ here, only form is adjusted (article, space between "GPL" and "v2" and so on). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: (allegedly) fix testsuite failureDenys Vlasenko2009-06-271-0/+2
| | | | | Signed-off-by: Colin Watson <cjwatson@ubuntu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: fix exit code on conversion errorDenys Vlasenko2009-06-181-13/+11
| | | | | Signed-off-by: Colin Watson <cjwatson@ubuntu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: accept negative numbers for %x; sh: overflowed numbers are 0Denys Vlasenko2009-06-051-0/+8
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printf: fix 1.12.0 breakage (from %*d fix). It was misinterpreting "*"Denis Vlasenko2009-03-031-3/+3
|
* printf: make integer format strings print long long-sized values.Denis Vlasenko2009-01-041-53/+65
| | | | | | | | | | | | | | function old new delta printf_main 668 834 +166 bb_strtoll - 84 +84 print_direc 391 431 +40 conv_strtoull - 19 +19 conv_strtoll - 19 +19 conv_strtoul 16 - -16 conv_strtol 16 - -16 ------------------------------------------------------------------------------ (add/remove: 4/2 grow/shrink: 2/0 up/down: 342/-32) Total: 296 bytes
* ash: printf builtin with no arguments should not exitDenis Vlasenko2008-12-101-1/+8
|
* ash: dont allow e.g. exec <&10 to attach to stript's fd!Denis Vlasenko2008-07-251-2/+5
| | | | | | | | | | | | | function old new delta is_hidden_fd - 61 +61 redirect 1135 1164 +29 popstring 134 140 +6 printf_main 635 637 +2 evalvar 1374 1376 +2 echo_main 294 296 +2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 5/0 up/down: 102/0) Total: 102 bytes
* fix all cases of strcpy on overlapping strings.Denis Vlasenko2008-07-221-1/+1
|
* printf: do not print garbage on "%Ld". closes bug 4214.Denis Vlasenko2008-07-181-6/+15
| | | | | | | | | | function old new delta printf_main 633 637 +4 multiconvert 99 79 -20 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-20) Total: -16 bytes
* printf: fix %b, fix several bugs in %*.*, fix compat issues withDenis Vlasenko2008-07-181-78/+121
| | | | | | | | | | | | | | | | | | | aborting too early, support %zd; expand testsuite function old new delta get_width_prec - 46 +46 multiconvert 82 99 +17 conv_strtod 44 54 +10 print_direc 382 391 +9 printf_main 629 633 +4 conv_strtoul 20 16 -4 conv_strtol 20 16 -4 my_xstrtoul 20 - -20 my_xstrtol 20 - -20 my_xstrtod 21 - -21 ------------------------------------------------------------------------------ (add/remove: 1/3 grow/shrink: 4/2 up/down: 86/-69) Total: 17 bytes
* printf: protect against bogus format specifiers. Hopefully closes bug 4184Denis Vlasenko2008-07-171-9/+13
|
* *: rename ATTRIBUTE_XXX to just XXX.Denis Vlasenko2008-07-051-1/+1
|
* ash: optional printf builtin. +25 bytes if off, +35 if on.Denis Vlasenko2008-06-011-3/+15
| | | | | by Cristian Ionescu-Idbohrn.
* printf: fix a trivial bugDenis Vlasenko2008-05-311-1/+1
|
* printf: code shrink by eliminating string alloc/copyDenis Vlasenko2008-05-311-28/+27
| | | | | | function old new delta print_direc 428 382 -46
* - use EXIT_{SUCCESS,FAILURE}. No object-code changesBernhard Reutner-Fischer2008-05-191-1/+1
|
* printf: fix printf -%s- foo, printf -- -%s- foo (bug 3354)Denis Vlasenko2008-05-181-28/+24
| | | | | | function old new delta printf_main 577 548 -29