eal/windows: fix C++ compatibility
[dpdk.git] / lib / librte_eal / windows / getopt.c
index 170c9b5..a1f51c6 100644 (file)
@@ -25,8 +25,8 @@ int   opterr = 1;             /* if error message should be printed */
 int    optind = 1;             /* index into parent argv vector */
 int    optopt = '?';           /* character checked for validity */
 
-static void pass(void) {}
-#define warnx(a, ...) pass()
+static void pass(const char *a) {(void) a; }
+#define warnx(a, ...) pass(a)
 
 #define PRINT_ERROR    ((opterr) && (*options != ':'))
 
@@ -242,7 +242,6 @@ getopt_internal(int nargc, char **nargv, const char *options,
        char *oli;                              /* option letter list index */
        int optchar, short_too;
        static int posixly_correct = -1;
-       char *buf;
        size_t len;
        int optreset = 0;
 
@@ -253,16 +252,16 @@ getopt_internal(int nargc, char **nargv, const char *options,
         * Disable GNU extensions if POSIXLY_CORRECT is set or options
         * string begins with a '+'.
         */
-       if (posixly_correct == -1)
-               posixly_correct = _dupenv_s(&buf, &len, "POSIXLY_CORRECT");
+       if (posixly_correct == -1) {
+               errno_t err = _wgetenv_s(&len, NULL, 0, L"POSIXLY_CORRECT");
+               posixly_correct = (err == 0) && (len > 0);
+       }
        if (!posixly_correct || *options == '+')
                flags &= ~FLAG_PERMUTE;
        else if (*options == '-')
                flags |= FLAG_ALLARGS;
        if (*options == '+' || *options == '-')
                options++;
-       if (!posixly_correct)
-               free(buf);
        /*
         * reset if requested
         */