diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-23 17:40:35 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-23 17:40:35 +0000 |
| commit | 5bfcb4d5ae716befe06a1f8801551ae09a144e91 (patch) | |
| tree | 3d39a2c528dcc1707a90a4beb878166281d2ff6a /libbb | |
| parent | bdc88fdc6844ee6890e31ba4cf56800becc8c682 (diff) | |
| download | busybox-w32-5bfcb4d5ae716befe06a1f8801551ae09a144e91.tar.gz busybox-w32-5bfcb4d5ae716befe06a1f8801551ae09a144e91.tar.bz2 busybox-w32-5bfcb4d5ae716befe06a1f8801551ae09a144e91.zip | |
getopt32 must remain NOFORK-safe (no mallocs!). Using alloca and pretending
stack is infinite. Unfortunately, +79 bytes.
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/getopt32.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index e5d97e98c..25eb113df 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
| @@ -307,7 +307,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
| 307 | va_list p; | 307 | va_list p; |
| 308 | #if ENABLE_GETOPT_LONG | 308 | #if ENABLE_GETOPT_LONG |
| 309 | const struct option *l_o; | 309 | const struct option *l_o; |
| 310 | struct option *long_options = NULL; | 310 | struct option *long_options = (struct option *) &bb_null_long_options; |
| 311 | #endif | 311 | #endif |
| 312 | unsigned trigger; | 312 | unsigned trigger; |
| 313 | char **pargv = NULL; | 313 | char **pargv = NULL; |
| @@ -350,11 +350,11 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
| 350 | count = 1; | 350 | count = 1; |
| 351 | optstr = applet_long_options; | 351 | optstr = applet_long_options; |
| 352 | while (optstr[0]) { | 352 | while (optstr[0]) { |
| 353 | optstr += strlen(optstr) + 3; /* skip \0, has_arg, val */ | 353 | optstr += strlen(optstr) + 3; /* skip NUL, has_arg, val */ |
| 354 | count++; | 354 | count++; |
| 355 | } | 355 | } |
| 356 | /* count == no. of longopts + 1 */ | 356 | /* count == no. of longopts + 1 */ |
| 357 | long_options = xzalloc(count * sizeof(*long_options)); | 357 | long_options = alloca(count * sizeof(*long_options)); |
| 358 | i = 0; | 358 | i = 0; |
| 359 | optstr = applet_long_options; | 359 | optstr = applet_long_options; |
| 360 | while (--count) { | 360 | while (--count) { |
| @@ -476,7 +476,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
| 476 | * (supposed to act as --header, but doesn't) */ | 476 | * (supposed to act as --header, but doesn't) */ |
| 477 | #if ENABLE_GETOPT_LONG | 477 | #if ENABLE_GETOPT_LONG |
| 478 | while ((c = getopt_long(argc, argv, applet_opts, | 478 | while ((c = getopt_long(argc, argv, applet_opts, |
| 479 | long_options ? long_options : bb_null_long_options, NULL)) != -1) { | 479 | long_options, NULL)) != -1) { |
| 480 | #else | 480 | #else |
| 481 | while ((c = getopt(argc, argv, applet_opts)) != -1) { | 481 | while ((c = getopt(argc, argv, applet_opts)) != -1) { |
| 482 | #endif | 482 | #endif |
| @@ -535,9 +535,6 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
| 535 | if (argc < min_arg || (max_arg >= 0 && argc > max_arg)) | 535 | if (argc < min_arg || (max_arg >= 0 && argc > max_arg)) |
| 536 | bb_show_usage(); | 536 | bb_show_usage(); |
| 537 | 537 | ||
| 538 | #if ENABLE_GETOPT_LONG | ||
| 539 | free(long_options); | ||
| 540 | #endif | ||
| 541 | option_mask32 = flags; | 538 | option_mask32 = flags; |
| 542 | return flags; | 539 | return flags; |
| 543 | } | 540 | } |
