aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0009-getopt-fix-optional-argument-processing.patch
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-12-04 10:43:32 +0200
committerTimo Teräs <timo.teras@iki.fi>2014-12-04 10:44:14 +0200
commit8f2469e413757e12582b651b24f49b0fb0072a34 (patch)
treefa5a536a6d34dbce3b62881ec6041d5c48a5ef7a /main/musl/0009-getopt-fix-optional-argument-processing.patch
parent7086cc9b981d724f4b530ba21a844b602d947d7c (diff)
downloadaports-8f2469e413757e12582b651b24f49b0fb0072a34.tar.bz2
aports-8f2469e413757e12582b651b24f49b0fb0072a34.tar.xz
main/musl: cherry-pick fixes and compatibility improvements from upstream
Diffstat (limited to 'main/musl/0009-getopt-fix-optional-argument-processing.patch')
-rw-r--r--main/musl/0009-getopt-fix-optional-argument-processing.patch38
1 files changed, 38 insertions, 0 deletions
diff --git a/main/musl/0009-getopt-fix-optional-argument-processing.patch b/main/musl/0009-getopt-fix-optional-argument-processing.patch
new file mode 100644
index 0000000000..e486d0c5d0
--- /dev/null
+++ b/main/musl/0009-getopt-fix-optional-argument-processing.patch
@@ -0,0 +1,38 @@
+From acccc93e084641861ca553317edb7da7791833b5 Mon Sep 17 00:00:00 2001
+From: Felix Fietkau <nbd@openwrt.org>
+Date: Tue, 21 Oct 2014 22:24:50 +0200
+Subject: [PATCH] getopt: fix optional argument processing
+
+Processing an option character with optional argument fails if the
+option is last on the command line. This happens because the
+if (optind >= argc) check runs first before testing for optional
+argument.
+---
+ src/misc/getopt.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/misc/getopt.c b/src/misc/getopt.c
+index 8a2e4d5..f94c4f7 100644
+--- a/src/misc/getopt.c
++++ b/src/misc/getopt.c
+@@ -55,7 +55,8 @@ int getopt(int argc, char * const argv[], const char *optstring)
+ return '?';
+ }
+ if (optstring[i+1] == ':') {
+- if (optind >= argc) {
++ if (optstring[i+2] == ':') optarg = 0;
++ else if (optind >= argc) {
+ if (optstring[0] == ':') return ':';
+ if (opterr) {
+ write(2, argv[0], strlen(argv[0]));
+@@ -65,7 +66,6 @@ int getopt(int argc, char * const argv[], const char *optstring)
+ }
+ return '?';
+ }
+- if (optstring[i+2] == ':') optarg = 0;
+ if (optstring[i+2] != ':' || optpos) {
+ optarg = argv[optind++] + optpos;
+ optpos = 0;
+--
+2.2.0
+