summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c20
-rw-r--r--libbb/getopt32.c4
-rw-r--r--libbb/vfork_daemon_rexec.c3
3 files changed, 19 insertions, 8 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 7f0d620..2dea2b4 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -78,6 +78,17 @@
#endif
+unsigned FAST_FUNC string_array_len(char **argv)
+{
+ char **start = argv;
+
+ while (*argv)
+ argv++;
+
+ return argv - start;
+}
+
+
#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
static const char usage_messages[] ALIGN1 = UNPACKED_USAGE;
#else
@@ -868,10 +879,7 @@ static int busybox_main(char **argv)
# if NUM_APPLETS > 0
void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
{
- int argc = 1;
-
- while (argv[argc])
- argc++;
+ int argc = string_array_len(argv);
/* Reinit some shared global data */
xfunc_error_retval = EXIT_FAILURE;
@@ -993,7 +1001,11 @@ int main(int argc UNUSED_PARAM, char **argv)
}
/* applet_names in this case is just "applet\0\0" */
lbb_prepare(applet_names IF_FEATURE_INDIVIDUAL(, argv));
+# if ENABLE_BUILD_LIBBUSYBOX
+ return SINGLE_APPLET_MAIN(string_array_len(argv), argv);
+# else
return SINGLE_APPLET_MAIN(argc, argv);
+# endif
#elif !ENABLE_BUSYBOX && NUM_APPLETS == 0
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index b87b835..80f4cc0 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -379,9 +379,7 @@ getopt32(char **argv, const char *applet_opts, ...)
int spec_flgs = 0;
/* skip 0: some applets cheat: they do not actually HAVE argv[0] */
- argc = 1;
- while (argv[argc])
- argc++;
+ argc = 1 + string_array_len(argv + 1);
va_start(p, applet_opts);
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index fd481bf..2695f99 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -16,6 +16,7 @@
*/
#include "busybox.h" /* uses applet tables */
+#include "NUM_APPLETS.h"
/* This does a fork/exec in one call, using vfork(). Returns PID of new child,
* -1 for failure. Runs argv[0], searching path if that has no / in it. */
@@ -156,7 +157,7 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
int FAST_FUNC spawn_and_wait(char **argv)
{
int rc;
-#if ENABLE_FEATURE_PREFER_APPLETS
+#if ENABLE_FEATURE_PREFER_APPLETS && (NUM_APPLETS > 1)
int a = find_applet_by_name(argv[0]);
if (a >= 0) {