| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: util.c,v 1.16 2012/05/06 22:32:05 joerg Exp $ */ | | 1 | /* $NetBSD: util.c,v 1.17 2013/01/21 03:24:43 msaitoh Exp $ */ |
2 | /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ | | 2 | /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ |
3 | /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ | | 3 | /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ |
4 | | | 4 | |
5 | /*- | | 5 | /*- |
6 | * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav | | 6 | * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav |
7 | * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org> | | 7 | * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org> |
8 | * All rights reserved. | | 8 | * All rights reserved. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -24,27 +24,27 @@ | | | @@ -24,27 +24,27 @@ |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #if HAVE_NBTOOL_CONFIG_H | | 32 | #if HAVE_NBTOOL_CONFIG_H |
33 | #include "nbtool_config.h" | | 33 | #include "nbtool_config.h" |
34 | #endif | | 34 | #endif |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | __RCSID("$NetBSD: util.c,v 1.16 2012/05/06 22:32:05 joerg Exp $"); | | 37 | __RCSID("$NetBSD: util.c,v 1.17 2013/01/21 03:24:43 msaitoh Exp $"); |
38 | | | 38 | |
39 | #include <sys/stat.h> | | 39 | #include <sys/stat.h> |
40 | #include <sys/types.h> | | 40 | #include <sys/types.h> |
41 | | | 41 | |
42 | #include <ctype.h> | | 42 | #include <ctype.h> |
43 | #include <err.h> | | 43 | #include <err.h> |
44 | #include <errno.h> | | 44 | #include <errno.h> |
45 | #include <fnmatch.h> | | 45 | #include <fnmatch.h> |
46 | #include <fts.h> | | 46 | #include <fts.h> |
47 | #include <libgen.h> | | 47 | #include <libgen.h> |
48 | #include <stdbool.h> | | 48 | #include <stdbool.h> |
49 | #include <stdio.h> | | 49 | #include <stdio.h> |
50 | #include <stdlib.h> | | 50 | #include <stdlib.h> |
| @@ -64,29 +64,30 @@ bool | | | @@ -64,29 +64,30 @@ bool |
64 | file_matching(const char *fname) | | 64 | file_matching(const char *fname) |
65 | { | | 65 | { |
66 | char *fname_base, *fname_copy; | | 66 | char *fname_base, *fname_copy; |
67 | unsigned int i; | | 67 | unsigned int i; |
68 | bool ret; | | 68 | bool ret; |
69 | | | 69 | |
70 | ret = finclude ? false : true; | | 70 | ret = finclude ? false : true; |
71 | fname_copy = grep_strdup(fname); | | 71 | fname_copy = grep_strdup(fname); |
72 | fname_base = basename(fname_copy); | | 72 | fname_base = basename(fname_copy); |
73 | | | 73 | |
74 | for (i = 0; i < fpatterns; ++i) { | | 74 | for (i = 0; i < fpatterns; ++i) { |
75 | if (fnmatch(fpattern[i].pat, fname, 0) == 0 || | | 75 | if (fnmatch(fpattern[i].pat, fname, 0) == 0 || |
76 | fnmatch(fpattern[i].pat, fname_base, 0) == 0) { | | 76 | fnmatch(fpattern[i].pat, fname_base, 0) == 0) { |
77 | if (fpattern[i].mode == EXCL_PAT) | | 77 | if (fpattern[i].mode == EXCL_PAT) { |
| | | 78 | free(fname_copy); |
78 | return (false); | | 79 | return (false); |
79 | else | | 80 | } else |
80 | ret = true; | | 81 | ret = true; |
81 | } | | 82 | } |
82 | } | | 83 | } |
83 | free(fname_copy); | | 84 | free(fname_copy); |
84 | return (ret); | | 85 | return (ret); |
85 | } | | 86 | } |
86 | | | 87 | |
87 | static inline bool | | 88 | static inline bool |
88 | dir_matching(const char *dname) | | 89 | dir_matching(const char *dname) |
89 | { | | 90 | { |
90 | unsigned int i; | | 91 | unsigned int i; |
91 | bool ret; | | 92 | bool ret; |
92 | | | 93 | |