aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-03 21:31:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-03 21:31:16 +0200
commitd4e4fdb5ce5ccc067b3d35d877f7a7d978869517 (patch)
treebac3e4a55fa72db0c67d377b90869b4d63e8c3c9 /libbb/appletlib.c
parent2e989ef232e35750df573898077dd356003705b2 (diff)
downloadbusybox-d4e4fdb5ce5ccc067b3d35d877f7a7d978869517.tar.gz
fixes for bugs found by make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 7f0d62060..2dea2b43a 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