crt: Fix mingw-w64 getenv_s() emulation for case when the variable name is NULL

This special case does not throw an exception from invalid parameter handler.

Co-authored-by: LIU Hao <lh_mouse@126.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/secapi/getenv_s.c b/mingw-w64-crt/secapi/getenv_s.c
index b273183..07ea3ac 100644
--- a/mingw-w64-crt/secapi/getenv_s.c
+++ b/mingw-w64-crt/secapi/getenv_s.c
@@ -23,15 +23,16 @@
         return errno = EINVAL;
     }
 
+    /* After passing parameter validation, the errno is not changed. */
+
     if (!varName) {
         *pReturnValue = 0;
         if (dstBuf)
             dstBuf[0] = '\0';
-        return errno = EINVAL;
+        /* UCRT `getenv_s()` reports success in this case. */
+        return 0;
     }
 
-    /* After passing parameter validation, the errno is not changed. */
-
     value = getenv(varName);
     if (!value) {
         *pReturnValue = 0;
diff --git a/mingw-w64-libraries/winstorecompat/src/getenv_s.c b/mingw-w64-libraries/winstorecompat/src/getenv_s.c
index f25dad3..93db31b 100644
--- a/mingw-w64-libraries/winstorecompat/src/getenv_s.c
+++ b/mingw-w64-libraries/winstorecompat/src/getenv_s.c
@@ -24,15 +24,16 @@
         return errno = EINVAL;
     }
 
+    /* After passing parameter validation, the errno is not changed. */
+
     if (!varName) {
         *pReturnValue = 0;
         if (dstBuf)
             dstBuf[0] = '\0';
-        return errno = EINVAL;
+        /* UCRT `getenv_s()` reports success in this case. */
+        return 0;
     }
 
-    /* After passing parameter validation, the errno is not changed. */
-
     /*
      * Function GetEnvironmentVariableA() is documented on:
      * https://learn.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea