diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-01 14:47:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-01 14:47:57 +0000 |
commit | 468aea2d8800cc0496383616d82d7c957ae8bc50 (patch) | |
tree | 8a2f3d80dc2440dd007caed4cfa235b3858c9170 /libbb/getopt32.c | |
parent | 165f5b394fa337e71e08435b51108f4394199b2b (diff) | |
download | busybox-w32-468aea2d8800cc0496383616d82d7c957ae8bc50.tar.gz busybox-w32-468aea2d8800cc0496383616d82d7c957ae8bc50.tar.bz2 busybox-w32-468aea2d8800cc0496383616d82d7c957ae8bc50.zip |
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.c | 17 |
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 }; | |||
285 | 285 | ||
286 | const char *opt_complementary; | 286 | const char *opt_complementary; |
287 | 287 | ||
288 | /* Many small applets don't want to suck in stdio.h only because | ||
289 | * they need to parse options by calling us */ | ||
290 | #define DONT_USE_PRINTF 1 | ||
291 | |||
288 | enum { | 292 | enum { |
289 | PARAM_STRING, | 293 | PARAM_STRING, |
290 | PARAM_LIST, | 294 | PARAM_LIST, |
@@ -335,7 +339,8 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
335 | #define SHOW_USAGE_IF_ERROR 1 | 339 | #define SHOW_USAGE_IF_ERROR 1 |
336 | #define ALL_ARGV_IS_OPTS 2 | 340 | #define ALL_ARGV_IS_OPTS 2 |
337 | #define FIRST_ARGV_IS_OPT 4 | 341 | #define FIRST_ARGV_IS_OPT 4 |
338 | #define FREE_FIRST_ARGV_IS_OPT 8 | 342 | #define FREE_FIRST_ARGV_IS_OPT (8 * !DONT_USE_PRINTF) |
343 | |||
339 | int spec_flgs = 0; | 344 | int spec_flgs = 0; |
340 | 345 | ||
341 | argc = 0; | 346 | argc = 0; |
@@ -489,10 +494,16 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
489 | va_end(p); | 494 | va_end(p); |
490 | 495 | ||
491 | if (spec_flgs & FIRST_ARGV_IS_OPT) { | 496 | if (spec_flgs & FIRST_ARGV_IS_OPT) { |
492 | if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') { | 497 | if (argv[1] && argv[1][0] != '-' && argv[1][1] != '\0') { |
498 | #if DONT_USE_PRINTF | ||
499 | char *pp = alloca(strlen(argv[1]) + 2); | ||
500 | *pp++ = '-'; | ||
501 | argv[1] = strcpy(pp, argv[1]); | ||
502 | #else | ||
493 | argv[1] = xasprintf("-%s", argv[1]); | 503 | argv[1] = xasprintf("-%s", argv[1]); |
494 | if (ENABLE_FEATURE_CLEAN_UP) | 504 | if (ENABLE_FEATURE_CLEAN_UP) |
495 | spec_flgs |= FREE_FIRST_ARGV_IS_OPT; | 505 | spec_flgs |= FREE_FIRST_ARGV_IS_OPT; |
506 | #endif | ||
496 | } | 507 | } |
497 | } | 508 | } |
498 | 509 | ||
@@ -573,7 +584,7 @@ getopt32(char **argv, const char *applet_opts, ...) | |||
573 | } | 584 | } |
574 | } | 585 | } |
575 | 586 | ||
576 | #if (ENABLE_AR || ENABLE_TAR) && ENABLE_FEATURE_CLEAN_UP | 587 | #if ENABLE_FEATURE_CLEAN_UP |
577 | if (spec_flgs & FREE_FIRST_ARGV_IS_OPT) | 588 | if (spec_flgs & FREE_FIRST_ARGV_IS_OPT) |
578 | free(argv[1]); | 589 | free(argv[1]); |
579 | #endif | 590 | #endif |