]> granicus.if.org Git - file/commitdiff
PR/518: Fall back to use setlocale() for the OS's that don't support
authorChristos Zoulas <christos@zoulas.com>
Wed, 10 Feb 2016 15:57:40 +0000 (15:57 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 10 Feb 2016 15:57:40 +0000 (15:57 +0000)
newlocale()/uselocale(). This is necessary because some regex patterns
we use (apple) have non-ascii characters in them.

src/file.h
src/funcs.c
src/readcdf.c

index 2b373473e8ce6f89dd01ffd79dbe150419256d0f..6e9067496726695470faccede9b4ad5c6a8591fa 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.175 2016/01/19 04:17:07 christos Exp $
+ * @(#)$File: file.h,v 1.176 2016/02/10 15:57:40 christos Exp $
  */
 
 #ifndef __file_h__
@@ -509,6 +509,8 @@ typedef struct {
 #define USE_C_LOCALE
        locale_t old_lc_ctype;
        locale_t c_lc_ctype;
+#else
+       char *old_lc_ctype;
 #endif
        int rc;
        regex_t rx;
index a26677219421420e825ac891f8949a8225b77e19..d26147b368c63cad3c9f62ff869f090648084fba 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.87 2015/09/22 15:40:32 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.88 2016/02/10 15:57:40 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -494,6 +494,8 @@ file_regcomp(file_regex_t *rx, const char *pat, int flags)
        assert(rx->c_lc_ctype != NULL);
        rx->old_lc_ctype = uselocale(rx->c_lc_ctype);
        assert(rx->old_lc_ctype != NULL);
+#else
+       rx->old_lc_ctype = setlocale(LC_CTYPE, "C");
 #endif
        rx->pat = pat;
 
@@ -516,6 +518,8 @@ file_regfree(file_regex_t *rx)
 #ifdef USE_C_LOCALE
        (void)uselocale(rx->old_lc_ctype);
        freelocale(rx->c_lc_ctype);
+#else
+       (void)setlocale(LC_CTYPE, rx->old_lc_ctype);
 #endif
 }
 
index 2ff61bfb6bd325b8a5fe03997c8ff551d0cb5cf1..fdc903936bd85a2bcab2abd489ab3358e878d6c5 100644 (file)
@@ -26,7 +26,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.54 2015/11/23 21:20:50 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.55 2016/02/10 15:57:40 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -120,6 +120,8 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv)
        assert(c_lc_ctype != NULL);
        old_lc_ctype = uselocale(c_lc_ctype);
        assert(old_lc_ctype != NULL);
+#else
+       char *old_lc_ctype = setlocale(LC_CTYPE, "C");
 #endif
        for (i = 0; nv[i].pattern != NULL; i++)
                if (strcasestr(vbuf, nv[i].pattern) != NULL) {
@@ -132,6 +134,8 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv)
 #ifdef USE_C_LOCALE
        (void)uselocale(old_lc_ctype);
        freelocale(c_lc_ctype);
+#else
+       setlocale(LC_CTYPE, old_lc_ctype);
 #endif
        return rv;
 }