[ETC] process nonexistent optional switch arg @ EOL. signed off by stan.smith@intel.com
authorstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 16 Jul 2009 22:51:26 +0000 (22:51 +0000)
committerstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 16 Jul 2009 22:51:26 +0000 (22:51 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2303 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

etc/user/getopt.c

index 9e05699..af9230c 100644 (file)
@@ -69,14 +69,22 @@ int getopt(int argc, char * const argv[], char const *opts)
                goto out;\r
        }\r
 \r
+       /* process switch argument */\r
        if (argv[optind][2] != '\0') {\r
                optarg = &argv[optind][2];\r
                goto out;\r
        }\r
 \r
        /* switch argument is optional (::) - be careful */\r
-       if (loc[2] == ':' && (argv[optind+1] && argv[optind+1][0] == '-'))\r
-               goto out;\r
+       if (loc[2] == ':' ) {\r
+               if ((argv[optind+1] == NULL)) {\r
+                       /* handle EOL without optional arg */\r
+                       optarg = NULL;\r
+                       goto out;\r
+               }\r
+               if (argv[optind+1] && argv[optind+1][0] == '-')\r
+                       goto out;\r
+       }\r
  \r
        optarg = argv[++optind];\r
        if (!optarg || !(*optarg)) {\r