mingw-runtime-3.15: regression in getopt() optind ?

Christian Franke Christian.Franke@t-online.de
Wed Oct 1 21:06:00 GMT 2008


Chris Sutcliffe wrote:
> I've made a new version of the mingw-runtime available for download.
> For a list of changes see:
>
> http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/mingw/ChangeLog?rev=1.409&cvsroot=src
>
> New features in release 3.15
> ============================
> ...
> * A replacement implementation for the getopt() family of functions,
>  adding support for the GNU getopt_long_only() function. ...
>   


This new getopt() sets optind to the index of the current option instead 
of the next option.

Testcase:

#include <stdio.h>
#include <getopt.h>

int main(int argc, char **argv)
{
  int opt;
  while ((opt = getopt(argc, argv, "ab:c")) != -1)
    printf("opt=%c, optind=%d\n", opt, optind);
  printf("end    optind=%d\n", optind);
  return 0;
}


Output for "./prog -a -b arg -c":

- mingw-runtime-3.14, Cygwin, GNU getopt:
opt=a, optind=2
opt=b, optind=4
opt=c, optind=5
end    optind=5

- mingw-runtime-3.15:
opt=a, optind=1
opt=b, optind=2
opt=c, optind=4
end    optind=5

The new behavior violates this POSIX requirement:
"The variable optind is the index of the next element of the argv[] 
vector to be processed."
http://www.opengroup.org/onlinepubs/009695399/functions/getopt.html


-- 
Christian Franke


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list