options/glibc: Impl. long opts with optional args

This commit is contained in:
Alexander van der Grinten 2021-01-16 12:24:08 +01:00
parent bbd2ca1e91
commit ddf5d1c2a2

View file

@ -76,6 +76,16 @@ int getopt_long(int argc, char * const argv[], const char *optstring,
fprintf(stderr, "--%s requires an argument.\n", arg);
return '?';
}
}else if(longopts[k].has_arg == optional_argument) {
if(s) {
// Consume the long option and its argument.
optarg = s + 1;
optind++;
}else{
// Consume the long option.
optarg = nullptr;
optind++;
}
}else{
__ensure(longopts[k].has_arg == no_argument);