about summary refs log tree commit diff
path: root/src/misc/getopt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/getopt.c')
-rw-r--r--src/misc/getopt.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/misc/getopt.c b/src/misc/getopt.c
index e921a60e..cd1f292f 100644
--- a/src/misc/getopt.c
+++ b/src/misc/getopt.c
@@ -84,8 +84,12 @@ int getopt(int argc, char * const argv[], const char *optstring)
 		return '?';
 	}
 	if (optstring[i] == ':') {
-		if (optstring[i+1] == ':') optarg = 0;
-		else if (optind >= argc) {
+		optarg = 0;
+		if (optstring[i+1] != ':' || optpos) {
+			optarg = argv[optind++] + optpos;
+			optpos = 0;
+		}
+		if (optind > argc) {
 			optopt = c;
 			if (optstring[0] == ':') return ':';
 			if (opterr) __getopt_msg(argv[0],
@@ -93,10 +97,6 @@ int getopt(int argc, char * const argv[], const char *optstring)
 				optchar, k);
 			return '?';
 		}
-		if (optstring[i+1] != ':' || optpos) {
-			optarg = argv[optind++] + optpos;
-			optpos = 0;
-		}
 	}
 	return c;
 }