musl: merge changes from git, includes further getopt fixes
[openwrt/openwrt.git] / toolchain / musl / patches / 001-revert-getopt-change.patch
1 commit 84d8240bb5c487034ea3fb674a1de6d884df18aa
2 Author: Felix Fietkau <nbd@openwrt.org>
3 Date: Sun Jan 11 19:16:32 2015 +0100
4
5 Revert "add error message printing to getopt_long and make related improvements"
6
7 This reverts commit 91184c4f16b143107fa9935edebe5d2b20bd70d8.
8
9 diff --git a/src/misc/getopt.c b/src/misc/getopt.c
10 index 9217983..9db5eaa 100644
11 --- a/src/misc/getopt.c
12 +++ b/src/misc/getopt.c
13 @@ -12,7 +12,7 @@ int optind=1, opterr=1, optopt, __optpos, __optreset=0;
14 #define optpos __optpos
15 weak_alias(__optreset, optreset);
16
17 -void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
18 +void __getopt_msg(const char *a, const char *b, const char *c, int l)
19 {
20 FILE *f = stderr;
21 b = __lctrans_cur(b);
22 @@ -80,7 +80,7 @@ int getopt(int argc, char * const argv[], const char *optstring)
23
24 if (d != c) {
25 if (optstring[0] != ':' && opterr)
26 - __getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
27 + __getopt_msg(argv[0], ": illegal option: ", optchar, k);
28 return '?';
29 }
30 if (optstring[i] == ':') {
31 diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
32 index e5a4a75..e245ab9 100644
33 --- a/src/misc/getopt_long.c
34 +++ b/src/misc/getopt_long.c
35 @@ -2,7 +2,6 @@
36 #include <stddef.h>
37 #include <getopt.h>
38 #include <stdio.h>
39 -#include <string.h>
40
41 extern int __optpos, __optreset;
42
43 @@ -16,14 +15,11 @@ static void permute(char *const *argv, int dest, int src)
44 av[dest] = tmp;
45 }
46
47 -void __getopt_msg(const char *, const char *, const char *, size_t);
48 -
49 static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
50
51 static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
52 {
53 int ret, skipped, resumed;
54 - const char *optstring2 = optstring + 1;
55 if (!optind || __optreset) {
56 __optreset = 0;
57 __optpos = 0;
58 @@ -38,10 +34,9 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con
59 if (argv[i][0] == '-' && argv[i][1]) break;
60 }
61 optind = i;
62 - optstring2 = optstring;
63 }
64 resumed = optind;
65 - ret = __getopt_long_core(argc, argv, optstring2, longopts, idx, longonly);
66 + ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
67 if (resumed > skipped) {
68 int i, cnt = optind-resumed;
69 for (i=0; i<cnt; i++)
70 @@ -78,27 +73,12 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
71 optind++;
72 optopt = longopts[i].val;
73 if (*opt == '=') {
74 - if (!longopts[i].has_arg) {
75 - if (optstring[0] == ':' || !opterr)
76 - return '?';
77 - __getopt_msg(argv[0],
78 - ": option does not take an argument: ",
79 - longopts[i].name,
80 - strlen(longopts[i].name));
81 - return '?';
82 - }
83 + if (!longopts[i].has_arg) return '?';
84 optarg = opt+1;
85 } else {
86 if (longopts[i].has_arg == required_argument) {
87 - if (!(optarg = argv[optind])) {
88 - if (optstring[0] == ':' || !opterr)
89 - return ':';
90 - __getopt_msg(argv[0],
91 - ": option requires an argument: ",
92 - longopts[i].name,
93 - strlen(longopts[i].name));
94 - return '?';
95 - }
96 + if (!(optarg = argv[optind]))
97 + return ':';
98 optind++;
99 } else optarg = NULL;
100 }
101 @@ -110,12 +90,6 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
102 return longopts[i].val;
103 }
104 if (argv[optind][1] == '-') {
105 - if (optstring[0] != ':' && opterr)
106 - __getopt_msg(argv[0], cnt ?
107 - ": option is ambiguous: " :
108 - ": unrecognized option: ",
109 - argv[optind]+2,
110 - strlen(argv[optind]+2));
111 optind++;
112 return '?';
113 }