about summary refs log tree commit diff
path: root/src/misc/getopt_long.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/getopt_long.c')
-rw-r--r--src/misc/getopt_long.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
index c6e14625..568ae7ba 100644
--- a/src/misc/getopt_long.c
+++ b/src/misc/getopt_long.c
@@ -75,9 +75,9 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
 		if (cnt==1) {
 			i = match;
 			optind++;
-			optopt = longopts[i].val;
 			if (*opt == '=') {
 				if (!longopts[i].has_arg) {
+					optopt = longopts[i].val;
 					if (colon || !opterr)
 						return '?';
 					__getopt_msg(argv[0],
@@ -89,6 +89,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
 				optarg = opt+1;
 			} else if (longopts[i].has_arg == required_argument) {
 				if (!(optarg = argv[optind])) {
+					optopt = longopts[i].val;
 					if (colon) return ':';
 					if (!opterr) return '?';
 					__getopt_msg(argv[0],
@@ -107,6 +108,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
 			return longopts[i].val;
 		}
 		if (argv[optind][1] == '-') {
+			optopt = 0;
 			if (!colon && opterr)
 				__getopt_msg(argv[0], cnt ?
 					": option is ambiguous: " :