From 488dd7086925b83bb36568965558221e04d2cc91 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 29 May 2011 04:24:13 +0200 Subject: fix !ENABLE_FEATURE_GETOPT_LONG build. Closes 3775 When compiling with !ENABLE_FEATURE_GETOPT_LONG, busybox still tries to include getopt.h which is not available; for example with uClibc when !UCLIBC_HAS_GETOPT_LONG. getopt.h is only required for the _long set of functions. Signed-off-by: Denys Vlasenko --- docs/style-guide.txt | 11 +++++------ libbb/getopt32.c | 4 +++- selinux/chcon.c | 1 - selinux/runcon.c | 1 - util-linux/getopt.c | 6 ++++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/style-guide.txt b/docs/style-guide.txt index fdf6cfe4d..10ed893dc 100644 --- a/docs/style-guide.txt +++ b/docs/style-guide.txt @@ -679,11 +679,10 @@ line in the midst of your #includes, if you need to parse long options: Then have long options defined: - static const struct option _long_options[] = { - { "list", 0, NULL, 't' }, - { "extract", 0, NULL, 'x' }, - { NULL, 0, NULL, 0 } - }; + static const char _longopts[] ALIGN1 = + "list\0" No_argument "t" + "extract\0" No_argument "x" + ; And a code block similar to the following near the top of your applet_main() routine: @@ -691,7 +690,7 @@ routine: char *str_b; opt_complementary = "cryptic_string"; - applet_long_options = _long_options; /* if you have them */ + applet_long_options = _longopts; /* if you have them */ opt = getopt32(argc, argv, "ab:c", &str_b); if (opt & 1) { handle_option_a(); diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 18f33c704..c7c4079c2 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -7,7 +7,9 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -#include +#if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG +# include +#endif #include "libbb.h" /* Documentation diff --git a/selinux/chcon.c b/selinux/chcon.c index 8644502b5..88d0cfec6 100644 --- a/selinux/chcon.c +++ b/selinux/chcon.c @@ -40,7 +40,6 @@ //usage: "\n -R Recurse" //usage: ) -#include #include #include "libbb.h" diff --git a/selinux/runcon.c b/selinux/runcon.c index f0b21269f..3183a2274 100644 --- a/selinux/runcon.c +++ b/selinux/runcon.c @@ -50,7 +50,6 @@ //usage: "\n -l RNG Levelrange" //usage: ) -#include #include #include diff --git a/util-linux/getopt.c b/util-linux/getopt.c index 10e1dc49b..85ff76189 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c @@ -25,7 +25,7 @@ * Added NLS support (partly written by Arkadiusz Mickiewicz * ) * Ported to Busybox - Alfred M. Szmidt - * Removed --version/-V and --help/-h in + * Removed --version/-V and --help/-h * Removed parse_error(), using bb_error_msg() from Busybox instead * Replaced our_malloc with xmalloc and our_realloc with xrealloc * @@ -79,7 +79,9 @@ //usage: " esac\n" //usage: "done\n" -#include +#if ENABLE_FEATURE_GETOPT_LONG +# include +#endif #include "libbb.h" /* NON_OPT is the code that is returned when a non-option is found in '+' -- cgit v1.2.3