diff options
| author | Ron Yorston <rmy@pobox.com> | 2024-04-09 09:50:59 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-09-27 19:39:28 +0200 |
| commit | 2c232f1e60fc42230c4e14bc7c548ac0e6593173 (patch) | |
| tree | d403ca070ce06a85153a0bd4b05f6849e9eecf29 /libbb | |
| parent | e5b0547ac834dcd34c72df9aee1cf9c326c14b6f (diff) | |
| download | busybox-w32-2c232f1e60fc42230c4e14bc7c548ac0e6593173.tar.gz busybox-w32-2c232f1e60fc42230c4e14bc7c548ac0e6593173.tar.bz2 busybox-w32-2c232f1e60fc42230c4e14bc7c548ac0e6593173.zip | |
libbb: use full_write1_str() to shrink busybox_main()
There are two calls to dup2() in busybox_main(). These were
introduced to coerce full_write2_str() into writing to stdout.
The relevant commits were: 21278dff7 (busybox: do not print help
to fd 2, print it to fd 1) and 5a7c72015 (busybox --list option.
+140 bytes. Rob wanted it.)
Later, in commit 729ecb87b (bbconfig: make it independent from
printf functions), the function full_write1_str() was added.
Using this in busybox_main() allows us to drop the dup2() calls.
function old new delta
run_applet_and_exit 796 760 -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-36) Total: -36 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/appletlib.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index d9cc48423..ad373ae1c 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
| @@ -776,10 +776,9 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
| 776 | help: | 776 | help: |
| 777 | output_width = get_terminal_width(2); | 777 | output_width = get_terminal_width(2); |
| 778 | 778 | ||
| 779 | dup2(1, 2); | 779 | full_write1_str(bb_banner); /* reuse const string */ |
| 780 | full_write2_str(bb_banner); /* reuse const string */ | 780 | full_write1_str(" multi-call binary.\n"); /* reuse */ |
| 781 | full_write2_str(" multi-call binary.\n"); /* reuse */ | 781 | full_write1_str( |
| 782 | full_write2_str( | ||
| 783 | "BusyBox is copyrighted by many authors between 1998-2015.\n" | 782 | "BusyBox is copyrighted by many authors between 1998-2015.\n" |
| 784 | "Licensed under GPLv2. See source distribution for detailed\n" | 783 | "Licensed under GPLv2. See source distribution for detailed\n" |
| 785 | "copyright notices.\n" | 784 | "copyright notices.\n" |
| @@ -817,20 +816,20 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
| 817 | while (*a) { | 816 | while (*a) { |
| 818 | int len2 = strlen(a) + 2; | 817 | int len2 = strlen(a) + 2; |
| 819 | if (col >= (int)output_width - len2) { | 818 | if (col >= (int)output_width - len2) { |
| 820 | full_write2_str(",\n"); | 819 | full_write1_str(",\n"); |
| 821 | col = 0; | 820 | col = 0; |
| 822 | } | 821 | } |
| 823 | if (col == 0) { | 822 | if (col == 0) { |
| 824 | col = 6; | 823 | col = 6; |
| 825 | full_write2_str("\t"); | 824 | full_write1_str("\t"); |
| 826 | } else { | 825 | } else { |
| 827 | full_write2_str(", "); | 826 | full_write1_str(", "); |
| 828 | } | 827 | } |
| 829 | full_write2_str(a); | 828 | full_write1_str(a); |
| 830 | col += len2; | 829 | col += len2; |
| 831 | a += len2 - 1; | 830 | a += len2 - 1; |
| 832 | } | 831 | } |
| 833 | full_write2_str("\n"); | 832 | full_write1_str("\n"); |
| 834 | return 0; | 833 | return 0; |
| 835 | } | 834 | } |
| 836 | 835 | ||
| @@ -850,14 +849,13 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
| 850 | if (is_prefixed_with(argv[1], "--list")) { | 849 | if (is_prefixed_with(argv[1], "--list")) { |
| 851 | unsigned i = 0; | 850 | unsigned i = 0; |
| 852 | const char *a = applet_names; | 851 | const char *a = applet_names; |
| 853 | dup2(1, 2); | ||
| 854 | while (*a) { | 852 | while (*a) { |
| 855 | # if ENABLE_FEATURE_INSTALLER | 853 | # if ENABLE_FEATURE_INSTALLER |
| 856 | if (argv[1][6]) /* --list-full? */ | 854 | if (argv[1][6]) /* --list-full? */ |
| 857 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); | 855 | full_write1_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); |
| 858 | # endif | 856 | # endif |
| 859 | full_write2_str(a); | 857 | full_write1_str(a); |
| 860 | full_write2_str("\n"); | 858 | full_write1_str("\n"); |
| 861 | i++; | 859 | i++; |
| 862 | while (*a++ != '\0') | 860 | while (*a++ != '\0') |
| 863 | continue; | 861 | continue; |
