The API is available since Windows XP and available in UWP for win8 and win10.

This avoids relying on getenv() from winstorecompat that returns NULL and can't
be reimplemented in a clean way.
---
 mingw-w64-crt/misc/getopt.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-crt/misc/getopt.c b/mingw-w64-crt/misc/getopt.c
index ac1fda42..c3357e6c 100644
--- a/mingw-w64-crt/misc/getopt.c
+++ b/mingw-w64-crt/misc/getopt.c
@@ -344,8 +344,11 @@ getopt_internal(int nargc, char * const *nargv, const char 
*options,
         * CV, 2009-12-14: Check POSIXLY_CORRECT anew if optind == 0 or
         *                 optreset != 0 for GNU compatibility.
         */
-       if (posixly_correct == -1 || optreset != 0)
-               posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
+       if (posixly_correct == -1 || optreset != 0) {
+               char dummy[2];
+               DWORD res = GetEnvironmentVariableA("POSIXLY_CORRECT", dummy, 
2);
+               posixly_correct = res != 0 || GetLastError() != 
ERROR_ENVVAR_NOT_FOUND;
+       }
        if (*options == '-')
                flags |= FLAG_ALLARGS;
        else if (posixly_correct || *options == '+')
-- 
2.17.1



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to