aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* win32: work around problem with stderr in MSVCRTRon Yorston2024-09-301-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Try to run a non-existent command with standard error closed: xyz 2>&- In recent versions of busybox-w32 this resulted in problems with moving through history (either using up/down keys or ctrl-r) and tab completion. In all cases the order of the prompt and the command were reversed. Bisection showed the problem was first seen in PRE-5396 which merged some commits from upstream, including fd47f0567 (lineedit: print prompt and editing operations to stderr). This (eventually) called to mind a previous problem with stderr in xargs which was fixed by commit f192e6539 (xargs: fix 'xargs -sNUM' tests). In both cases it seemed that mixing calls to bb_putchar_stderr() and fprintf(stderr, ...) was at fault. The former uses a file descriptor while the latter uses a stream. It was almost as if the stream was buffered. - The problem with xargs affected 32-bit and 64-bit builds with MSVCRT. - The problem with '2>&-' only affected 32-bit builds with MSVCRT. - Neither problem was present with UCRT builds. As a workaround change bb_putchar_stderr() to use the stderr stream in builds for MSVCRT. Saves 16 bytes in the 32-bit build. (GitHub issue #460)
* Merge branch 'busybox' into mergeRon Yorston2023-07-131-0/+10
|\
| * libbb: code shrink: introduce and use [_]exit_FAILURE()Denys Vlasenko2023-06-151-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta exit_FAILURE - 7 +7 _exit_FAILURE - 7 +7 run 198 199 +1 restore_state_and_exit 114 115 +1 xbsd_write_bootstrap 399 397 -2 vfork_compressor 209 207 -2 sig_handler 12 10 -2 serial_ctl 154 152 -2 parse_args 1169 1167 -2 onintr 21 19 -2 make_new_session 493 491 -2 login_main 988 986 -2 gotsig 35 33 -2 do_iplink 1315 1313 -2 addgroup_main 397 395 -2 inetd_main 1911 1908 -3 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 2/12 up/down: 16/-25) Total: -9 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | libbb: don't build useless functionsRon Yorston2023-04-161-0/+2
| | | | | | | | | | | | | | | | | | | | The functions ndelay_on(), ndelay_off() and close_on_exec_on() don't do anything useful because our fcntl(2) implementation doesn't support the features they require. Replace them with stubs. Saves 176-208 bytes.
* | win32: virtual terminal input fixesRon Yorston2023-03-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | - Disable ENABLE_PROCESSED_INPUT in raw mode. Otherwise ^C isn't immediately detected during shell command line editing with virtual terminal input enabled. - Switch read_key()/unix_readkey() to windows_read_key()/read_key(). This allows the shell `read` builtin to use windows_read_key(). Without this change `read` fails when virtual terminal input is enabled.
* | win32: add virtual terminal support to termios(3)Ron Yorston2023-03-051-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | Modify `struct termios` to support Windows virtual terminals. Native console mode flags replace the Unix `c_?flag` structure members. Remove unsupported flags from termios.h. Add implementations of tcgetattr(3)/tcsetattr(3) to get/set console flags when virtual terminal input mode is enabled. Add support for emulating raw mode to get_termios_and_make_raw(). This (and related functions) are exposed but not yet used.
* | Merge busybox into mergeRon Yorston2022-01-061-0/+10
|\| | | | | | | | | | | Fix merge conflict in miscutils/less.c. Use exit_SUCCESS() where possible.
| * libbb: code shrink: introduce and use [_]exit_SUCCESS()Denys Vlasenko2022-01-051-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta exit_SUCCESS - 7 +7 _exit_SUCCESS - 7 +7 run_pipe 1562 1567 +5 pseudo_exec_argv 399 400 +1 finish 86 87 +1 start_stop_daemon_main 1109 1107 -2 shutdown_on_signal 38 36 -2 runsv_main 1662 1660 -2 redirect 1070 1068 -2 read_line 79 77 -2 pause_and_low_level_reboot 54 52 -2 list_i2c_busses_and_exit 483 481 -2 less_exit 12 10 -2 identify 4123 4121 -2 grep_file 1161 1159 -2 getty_main 1519 1517 -2 fsck_minix_main 2681 2679 -2 free_session 132 130 -2 fdisk_main 4739 4737 -2 clean_up_and_exit 53 51 -2 bsd_select 1566 1564 -2 bb_daemonize_or_rexec 198 196 -2 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 3/17 up/down: 21/-34) Total: -13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2021-06-071-0/+6
|\|
| * libbb: correct the name of is_TERM_dumb()Denys Vlasenko2021-06-051-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ls: don't output any colors with TERM=dumbSören Tempel2021-06-041-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The TERM variable is usually set to "dumb" to indicate that the terminal does not support any ANSI escape sequences. Presently, ls does not honor this variable and outputs colors anyhow which results in unreadable output, unless the user explicitly disables colors using `ls --color=never`. The rational behind this change is that ls should "just work" by default, even on dumb terminals. For this reason, this patch adds a check which additionally consults the TERM variable before printing any colors. This is analogous to the existing check for ensuring that standard output is a tty. As such, colors can still be forced with `--color=force`, even if TERM is set to dumb. function old new delta is_TERM_dumb - 40 +40 ls_main 579 598 +19 .rodata 103246 103251 +5 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 64/0) Total: 64 bytes Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2021-01-141-12/+0
|\|
| * libbb: introduce and use xsettimeofday()Denys Vlasenko2020-12-161-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta xsettimeofday - 25 +25 rdate_main 274 260 -14 step_time 348 331 -17 set_kernel_timezone_and_clock 119 102 -17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 25/-48) Total: -23 bytes text data bss dec hex filename 1020753 559 5052 1026364 fa93c busybox_old 1020708 559 5052 1026319 fa90f busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2019-08-161-1/+1
|\|
| * 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>
* | Merge branch 'busybox' into mergeRon Yorston2018-05-131-4/+9
|\|
| * less: fix fallout from "use common routine to set raw termios"Denys Vlasenko2018-04-161-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Testcase: (sleep 10; ls) | busybox less [...] ~ LICENSE ~ Makefile ~ Makefile.custom ~ Makefile.flags [...] less did not want this part: + /* dont convert NL to CR+NL on output */ + newterm->c_oflag &= ~(ONLCR); function old new delta get_termios_and_make_raw 108 115 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: exclude termios codeRon Yorston2018-04-051-0/+2
| | | | | | | | | | The code to manipulate terminal settings serves no purpose in WIN32. Use conditional compilation to exclude much of it.
* | win32: improvements to get_terminal_width_heightRon Yorston2018-04-031-0/+2
|/ | | | | | | | - move winansi_get_terminal_width_height from winansi.c to ioctl.c, the only caller; - check both stdout and stderr for a connection to a console; - omit unnecessary code in get_terminal_width_height (because the WIN32 implementation ignores the file descriptor).
* libbb: use BUILD_BUG_ON in utoa_to_buf()Denys Vlasenko2018-03-281-4/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* xfuncs: Handle missing non-POSIX termios constantsJames Clarke2017-10-301-0/+9
| | | | | Signed-off-by: James Clarke <jrtc27@jrtc27.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* whitespace and comment format fixes, no code changesDenys Vlasenko2017-10-051-2/+0
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Clarify OPOST bit meaningDenys Vlasenko2017-09-151-3/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* less,microcom,lineedit: use common routine to set raw termiosDenys Vlasenko2017-09-151-15/+40
| | | | | | | | | | | | | function old new delta get_termios_and_make_raw - 139 +139 xget1 39 8 -31 read_line_input 3912 3867 -45 less_main 2525 2471 -54 set_termios_to_raw 116 36 -80 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/4 up/down: 139/-210) Total: -71 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* slattach: code shrink, better --help textDenys Vlasenko2017-08-061-1/+1
| | | | | | | | | | | | | | function old new delta tcsetattr_serial_or_warn - 34 +34 static.int_N_SLIP - 4 +4 restore_state_and_exit 123 117 -6 packed_usage 31774 31747 -27 set_termios_state_or_warn 42 - -42 slattach_main 673 624 -49 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 0/3 up/down: 38/-124) Total: -86 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: consolidate the code to set termios unbuffered modeDenys Vlasenko2017-01-111-0/+37
| | | | | | | | | | | | | | | | function old new delta set_termios_to_raw - 116 +116 count_lines 72 74 +2 powertop_main 1458 1430 -28 top_main 943 914 -29 more_main 759 714 -45 fsck_minix_main 2969 2921 -48 conspy_main 1197 1135 -62 rawmode 99 36 -63 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/6 up/down: 118/-275) Total: -157 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* man: make width selection more thorough; explain how to override itDenys Vlasenko2016-10-311-9/+38
| | | | | | | Fedora's "man CMD >file" still uses terminal width, not 80 (but disables formatting), this change mimics that. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: two new functions: wait_for_exitstatus(pid), xfchdir(fd)Denys Vlasenko2016-04-011-0/+12
| | | | | | Bartosz Golaszewski proposed xfchdir() Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: factor out code which queries screen widthDenys Vlasenko2015-10-231-0/+6
| | | | | | | | | | | | | | | | function old new delta get_terminal_width - 17 +17 stty_main 1196 1197 +1 pstree_main 321 319 -2 ls_main 735 731 -4 watch_main 232 225 -7 bb_progress_update 714 706 -8 ps_main 555 543 -12 run_applet_and_exit 708 695 -13 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/6 up/down: 18/-46) Total: -28 byte Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Removes stray empty line from codeManinder Singh2015-07-131-1/+0
| | | | | | | | | This patch removes stray empty line from busybox code reported by script find_stray_empty_lines Signed-off-by: Maninder Singh <maninder1.s@samsung.com> Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* less: move "retry-on-EAGAIN" logic closer to read opsDenys Vlasenko2014-09-221-4/+6
| | | | | | | | | | | | | | | This makes "G" (goto end of input) command work as well as /search_for_nonexistent_string: both will read to EOF now even from somewhat slow input (such as kernel's "git log"). function old new delta ndelay_on 35 43 +8 ndelay_off 35 43 +8 read_lines 695 691 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-4) Total: 12 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: make ndelay_no/off a bit more clever. +14 bytesDenys Vlasenko2011-01-241-6/+12
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* typo fixDenys Vlasenko2010-12-051-1/+1
| | | | 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>
* libbb: introduce and use BB_EXECVP_or_die()Pascal Bellard2010-07-041-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta BB_EXECVP_or_die - 47 +47 time_main 1042 1043 +1 chrt_main 371 364 -7 ionice_main 292 282 -10 setsid_main 69 56 -13 nohup_main 236 223 -13 cttyhack_main 266 253 -13 chroot_main 94 81 -13 chpst_main 746 733 -13 timeout_main 297 279 -18 taskset_main 541 522 -19 vfork_child 67 45 -22 parse 975 953 -22 lpd_main 770 748 -22 launch_helper 192 170 -22 tcpudpsvd_main 1810 1782 -28 nice_main 190 156 -34 env_main 242 206 -36 run_command 221 174 -47 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/17 up/down: 48/-352) Total: -304 bytes Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* utoa: shrinkDenys Vlasenko2010-06-101-15/+29
| | | | | | | | function old new delta itoa_to_buf 20 23 +3 utoa_to_buf 117 101 -16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* bbconfig: make it independent from printf functionsDenys Vlasenko2010-06-071-0/+10
| | | | | | | | | | | | | | function old new delta full_write2_str - 25 +25 full_write1_str - 25 +25 clear_main 21 20 -1 telnet_main 1488 1477 -11 getty_main 1932 1918 -14 full_write22_str 25 - -25 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 0/3 up/down: 50/-51) Total: -1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* pipe_progress: make it independent of printf machineryDenys Vlasenko2010-06-061-71/+2
| | | | | | | | | | | | | function old new delta bb_putchar_stderr - 24 +24 ParseField 494 471 -23 progress_meter 212 188 -24 xargs_main 888 842 -46 pipe_progress_main 151 105 -46 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 0/4 up/down: 24/-139) Total: -115 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* vi: discover window size even on serial consoles. optionalDenys Vlasenko2010-04-181-24/+30
| | | | | | | | | | | | | | | | function old new delta edit_file 671 761 +90 wh_helper - 57 +57 query_screen_dimensions 54 63 +9 ar_main 533 542 +9 refresh 767 773 +6 vi_main 242 243 +1 text_yank 56 54 -2 get_terminal_width_height 180 135 -45 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 5/2 up/down: 172/-47) Total: 125 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: factor out hex2bin() for infiniband address parserDenys Vlasenko2010-04-041-0/+35
| | | | | | | | function old new delta hex2bin - 149 +149 in_ib 172 27 -145 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* tidy up O_NONBLOCK usage. use libbb functions in stty.Denys Vlasenko2009-11-111-2/+2
| | | | | | | | | | Added O_RDONLY where improves readability. Note: O_RDONLY == 0, so it is there even if not specified. function old new delta stty_main 1289 1235 -54 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* move generate_uuid from mkswap to libbbVladimir Dronnikov2009-10-151-0/+63
| | | | | Signed-off-by: Vladimir Dronnikov <dronnikov@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb/human_readable.c: shrink; and reduce bss usageDenys Vlasenko2009-10-131-104/+0
| | | | | | | | | | | | | | | | | | | | also, move smart_ulltoaN there and comment usage locations function old new delta static.unit_chars 7 9 +2 utoa_to_buf 110 108 -2 make_human_readable_str 262 258 -4 fallbackSort 1723 1719 -4 static.fmt 97 92 -5 static.fmt_tenths 10 - -10 static.str 21 4 -17 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/5 up/down: 2/-42) Total: -40 bytes text data bss dec hex filename 820981 453 6932 828366 ca3ce busybox_old 820968 453 6916 828337 ca3b1 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: introduce and use xmalloc_ttyname (-32 in bss).Denis Vlasenko2008-12-231-0/+11
| | | | | | | | | ash: small code shrink text data bss dec hex filename 793669 504 7524 801697 c3ba1 busybox_old 793659 504 7492 801655 c3b77 busybox_unstripped
* libbb: add strncpy_IFNAMSIZDenis Vlasenko2008-12-021-0/+8
| | | | | | | | | | | | | | | | | | | | function old new delta ... udhcp_read_interface 225 220 -5 brctl_main 1151 1146 -5 add_interface 109 104 -5 ipaddr_list_or_flush 2174 2167 -7 do_add_ioctl 88 80 -8 vconfig_main 249 240 -9 do_del_ioctl 78 68 -10 do_iplink 1186 1173 -13 do_if_fetch 766 753 -13 buffer_fill_and_print 196 179 -17 parse_args 1709 1684 -25 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/20 up/down: 11/-140) Total: -129 bytes
* *: code shrink by adding a wrapper around very common tcsetattr(0, TCSANOW, ↵Denis Vlasenko2008-11-051-0/+5
| | | | | | | | | | | | | | | | | | | | | | xx) op function old new delta tcsetattr_stdin_TCSANOW - 14 +14 set_sane_term 116 113 -3 top_main 1277 1273 -4 make_new_session 421 415 -6 rawmode 133 126 -7 reset_term 18 10 -8 die 43 35 -8 cookmode 62 54 -8 vlock_main 425 415 -10 read_line_input 3165 3155 -10 bb_askpass 357 347 -10 fsck_minix_main 3079 3065 -14 getty_main 2375 2332 -43 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/12 up/down: 14/-131) Total: -117 bytes
* *: introduce and use FAST_FUNC: regparm on i386, otherwise no-onDenis Vlasenko2008-06-271-12/+12
| | | | | | | text data bss dec hex filename 808035 611 6868 815514 c719a busybox_old 804472 611 6868 811951 c63af busybox_unstripped
* more -Wall warning fixes. -Wall is enabled now.Denis Vlasenko2008-05-181-1/+1
|
* style fixes. no code changesDenis Vlasenko2008-04-191-1/+1
|
* Splitting xfuncs.c into two parts. No code chabges.Denis Vlasenko2008-04-091-507/+24
|