aboutsummaryrefslogtreecommitdiffstats
path: root/toolchain/musl/patches/120-getopt_non-option-arguments_fix.patch
diff options
context:
space:
mode:
authorJohn Crispin <john@openwrt.org>2014-11-19 09:21:02 +0000
committerJohn Crispin <john@openwrt.org>2014-11-19 09:21:02 +0000
commitd49f9039f78c808a3cc28ece28a1b18f173a944d (patch)
tree1b7b3394145626d2f199128b2babb7ecafd28273 /toolchain/musl/patches/120-getopt_non-option-arguments_fix.patch
parentbd164f233caf0910e93396142be595d9572be07f (diff)
downloadupstream-d49f9039f78c808a3cc28ece28a1b18f173a944d.tar.gz
upstream-d49f9039f78c808a3cc28ece28a1b18f173a944d.tar.bz2
upstream-d49f9039f78c808a3cc28ece28a1b18f173a944d.zip
musl: add getopt support for non-option arguments
musl libc doesn't support the GNU getopt extension to parse non-option arguments when the optstring starts with '-'. This extension is used by some utilities, notably iptables, that currently return with errors even with perfectly valid invocations. The patch adds the code needed by getopt.c and getopt_long.c to implement that extension. Signed-off-by: Gianluca Anzolin <gianluca@sottospazio.it> SVN-Revision: 43309
Diffstat (limited to 'toolchain/musl/patches/120-getopt_non-option-arguments_fix.patch')
-rw-r--r--toolchain/musl/patches/120-getopt_non-option-arguments_fix.patch43
1 files changed, 43 insertions, 0 deletions
diff --git a/toolchain/musl/patches/120-getopt_non-option-arguments_fix.patch b/toolchain/musl/patches/120-getopt_non-option-arguments_fix.patch
new file mode 100644
index 0000000000..3cd909da46
--- /dev/null
+++ b/toolchain/musl/patches/120-getopt_non-option-arguments_fix.patch
@@ -0,0 +1,43 @@
+--- a/src/misc/getopt.c
++++ b/src/misc/getopt.c
+@@ -24,8 +24,23 @@ int getopt(int argc, char * const argv[]
+ optind = 1;
+ }
+
+- if (optind >= argc || !argv[optind] || argv[optind][0] != '-' || !argv[optind][1])
++ if (optind >= argc || !argv[optind])
+ return -1;
++
++ if (argv[optind][0] != '-') {
++ /* GNU extension */
++ if (optstring[0] == '-') {
++ optarg = argv[optind];
++ optind++;
++ return 1;
++ }
++
++ return -1;
++ }
++
++ if (!argv[optind][1])
++ return -1;
++
+ if (argv[optind][1] == '-' && !argv[optind][2])
+ return optind++, -1;
+
+--- a/src/misc/getopt_long.c
++++ b/src/misc/getopt_long.c
+@@ -12,7 +12,12 @@ static int __getopt_long(int argc, char
+ __optpos = 0;
+ optind = 1;
+ }
+- if (optind >= argc || !argv[optind] || argv[optind][0] != '-') return -1;
++ if (optind >= argc || !argv[optind])
++ return -1;
++
++ if (argv[optind][0] != '-')
++ return getopt(argc, argv, optstring);
++
+ if ((longonly && argv[optind][1]) ||
+ (argv[optind][1] == '-' && argv[optind][2]))
+ {