Browse Source

Avoid calling getopt_long again after it returns -1

On GNU, calling getopt_long again will reset optind back to the first
non-option argument, which would cause an infinite loop of reading the
same configurtion file forever.
master
Causal Agent 5 days ago
parent
commit
ca22cbfab6
Signed by: C. McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 4 additions and 1 deletions
  1. 4
    1
      config.c

+ 4
- 1
config.c View File

@@ -42,7 +42,10 @@ int getopt_config(
int argc, char *const *argv,
const char *optstring, const struct option *longopts, int *longindex
) {
int opt = getopt_long(argc, argv, optstring, longopts, longindex);
static int opt;
if (opt >= 0) {
opt = getopt_long(argc, argv, optstring, longopts, longindex);
}
if (opt >= 0) return opt;

for (;;) {

Loading…
Cancel
Save