summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/misc/getopt_long.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
index 008b747c..ddcef949 100644
--- a/src/misc/getopt_long.c
+++ b/src/misc/getopt_long.c
@@ -1,5 +1,7 @@
#define _GNU_SOURCE
#include <stddef.h>
+#include <stdlib.h>
+#include <limits.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
@@ -58,10 +60,10 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
{
int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':';
int i, cnt, match;
- char *arg, *opt;
+ char *arg, *opt, *start = argv[optind]+1;
for (cnt=i=0; longopts[i].name; i++) {
const char *name = longopts[i].name;
- opt = argv[optind]+1;
+ opt = start;
if (*opt == '-') opt++;
while (*opt && *opt != '=' && *opt == *name)
name++, opt++;
@@ -74,6 +76,17 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
}
cnt++;
}
+ if (cnt==1 && longonly && arg-start == mblen(start, MB_LEN_MAX)) {
+ int l = arg-start;
+ for (i=0; optstring[i]; i++) {
+ int j;
+ for (j=0; j<l && start[j]==optstring[i+j]; j++);
+ if (j==l) {
+ cnt++;
+ break;
+ }
+ }
+ }
if (cnt==1) {
i = match;
opt = arg;