aboutsummaryrefslogtreecommitdiffstats
path: root/toolchain/musl/patches/120-getopt_non-option-arguments_fix.patch
blob: 3cd909da46c3908b8a3e13e7f5de3b97664fd739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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]))
 	{