flac and metaflac : Don't always call setlocale() in Windows.
authorErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 19 Jul 2014 08:17:25 +0000 (18:17 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 19 Jul 2014 08:17:28 +0000 (18:17 +1000)
Windows (MSVC, MinGW) versions of setlocale don't care about LC_*
environment variables. For example, flac cannot pass the test for
--until and --skip options the script calls it with --skip=0:01.1001
and it expects decimal comma (--skip=0:01,1001) on some locales.

Solve this (on Windows) by calling setlocale(LC_ALL, "") if some
LC_* variable is set to "C".

Patch-from: lvqcl <lvqcl.mail@gmail.com>

src/flac/main.c
src/metaflac/main.c

index 4abc192..40f5220 100644 (file)
@@ -310,7 +310,20 @@ int main(int argc, char *argv[])
 #endif
 
        srand((unsigned)time(0));
+#ifdef _WIN32
+       {
+               const char *var;
+               var = getenv("LC_ALL");
+               if (!var)
+                       var = getenv("LC_NUMERIC");
+               if (!var)
+                       var = getenv("LANG");
+               if (!var || strcmp(var, "C") != 0)
+                       setlocale(LC_ALL, "");
+       }
+#else
        setlocale(LC_ALL, "");
+#endif
        if(!init_options()) {
                flac__utils_printf(stderr, 1, "ERROR: allocating memory\n");
                retval = 1;
index 2e28a88..8b99369 100644 (file)
@@ -43,7 +43,20 @@ int main(int argc, char *argv[])
        }
 #endif
 
+#ifdef _WIN32
+       {
+               const char *var;
+               var = getenv("LC_ALL");
+               if (!var)
+                       var = getenv("LC_NUMERIC");
+               if (!var)
+                       var = getenv("LANG");
+               if (!var || strcmp(var, "C") != 0)
+                       setlocale(LC_ALL, "");
+       }
+#else
        setlocale(LC_ALL, "");
+#endif
        init_options(&options);
 
        if ((ret = parse_options(argc, argv, &options)) == 0)