From 551bfdb97f45f0277a408ec2d44ee18967b98304 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 31 Jul 2025 18:35:11 +0200 Subject: ls: implement -q, fix -w0, reduce startup time function old new delta ls_main 598 660 +62 ls_longopts - 47 +47 G_isatty - 36 +36 print_name 102 134 +32 display_files 358 374 +16 .rodata 105829 105833 +4 vgetopt32 1330 1317 -13 static.ls_longopts 47 - -47 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 4/1 up/down: 197/-60) Total: 137 bytes Signed-off-by: Denys Vlasenko --- libbb/getopt32.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/getopt32.c b/libbb/getopt32.c index b5efa19ac..4c05dcb97 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -530,6 +530,7 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options, * "fake" short options, like this one: * wget $'-\203' "Test: test" http://kernel.org/ * (supposed to act as --header, but doesn't) */ + next_opt: #if ENABLE_LONG_OPTS while ((c = getopt_long(argc, argv, applet_opts, long_options, NULL)) != -1) { @@ -544,8 +545,16 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options, * but we construct long opts so that flag * is always NULL (see above) */ if (on_off->opt_char == '\0' /* && c != '\0' */) { - /* c is probably '?' - "bad option" */ - goto error; + /* We reached the end of complementary[] and did not find -c */ + if (c == '?') /* getopt says: "bad option, or option has no required argument" */ + goto error; + /* if there were options beyond 32 bits (example: ls), + * they got no complementary[] slot, and no result bit. + * IOW: they must be "accept but ignore" options. + * For them, we end up here. + */ + //bb_error_msg("ignored option '%c', skipping", c); + goto next_opt; } } if (flags & on_off->incongruously) -- cgit v1.2.3-55-g6feb