diff options
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 |