Deleted Added
full compact
funcs.c (275666) funcs.c (275698)
1/*
2 * Copyright (c) Christos Zoulas 2003.
3 * All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27#include "file.h"
28
29#ifndef lint
1/*
2 * Copyright (c) Christos Zoulas 2003.
3 * All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27#include "file.h"
28
29#ifndef lint
30FILE_RCSID("@(#)$File: funcs.c,v 1.72 2014/05/14 23:15:42 christos Exp $")
30FILE_RCSID("@(#)$File: funcs.c,v 1.77 2014/11/28 02:46:39 christos Exp $")
31#endif /* lint */
32
33#include "magic.h"
34#include <assert.h>
35#include <stdarg.h>
36#include <stdlib.h>
37#include <string.h>
38#include <ctype.h>
39#if defined(HAVE_WCHAR_H)
40#include <wchar.h>
41#endif
42#if defined(HAVE_WCTYPE_H)
43#include <wctype.h>
44#endif
45#if defined(HAVE_LIMITS_H)
46#include <limits.h>
47#endif
31#endif /* lint */
32
33#include "magic.h"
34#include <assert.h>
35#include <stdarg.h>
36#include <stdlib.h>
37#include <string.h>
38#include <ctype.h>
39#if defined(HAVE_WCHAR_H)
40#include <wchar.h>
41#endif
42#if defined(HAVE_WCTYPE_H)
43#include <wctype.h>
44#endif
45#if defined(HAVE_LIMITS_H)
46#include <limits.h>
47#endif
48#if defined(HAVE_LOCALE_H)
49#include <locale.h>
50#endif
51
52#ifndef SIZE_MAX
53#define SIZE_MAX ((size_t)~0)
54#endif
55
56/*
57 * Like printf, only we append to a buffer.
58 */

--- 166 unchanged lines hidden (view full) ---

225 if ((m = file_trycdf(ms, fd, ubuf, nb)) != 0) {
226 if ((ms->flags & MAGIC_DEBUG) != 0)
227 (void)fprintf(stderr, "cdf %d\n", m);
228 goto done;
229 }
230
231 /* try soft magic tests */
232 if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
48
49#ifndef SIZE_MAX
50#define SIZE_MAX ((size_t)~0)
51#endif
52
53/*
54 * Like printf, only we append to a buffer.
55 */

--- 166 unchanged lines hidden (view full) ---

222 if ((m = file_trycdf(ms, fd, ubuf, nb)) != 0) {
223 if ((ms->flags & MAGIC_DEBUG) != 0)
224 (void)fprintf(stderr, "cdf %d\n", m);
225 goto done;
226 }
227
228 /* try soft magic tests */
229 if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
233 if ((m = file_softmagic(ms, ubuf, nb, 0, BINTEST,
230 if ((m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST,
234 looks_text)) != 0) {
235 if ((ms->flags & MAGIC_DEBUG) != 0)
236 (void)fprintf(stderr, "softmagic %d\n", m);
237#ifdef BUILTIN_ELF
238 if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 &&
239 nb > 5 && fd != -1) {
240 /*
241 * We matched something in the file, so this

--- 208 unchanged lines hidden (view full) ---

450out:
451 file_regfree(&rx);
452 return rv;
453}
454
455protected int
456file_regcomp(file_regex_t *rx, const char *pat, int flags)
457{
231 looks_text)) != 0) {
232 if ((ms->flags & MAGIC_DEBUG) != 0)
233 (void)fprintf(stderr, "softmagic %d\n", m);
234#ifdef BUILTIN_ELF
235 if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 &&
236 nb > 5 && fd != -1) {
237 /*
238 * We matched something in the file, so this

--- 208 unchanged lines hidden (view full) ---

447out:
448 file_regfree(&rx);
449 return rv;
450}
451
452protected int
453file_regcomp(file_regex_t *rx, const char *pat, int flags)
454{
458 rx->old_lc_ctype = setlocale(LC_CTYPE, NULL);
455#ifdef USE_C_LOCALE
456 rx->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
457 assert(rx->c_lc_ctype != NULL);
458 rx->old_lc_ctype = uselocale(rx->c_lc_ctype);
459 assert(rx->old_lc_ctype != NULL);
459 assert(rx->old_lc_ctype != NULL);
460 rx->old_lc_ctype = strdup(rx->old_lc_ctype);
461 assert(rx->old_lc_ctype != NULL);
460#endif
462 rx->pat = pat;
463
461 rx->pat = pat;
462
464 (void)setlocale(LC_CTYPE, "C");
465 return rx->rc = regcomp(&rx->rx, pat, flags);
466}
467
468protected int
469file_regexec(file_regex_t *rx, const char *str, size_t nmatch,
470 regmatch_t* pmatch, int eflags)
471{
472 assert(rx->rc == 0);
473 return regexec(&rx->rx, str, nmatch, pmatch, eflags);
474}
475
476protected void
477file_regfree(file_regex_t *rx)
478{
479 if (rx->rc == 0)
480 regfree(&rx->rx);
463 return rx->rc = regcomp(&rx->rx, pat, flags);
464}
465
466protected int
467file_regexec(file_regex_t *rx, const char *str, size_t nmatch,
468 regmatch_t* pmatch, int eflags)
469{
470 assert(rx->rc == 0);
471 return regexec(&rx->rx, str, nmatch, pmatch, eflags);
472}
473
474protected void
475file_regfree(file_regex_t *rx)
476{
477 if (rx->rc == 0)
478 regfree(&rx->rx);
481 (void)setlocale(LC_CTYPE, rx->old_lc_ctype);
482 free(rx->old_lc_ctype);
479#ifdef USE_C_LOCALE
480 (void)uselocale(rx->old_lc_ctype);
481 freelocale(rx->c_lc_ctype);
482#endif
483}
484
485protected void
486file_regerror(file_regex_t *rx, int rc, struct magic_set *ms)
487{
488 char errmsg[512];
489
490 (void)regerror(rc, &rx->rx, errmsg, sizeof(errmsg));

--- 43 unchanged lines hidden ---
483}
484
485protected void
486file_regerror(file_regex_t *rx, int rc, struct magic_set *ms)
487{
488 char errmsg[512];
489
490 (void)regerror(rc, &rx->rx, errmsg, sizeof(errmsg));

--- 43 unchanged lines hidden ---