1 commit 84d8240bb5c487034ea3fb674a1de6d884df18aa
2 Author: Felix Fietkau <nbd@openwrt.org>
3 Date: Sun Jan 11 19:16:32 2015 +0100
5 Revert "add error message printing to getopt_long and make related improvements"
7 This reverts commit 91184c4f16b143107fa9935edebe5d2b20bd70d8.
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);
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)
22 @@ -80,7 +80,7 @@ int getopt(int argc, char * const argv[], const char *optstring)
25 if (optstring[0] != ':' && opterr)
26 - __getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
27 + __getopt_msg(argv[0], ": illegal option: ", optchar, k);
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
41 extern int __optpos, __optreset;
43 @@ -16,14 +15,11 @@ static void permute(char *const *argv, int dest, int src)
47 -void __getopt_msg(const char *, const char *, const char *, size_t);
49 static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
51 static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
53 int ret, skipped, resumed;
54 - const char *optstring2 = optstring + 1;
55 if (!optind || __optreset) {
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;
62 - optstring2 = optstring;
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;
70 @@ -78,27 +73,12 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
72 optopt = longopts[i].val;
74 - if (!longopts[i].has_arg) {
75 - if (optstring[0] == ':' || !opterr)
77 - __getopt_msg(argv[0],
78 - ": option does not take an argument: ",
80 - strlen(longopts[i].name));
83 + if (!longopts[i].has_arg) return '?';
86 if (longopts[i].has_arg == required_argument) {
87 - if (!(optarg = argv[optind])) {
88 - if (optstring[0] == ':' || !opterr)
90 - __getopt_msg(argv[0],
91 - ": option requires an argument: ",
93 - strlen(longopts[i].name));
96 + if (!(optarg = argv[optind]))
101 @@ -110,12 +90,6 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
102 return longopts[i].val;
104 if (argv[optind][1] == '-') {
105 - if (optstring[0] != ':' && opterr)
106 - __getopt_msg(argv[0], cnt ?
107 - ": option is ambiguous: " :
108 - ": unrecognized option: ",
110 - strlen(argv[optind]+2));