mirror of https://github.com/hak5/openwrt-owl.git
musl: merge changes from git, includes further getopt fixes
Signed-off-by: Felix Fietkau <nbd@openwrt.org> SVN-Revision: 43939owl
parent
9db3df9d6b
commit
63176d7e1e
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,113 @@
|
||||||
|
commit 84d8240bb5c487034ea3fb674a1de6d884df18aa
|
||||||
|
Author: Felix Fietkau <nbd@openwrt.org>
|
||||||
|
Date: Sun Jan 11 19:16:32 2015 +0100
|
||||||
|
|
||||||
|
Revert "add error message printing to getopt_long and make related improvements"
|
||||||
|
|
||||||
|
This reverts commit 91184c4f16b143107fa9935edebe5d2b20bd70d8.
|
||||||
|
|
||||||
|
diff --git a/src/misc/getopt.c b/src/misc/getopt.c
|
||||||
|
index 9217983..9db5eaa 100644
|
||||||
|
--- a/src/misc/getopt.c
|
||||||
|
+++ b/src/misc/getopt.c
|
||||||
|
@@ -12,7 +12,7 @@ int optind=1, opterr=1, optopt, __optpos, __optreset=0;
|
||||||
|
#define optpos __optpos
|
||||||
|
weak_alias(__optreset, optreset);
|
||||||
|
|
||||||
|
-void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
|
||||||
|
+void __getopt_msg(const char *a, const char *b, const char *c, int l)
|
||||||
|
{
|
||||||
|
FILE *f = stderr;
|
||||||
|
b = __lctrans_cur(b);
|
||||||
|
@@ -80,7 +80,7 @@ int getopt(int argc, char * const argv[], const char *optstring)
|
||||||
|
|
||||||
|
if (d != c) {
|
||||||
|
if (optstring[0] != ':' && opterr)
|
||||||
|
- __getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
|
||||||
|
+ __getopt_msg(argv[0], ": illegal option: ", optchar, k);
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
if (optstring[i] == ':') {
|
||||||
|
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
|
||||||
|
index e5a4a75..e245ab9 100644
|
||||||
|
--- a/src/misc/getopt_long.c
|
||||||
|
+++ b/src/misc/getopt_long.c
|
||||||
|
@@ -2,7 +2,6 @@
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
-#include <string.h>
|
||||||
|
|
||||||
|
extern int __optpos, __optreset;
|
||||||
|
|
||||||
|
@@ -16,14 +15,11 @@ static void permute(char *const *argv, int dest, int src)
|
||||||
|
av[dest] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
-void __getopt_msg(const char *, const char *, const char *, size_t);
|
||||||
|
-
|
||||||
|
static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
|
||||||
|
|
||||||
|
static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||||
|
{
|
||||||
|
int ret, skipped, resumed;
|
||||||
|
- const char *optstring2 = optstring + 1;
|
||||||
|
if (!optind || __optreset) {
|
||||||
|
__optreset = 0;
|
||||||
|
__optpos = 0;
|
||||||
|
@@ -38,10 +34,9 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con
|
||||||
|
if (argv[i][0] == '-' && argv[i][1]) break;
|
||||||
|
}
|
||||||
|
optind = i;
|
||||||
|
- optstring2 = optstring;
|
||||||
|
}
|
||||||
|
resumed = optind;
|
||||||
|
- ret = __getopt_long_core(argc, argv, optstring2, longopts, idx, longonly);
|
||||||
|
+ ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
|
||||||
|
if (resumed > skipped) {
|
||||||
|
int i, cnt = optind-resumed;
|
||||||
|
for (i=0; i<cnt; i++)
|
||||||
|
@@ -78,27 +73,12 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
|
||||||
|
optind++;
|
||||||
|
optopt = longopts[i].val;
|
||||||
|
if (*opt == '=') {
|
||||||
|
- if (!longopts[i].has_arg) {
|
||||||
|
- if (optstring[0] == ':' || !opterr)
|
||||||
|
- return '?';
|
||||||
|
- __getopt_msg(argv[0],
|
||||||
|
- ": option does not take an argument: ",
|
||||||
|
- longopts[i].name,
|
||||||
|
- strlen(longopts[i].name));
|
||||||
|
- return '?';
|
||||||
|
- }
|
||||||
|
+ if (!longopts[i].has_arg) return '?';
|
||||||
|
optarg = opt+1;
|
||||||
|
} else {
|
||||||
|
if (longopts[i].has_arg == required_argument) {
|
||||||
|
- if (!(optarg = argv[optind])) {
|
||||||
|
- if (optstring[0] == ':' || !opterr)
|
||||||
|
- return ':';
|
||||||
|
- __getopt_msg(argv[0],
|
||||||
|
- ": option requires an argument: ",
|
||||||
|
- longopts[i].name,
|
||||||
|
- strlen(longopts[i].name));
|
||||||
|
- return '?';
|
||||||
|
- }
|
||||||
|
+ if (!(optarg = argv[optind]))
|
||||||
|
+ return ':';
|
||||||
|
optind++;
|
||||||
|
} else optarg = NULL;
|
||||||
|
}
|
||||||
|
@@ -110,12 +90,6 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
|
||||||
|
return longopts[i].val;
|
||||||
|
}
|
||||||
|
if (argv[optind][1] == '-') {
|
||||||
|
- if (optstring[0] != ':' && opterr)
|
||||||
|
- __getopt_msg(argv[0], cnt ?
|
||||||
|
- ": option is ambiguous: " :
|
||||||
|
- ": unrecognized option: ",
|
||||||
|
- argv[optind]+2,
|
||||||
|
- strlen(argv[optind]+2));
|
||||||
|
optind++;
|
||||||
|
return '?';
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
--- a/src/misc/getopt.c
|
|
||||||
+++ b/src/misc/getopt.c
|
|
||||||
@@ -55,7 +55,9 @@ int getopt(int argc, char * const argv[]
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
if (optstring[i+1] == ':') {
|
|
||||||
+ if (optstring[i+2] == ':') optarg = 0;
|
|
||||||
if (optind >= argc) {
|
|
||||||
+ if (optstring[i+2] == ':') return c;
|
|
||||||
if (optstring[0] == ':') return ':';
|
|
||||||
if (opterr) {
|
|
||||||
write(2, argv[0], strlen(argv[0]));
|
|
||||||
@@ -65,7 +67,6 @@ int getopt(int argc, char * const argv[]
|
|
||||||
}
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
- if (optstring[i+2] == ':') optarg = 0;
|
|
||||||
if (optstring[i+2] != ':' || optpos) {
|
|
||||||
optarg = argv[optind++] + optpos;
|
|
||||||
optpos = 0;
|
|
|
@ -1,43 +0,0 @@
|
||||||
--- 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]))
|
|
||||||
{
|
|
Loading…
Reference in New Issue