Skip to content
Permalink
Browse files

PR/518: Fall back to use setlocale() for the OS's that don't support

newlocale()/uselocale(). This is necessary because some regex patterns
we use (apple) have non-ascii characters in them.
  • Loading branch information...
zoulasc committed Feb 10, 2016
1 parent 1792a31 commit b74175e236c34beeb930c95bb25300c92a205cd3
Showing with 13 additions and 3 deletions.
  1. +3 −1 src/file.h
  2. +5 −1 src/funcs.c
  3. +5 −1 src/readcdf.c
@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
* @(#)$File: file.h,v 1.174 2015/11/13 15:36:14 christos Exp $
* @(#)$File: file.h,v 1.175 2016/01/19 04:17:07 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;
@@ -27,7 +27,7 @@
#include "file.h"

#ifndef lint
FILE_RCSID("@(#)$File: funcs.c,v 1.86 2015/09/17 01:14:09 christos Exp $")
FILE_RCSID("@(#)$File: funcs.c,v 1.87 2015/09/22 15:40:32 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
}

@@ -26,7 +26,7 @@
#include "file.h"

#ifndef lint
FILE_RCSID("@(#)$File: readcdf.c,v 1.53 2015/04/09 20:01:41 christos Exp $")
FILE_RCSID("@(#)$File: readcdf.c,v 1.54 2015/11/23 21:20:50 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;
}

0 comments on commit b74175e

Please sign in to comment.
You can’t perform that action at this time.