fi])
dnl Checks for functions
-AC_CHECK_FUNCS(strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof)
+AC_CHECK_FUNCS(strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale)
dnl Provide implementation of some required functions if necessary
AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r pread strcasestr fmtcheck)
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.152 2013/06/26 14:46:54 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.153 2014/02/11 15:41:04 christos Exp $")
#endif /* lint */
#include "magic.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* for read() */
#endif
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
#ifdef HAVE_WCHAR_H
#include <wchar.h>
#endif
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.152 2014/06/03 19:01:34 christos Exp $
+ * @(#)$File: file.h,v 1.153 2014/08/04 06:19:44 christos Exp $
*/
#ifndef __file_h__
size_t);
#endif /* __EMX__ */
+#if defined(HAVE_LOCALE_H)
+#include <locale.h>
+#endif
+
typedef struct {
const char *pat;
- char *old_lc_ctype;
+#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
+#define USE_C_LOCALE
+ locale_t old_lc_ctype;
+ locale_t c_lc_ctype;
+#endif
int rc;
regex_t rx;
} file_regex_t;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.71 2014/05/05 20:53:10 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.72 2014/05/14 23:15:42 christos Exp $")
#endif /* lint */
#include "magic.h"
#if defined(HAVE_LIMITS_H)
#include <limits.h>
#endif
-#if defined(HAVE_LOCALE_H)
-#include <locale.h>
-#endif
#ifndef SIZE_MAX
#define SIZE_MAX ((size_t)~0)
protected int
file_regcomp(file_regex_t *rx, const char *pat, int flags)
{
- rx->old_lc_ctype = setlocale(LC_CTYPE, NULL);
- assert(rx->old_lc_ctype != NULL);
- rx->old_lc_ctype = strdup(rx->old_lc_ctype);
+#ifdef USE_C_LOCALE
+ rx->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
+ assert(rx->c_lc_ctype != NULL);
+ rx->old_lc_ctype = uselocale(rx->c_lc_ctype);
assert(rx->old_lc_ctype != NULL);
+#endif
rx->pat = pat;
- (void)setlocale(LC_CTYPE, "C");
return rx->rc = regcomp(&rx->rx, pat, flags);
}
{
if (rx->rc == 0)
regfree(&rx->rx);
- (void)setlocale(LC_CTYPE, rx->old_lc_ctype);
- free(rx->old_lc_ctype);
+#ifdef USE_C_LOCALE
+ (void)uselocale(rx->old_lc_ctype);
+ freelocale(rx->c_lc_ctype);
+#endif
}
protected void
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.46 2014/08/27 06:59:35 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.47 2014/08/27 13:00:37 christos Exp $")
#endif
#include <assert.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
-#if defined(HAVE_LOCALE_H)
-#include <locale.h>
-#endif
#include "cdf.h"
#include "magic.h"
{
size_t i;
const char *rv = NULL;
- char *old_lc_ctype;
+#ifdef USE_C_LOCALE
+ locale_t old_lc_ctype, c_lc_ctype;
- old_lc_ctype = setlocale(LC_CTYPE, NULL);
- assert(old_lc_ctype != NULL);
- old_lc_ctype = strdup(old_lc_ctype);
+ c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
+ assert(c_lc_ctype != NULL);
+ old_lc_ctype = uselocale(c_lc_ctype);
assert(old_lc_ctype != NULL);
- (void)setlocale(LC_CTYPE, "C");
+#endif
for (i = 0; nv[i].pattern != NULL; i++)
if (strcasestr(vbuf, nv[i].pattern) != NULL) {
rv = nv[i].mime;
break;
}
- (void)setlocale(LC_CTYPE, old_lc_ctype);
- free(old_lc_ctype);
+#ifdef USE_C_LOCALE
+ (void)uselocale(old_lc_ctype);
+ freelocale(c_lc_ctype);
+#endif
return rv;
}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.191 2014/06/04 17:36:34 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.192 2014/08/30 15:30:11 christos Exp $")
#endif /* lint */
#include "magic.h"
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
-#if defined(HAVE_LOCALE_H)
-#include <locale.h>
-#endif
-
private int match(struct magic_set *, struct magic *, uint32_t,
const unsigned char *, size_t, size_t, int, int, int, int, int *, int *,