aboutsummaryrefslogtreecommitdiff
path: root/libbb/getopt32.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-04-01 14:47:57 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-04-01 14:47:57 +0000
commit468aea2d8800cc0496383616d82d7c957ae8bc50 (patch)
tree8a2f3d80dc2440dd007caed4cfa235b3858c9170 /libbb/getopt32.c
parent165f5b394fa337e71e08435b51108f4394199b2b (diff)
downloadbusybox-468aea2d8800cc0496383616d82d7c957ae8bc50.tar.gz
shells: do not frocibly enable test, echo and kill _applets_,
just build relevant source and use xxx_main functions. build system: add a special case when we have exactly one applet enabled (makes "true", "false", "basename" REALLY tiny). getopt32: do not use stdio. function old new delta getopt32 1385 1412 +27 make_device 1187 1200 +13 basename_main 120 127 +7 tcpudpsvd_main 1922 1926 +4 testcmd 5 - -5 echocmd 5 - -5 fuser_main 1243 1231 -12 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 4/1 up/down: 51/-22) Total: 29 bytes
Diffstat (limited to 'libbb/getopt32.c')
-rw-r--r--libbb/getopt32.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 51e030653..c0d885603 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -285,6 +285,10 @@ const char *const bb_argv_dash[] = { "-", NULL };
const char *opt_complementary;
+/* Many small applets don't want to suck in stdio.h only because
+ * they need to parse options by calling us */
+#define DONT_USE_PRINTF 1
+
enum {
PARAM_STRING,
PARAM_LIST,
@@ -335,7 +339,8 @@ getopt32(char **argv, const char *applet_opts, ...)
#define SHOW_USAGE_IF_ERROR 1
#define ALL_ARGV_IS_OPTS 2
#define FIRST_ARGV_IS_OPT 4
-#define FREE_FIRST_ARGV_IS_OPT 8
+#define FREE_FIRST_ARGV_IS_OPT (8 * !DONT_USE_PRINTF)
+
int spec_flgs = 0;
argc = 0;
@@ -489,10 +494,16 @@ getopt32(char **argv, const char *applet_opts, ...)
va_end(p);
if (spec_flgs & FIRST_ARGV_IS_OPT) {
- if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
+ if (argv[1] && argv[1][0] != '-' && argv[1][1] != '\0') {
+#if DONT_USE_PRINTF
+ char *pp = alloca(strlen(argv[1]) + 2);
+ *pp++ = '-';
+ argv[1] = strcpy(pp, argv[1]);
+#else
argv[1] = xasprintf("-%s", argv[1]);
if (ENABLE_FEATURE_CLEAN_UP)
spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
+#endif
}
}
@@ -573,7 +584,7 @@ getopt32(char **argv, const char *applet_opts, ...)
}
}
-#if (ENABLE_AR || ENABLE_TAR) && ENABLE_FEATURE_CLEAN_UP
+#if ENABLE_FEATURE_CLEAN_UP
if (spec_flgs & FREE_FIRST_ARGV_IS_OPT)
free(argv[1]);
#endif