RCS file: /p/file/cvsroot/file/ChangeLog,v
retrieving revision 1.219
retrieving revision 1.220
diff -u -r1.219 -r1.220
|
|
|
| 1 | 2014-02-18 13:04 Kimmo Suominen (kimmo@suominen.com) |
| 2 | |
| 3 | * Cache old LC_CTYPE locale before setting it to "C", so |
| 4 | we can use it to restore LC_CTYPE instead of asking |
| 5 | setlocale() to scan the environment variables. |
| 6 | |
1 | 7 | 2014-02-12 18:21 Christos Zoulas <christos@zoulas.com> |
2 | 8 | |
3 | 9 | * Count recursion levels through indirect magic |
RCS file: /p/file/cvsroot/file/src/funcs.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
|
|
|
27 | 27 | #include "file.h" |
28 | 28 | |
29 | 29 | #ifndef lint |
30 | | FILE_RCSID("@(#)$File: funcs.c,v 1.67 2014/02/12 23:20:53 christos Exp $") |
| 30 | FILE_RCSID("@(#)$File: funcs.c,v 1.68 2014/02/18 11:09:31 kim Exp $") |
31 | 31 | #endif /* lint */ |
32 | 32 | |
33 | 33 | #include "magic.h" |
| 34 | #include <assert.h> |
34 | 35 | #include <stdarg.h> |
35 | 36 | #include <stdlib.h> |
36 | 37 | #include <string.h> |
… |
… |
|
442 | 443 | { |
443 | 444 | regex_t rx; |
444 | 445 | int rc, rv = -1; |
| 446 | char *old_lc_ctype; |
445 | 447 | |
| 448 | old_lc_ctype = setlocale(LC_CTYPE, NULL); |
| 449 | assert(old_lc_ctype != NULL); |
| 450 | old_lc_ctype = strdup(old_lc_ctype); |
| 451 | assert(old_lc_ctype != NULL); |
446 | 452 | (void)setlocale(LC_CTYPE, "C"); |
447 | 453 | rc = regcomp(&rx, pat, REG_EXTENDED); |
448 | 454 | if (rc) { |
… |
… |
|
463 | 469 | rv = nm; |
464 | 470 | } |
465 | 471 | out: |
466 | | (void)setlocale(LC_CTYPE, ""); |
| 472 | (void)setlocale(LC_CTYPE, old_lc_ctype); |
| 473 | free(old_lc_ctype); |
467 | 474 | return rv; |
468 | 475 | } |
RCS file: /p/file/cvsroot/file/src/readcdf.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
|
|
|
26 | 26 | #include "file.h" |
27 | 27 | |
28 | 28 | #ifndef lint |
29 | | FILE_RCSID("@(#)$File: readcdf.c,v 1.37 2014/01/06 13:41:18 rrt Exp $") |
| 29 | FILE_RCSID("@(#)$File: readcdf.c,v 1.38 2014/02/18 11:09:31 kim Exp $") |
30 | 30 | #endif |
31 | 31 | |
| 32 | #include <assert.h> |
32 | 33 | #include <stdlib.h> |
33 | 34 | #include <unistd.h> |
34 | 35 | #include <string.h> |
… |
… |
|
74 | 75 | { |
75 | 76 | size_t i; |
76 | 77 | const char *rv = NULL; |
| 78 | char *old_lc_ctype; |
77 | 79 | |
| 80 | old_lc_ctype = setlocale(LC_CTYPE, NULL); |
| 81 | assert(old_lc_ctype != NULL); |
| 82 | old_lc_ctype = strdup(old_lc_ctype); |
| 83 | assert(old_lc_ctype != NULL); |
78 | 84 | (void)setlocale(LC_CTYPE, "C"); |
79 | 85 | for (i = 0; nv[i].pattern != NULL; i++) |
80 | 86 | if (strcasestr(vbuf, nv[i].pattern) != NULL) { |
81 | 87 | rv = nv[i].mime; |
82 | 88 | break; |
83 | 89 | } |
84 | | (void)setlocale(LC_CTYPE, ""); |
| 90 | (void)setlocale(LC_CTYPE, old_lc_ctype); |
| 91 | free(old_lc_ctype); |
85 | 92 | return rv; |
86 | 93 | } |
87 | 94 | |
RCS file: /p/file/cvsroot/file/src/softmagic.c,v
retrieving revision 1.174
retrieving revision 1.176
diff -u -r1.174 -r1.176
|
|
|
32 | 32 | #include "file.h" |
33 | 33 | |
34 | 34 | #ifndef lint |
35 | | FILE_RCSID("@(#)$File: softmagic.c,v 1.174 2014/02/12 23:20:53 christos Exp $") |
| 35 | FILE_RCSID("@(#)$File: softmagic.c,v 1.176 2014/02/18 17:59:21 kim Exp $") |
36 | 36 | #endif /* lint */ |
37 | 37 | |
38 | 38 | #include "magic.h" |
… |
… |
|
42 | 42 | #else |
43 | 43 | #define F(a, b) (a) |
44 | 44 | #endif |
| 45 | #include <assert.h> |
45 | 46 | #include <string.h> |
46 | 47 | #include <ctype.h> |
47 | 48 | #include <stdlib.h> |
… |
… |
|
352 | 353 | { |
353 | 354 | regex_t rx; |
354 | 355 | int rc, rv = -1; |
| 356 | char *old_lc_ctype; |
355 | 357 | |
356 | 358 | if (strchr(m->desc, '%') == NULL) |
357 | 359 | return 0; |
358 | 360 | |
| 361 | old_lc_ctype = setlocale(LC_CTYPE, NULL); |
| 362 | assert(old_lc_ctype != NULL); |
| 363 | old_lc_ctype = strdup(old_lc_ctype); |
| 364 | assert(old_lc_ctype != NULL); |
359 | 365 | (void)setlocale(LC_CTYPE, "C"); |
360 | 366 | rc = regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB); |
361 | 367 | if (rc) { |
… |
… |
|
367 | 373 | regfree(&rx); |
368 | 374 | rv = !rc; |
369 | 375 | } |
370 | | (void)setlocale(LC_CTYPE, ""); |
| 376 | (void)setlocale(LC_CTYPE, old_lc_ctype); |
| 377 | free(old_lc_ctype); |
371 | 378 | return rv; |
372 | 379 | } |
373 | 380 | |
… |
… |
|
1884 | 1891 | double dl, dv; |
1885 | 1892 | int matched; |
1886 | 1893 | union VALUETYPE *p = &ms->ms_value; |
| 1894 | char *old_lc_ctype; |
1887 | 1895 | |
1888 | 1896 | switch (m->type) { |
1889 | 1897 | case FILE_BYTE: |
… |
… |
|
2042 | 2050 | if (ms->search.s == NULL) |
2043 | 2051 | return 0; |
2044 | 2052 | |
| 2053 | old_lc_ctype = setlocale(LC_CTYPE, NULL); |
| 2054 | assert(old_lc_ctype != NULL); |
| 2055 | old_lc_ctype = strdup(old_lc_ctype); |
| 2056 | assert(old_lc_ctype != NULL); |
| 2057 | (void)setlocale(LC_CTYPE, "C"); |
2045 | 2058 | l = 0; |
2046 | 2059 | rc = regcomp(&rx, m->value.s, |
2047 | 2060 | REG_EXTENDED|REG_NEWLINE| |
… |
… |
|
2090 | 2103 | } |
2091 | 2104 | regfree(&rx); |
2092 | 2105 | } |
| 2106 | (void)setlocale(LC_CTYPE, old_lc_ctype); |
| 2107 | free(old_lc_ctype); |
2093 | 2108 | if (v == (uint64_t)-1) |
2094 | 2109 | return -1; |
2095 | 2110 | break; |