[ofw] etc\getopt.c patch

Smith, Stan stan.smith at intel.com
Thu Jul 16 13:57:39 PDT 2009


Correctly process a cmd-line switch with nonexistent 'optional' argument as the last token on a command line; 'ndinstall -i'.

--- C:/Documents and Settings/scsmith/Local Settings/Temp/getopt.c-revBASE.svn000.tmp.c Thu Jul 16 13:46:09 2009
+++ C:/Documents and Settings/scsmith/My Documents/openIB-windows/SVN/gen1/branches/WOF2-1/etc/user/getopt.c    Thu Jul 16 13:43:46 2009
@@ -69,14 +69,22 @@
                goto out;
        }

+       /* process switch argument */
        if (argv[optind][2] != '\0') {
                optarg = &argv[optind][2];
                goto out;
        }

        /* switch argument is optional (::) - be careful */
-       if (loc[2] == ':' && (argv[optind+1] && argv[optind+1][0] == '-'))
-               goto out;
+       if (loc[2] == ':' ) {
+               if ((argv[optind+1] == NULL)) {
+                       /* handle EOL without optional arg */
+                       optarg = NULL;
+                       goto out;
+               }
+               if (argv[optind+1] && argv[optind+1][0] == '-')
+                       goto out;
+       }

        optarg = argv[++optind];
        if (!optarg || !(*optarg)) {




More information about the ofw mailing list