[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH 1/2] libbb: use full_write1_str() to shrink busybox_main()
From: Ron Yorston <rmy () pobox ! com>
Date: 2024-04-09 8:50:59
Message-ID: 66150173.MXIbzXB/MRJvMLLn%rmy () pobox ! com
[Download RAW message or body]
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>
---
libbb/appletlib.c | 24 +++++++++++-------------
1 file 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)
help:
output_width = get_terminal_width(2);
- dup2(1, 2);
- full_write2_str(bb_banner); /* reuse const string */
- full_write2_str(" multi-call binary.\n"); /* reuse */
- full_write2_str(
+ full_write1_str(bb_banner); /* reuse const string */
+ full_write1_str(" multi-call binary.\n"); /* reuse */
+ full_write1_str(
"BusyBox is copyrighted by many authors between 1998-2015.\n"
"Licensed under GPLv2. See source distribution for detailed\n"
"copyright notices.\n"
@@ -817,20 +816,20 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
while (*a) {
int len2 = strlen(a) + 2;
if (col >= (int)output_width - len2) {
- full_write2_str(",\n");
+ full_write1_str(",\n");
col = 0;
}
if (col == 0) {
col = 6;
- full_write2_str("\t");
+ full_write1_str("\t");
} else {
- full_write2_str(", ");
+ full_write1_str(", ");
}
- full_write2_str(a);
+ full_write1_str(a);
col += len2;
a += len2 - 1;
}
- full_write2_str("\n");
+ full_write1_str("\n");
return 0;
}
@@ -850,14 +849,13 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
if (is_prefixed_with(argv[1], "--list")) {
unsigned i = 0;
const char *a = applet_names;
- dup2(1, 2);
while (*a) {
# if ENABLE_FEATURE_INSTALLER
if (argv[1][6]) /* --list-full? */
- full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
+ full_write1_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
# endif
- full_write2_str(a);
- full_write2_str("\n");
+ full_write1_str(a);
+ full_write1_str("\n");
i++;
while (*a++ != '\0')
continue;
--
2.44.0
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic