Index: getopt.c =================================================================== RCS file: /cvs/src/src/winsup/mingw/mingwex/getopt.c,v retrieving revision 1.2 diff -u -p -r1.2 getopt.c --- getopt.c 3 Mar 2003 10:27:57 -0000 1.2 +++ getopt.c 15 Dec 2003 07:57:58 -0000 @@ -69,15 +69,18 @@ __weak_alias(getopt_long,_getopt_long) extern char __declspec(dllimport) *__progname; #endif +static int using_long; + #define IGNORE_FIRST (*options == '-' || *options == '+') #define PRINT_ERROR ((opterr) && ((*options != ':') \ || (IGNORE_FIRST && options[1] != ':'))) -#define IS_POSIXLY_CORRECT (getenv("POSIXLY_INCORRECT_GETOPT") == NULL) +#define IS_POSIXLY_CORRECT (using_long ? (getenv("POSIXLY_CORRECT") != NULL) : \ + (getenv("POSIXLY_INCORRECT_GETOPT") == NULL)) #define PERMUTE (!IS_POSIXLY_CORRECT && !IGNORE_FIRST) -/* XXX: GNU ignores PC if *options == '-' */ -#define IN_ORDER (!IS_POSIXLY_CORRECT && *options == '-') +/* XXX: GNU ignores PC if *options == '-'; and now so do we */ +#define IN_ORDER (*options == '-') /* return values */ #define BADCH (int)'?' @@ -346,6 +349,8 @@ getopt(nargc, nargv, options) _DIAGASSERT(nargv != NULL); _DIAGASSERT(options != NULL); + using_long = 0; + if ((retval = getopt_internal(nargc, nargv, options)) == -2) { ++optind; /* @@ -382,6 +387,8 @@ getopt_long(nargc, nargv, options, long_ _DIAGASSERT(options != NULL); _DIAGASSERT(long_options != NULL); /* idx may be NULL */ + + using_long = 1; if ((retval = getopt_internal(nargc, nargv, options)) == -2) { char *current_argv, *has_equal;