tree-wide: reset optind to 0 when GNU extensions in optstring are used

Otherwise, if getopt() and friends are used before parse_argv(), then
the GNU extensions may be ignored.

This should not change any behavior at least now, as we usually use
getopt_long() only once per invocation. But in the next commit,
getopt_long() will be used for other arrays, hence this change will
become necessary.
This commit is contained in:
Yu Watanabe
2023-03-29 10:34:41 +09:00
parent dd2d3e975e
commit ef9c12b157
12 changed files with 40 additions and 0 deletions
+4
View File
@@ -1150,6 +1150,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_services = l;
}
/* Resetting to 0 forces the invocation of an internal initialization routine of getopt_long()
* that checks for GNU extensions in optstring ('-' or '+' at the beginning). */
optind = 0;
for (;;) {
int c;