+2014-02-18 13:04 Kimmo Suominen (kimmo@suominen.com)
+
+ * Cache old LC_CTYPE locale before setting it to "C", so
+ we can use it to restore LC_CTYPE instead of asking
+ setlocale() to scan the environment variables.
+
2014-02-12 18:21 Christos Zoulas <christos@zoulas.com>
* Count recursion levels through indirect magic
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.67 2014/02/12 23:20:53 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.68 2014/02/18 11:09:31 kim Exp $")
#endif /* lint */
#include "magic.h"
+#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
{
regex_t rx;
int rc, rv = -1;
+ char *old_lc_ctype;
+ old_lc_ctype = setlocale(LC_CTYPE, NULL);
+ assert(old_lc_ctype != NULL);
+ old_lc_ctype = strdup(old_lc_ctype);
+ assert(old_lc_ctype != NULL);
(void)setlocale(LC_CTYPE, "C");
rc = regcomp(&rx, pat, REG_EXTENDED);
if (rc) {
rv = nm;
}
out:
- (void)setlocale(LC_CTYPE, "");
+ (void)setlocale(LC_CTYPE, old_lc_ctype);
+ free(old_lc_ctype);
return rv;
}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.37 2014/01/06 13:41:18 rrt Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.38 2014/02/18 11:09:31 kim Exp $")
#endif
+#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
{
size_t i;
const char *rv = NULL;
+ char *old_lc_ctype;
+ old_lc_ctype = setlocale(LC_CTYPE, NULL);
+ assert(old_lc_ctype != NULL);
+ old_lc_ctype = strdup(old_lc_ctype);
+ assert(old_lc_ctype != NULL);
(void)setlocale(LC_CTYPE, "C");
for (i = 0; nv[i].pattern != NULL; i++)
if (strcasestr(vbuf, nv[i].pattern) != NULL) {
rv = nv[i].mime;
break;
}
- (void)setlocale(LC_CTYPE, "");
+ (void)setlocale(LC_CTYPE, old_lc_ctype);
+ free(old_lc_ctype);
return rv;
}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.174 2014/02/12 23:20:53 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.175 2014/02/18 11:09:31 kim Exp $")
#endif /* lint */
#include "magic.h"
#else
#define F(a, b) (a)
#endif
+#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
{
regex_t rx;
int rc, rv = -1;
+ char *old_lc_ctype;
if (strchr(m->desc, '%') == NULL)
return 0;
+ old_lc_ctype = setlocale(LC_CTYPE, NULL);
+ assert(old_lc_ctype != NULL);
+ old_lc_ctype = strdup(old_lc_ctype);
+ assert(old_lc_ctype != NULL);
(void)setlocale(LC_CTYPE, "C");
rc = regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
if (rc) {
regfree(&rx);
rv = !rc;
}
- (void)setlocale(LC_CTYPE, "");
+ (void)setlocale(LC_CTYPE, old_lc_ctype);
+ free(old_lc_ctype);
return rv;
}