accept null longopts pointer in getopt_long
authorRich Felker <dalias@aerifal.cx>
Thu, 11 Dec 2014 06:07:02 +0000 (01:07 -0500)
committerRich Felker <dalias@aerifal.cx>
Thu, 11 Dec 2014 06:07:02 +0000 (01:07 -0500)
this is an undocumented feature of GNU getopt_long that the BSD
version also mimics, and is reportedly needed by some programs.

src/misc/getopt_long.c

index 469ee92..c3cf7f9 100644 (file)
@@ -52,7 +52,7 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con
 static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
 {
 
-       if (argv[optind][0] == '-' &&
+       if (longopts && argv[optind][0] == '-' &&
                ((longonly && argv[optind][1]) ||
                 (argv[optind][1] == '-' && argv[optind][2])))
        {