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.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/misc/getopt.c b/src/misc/getopt.c
index f94c4f70..a698c8d4 100644
--- a/src/misc/getopt.c
+++ b/src/misc/getopt.c
@@ -24,8 +24,20 @@ int getopt(int argc, char * const argv[], const char *optstring)
 		optind = 1;
 	}
 
-	if (optind >= argc || !argv[optind] || argv[optind][0] != '-' || !argv[optind][1])
+	if (optind >= argc || !argv[optind])
 		return -1;
+
+	if (argv[optind][0] != '-') {
+		if (optstring[0] == '-') {
+			optarg = argv[optind++];
+			return 1;
+		}
+		return -1;
+	}
+
+	if (!argv[optind][1])
+		return -1;
+
 	if (argv[optind][1] == '-' && !argv[optind][2])
 		return optind++, -1;
 
@@ -43,6 +55,9 @@ int getopt(int argc, char * const argv[], const char *optstring)
 		optpos = 0;
 	}
 
+	if (optstring[0] == '-')
+		optstring++;
+
 	for (i=0; (l = mbtowc(&d, optstring+i, MB_LEN_MAX)) && d!=c; i+=l>0?l:1);
 
 	if (d != c) {