]>
Commit | Line | Data |
---|---|---|
12089155 KZ |
1 | /* |
2 | * Copyright (C) 2011 Karel Zak <kzak@redhat.com> | |
3 | * | |
4 | * This file may be redistributed under the terms of the | |
5 | * GNU Lesser General Public License. | |
6 | */ | |
7 | ||
8 | #include <string.h> | |
9 | ||
1369e06c KZ |
10 | #include "match.h" |
11 | ||
12089155 KZ |
12 | /* |
13 | * match_fstype: | |
14 | * @type: filesystem type | |
15 | * @pattern: filesystem name or comma delimited list of names | |
16 | * | |
17 | * The @pattern list of filesystem can be prefixed with a global | |
18 | * "no" prefix to invert matching of the whole list. The "no" could | |
19 | * also be used for individual items in the @pattern list. So, | |
20 | * "nofoo,bar" has the same meaning as "nofoo,nobar". | |
21 | */ | |
22 | int match_fstype(const char *type, const char *pattern) | |
23 | { | |
24 | int no = 0; /* negated types list */ | |
25 | int len; | |
26 | const char *p; | |
27 | ||
28 | if (!pattern && !type) | |
29 | return 1; | |
30 | if (!pattern) | |
31 | return 0; | |
32 | ||
33 | if (!strncmp(pattern, "no", 2)) { | |
34 | no = 1; | |
35 | pattern += 2; | |
36 | } | |
37 | ||
38 | /* Does type occur in types, separated by commas? */ | |
39 | len = strlen(type); | |
40 | p = pattern; | |
41 | while(1) { | |
0158e68f | 42 | if (!strncmp(p, "no", 2) && !strncasecmp(p+2, type, len) && |
12089155 KZ |
43 | (p[len+2] == 0 || p[len+2] == ',')) |
44 | return 0; | |
0158e68f | 45 | if (strncasecmp(p, type, len) == 0 && (p[len] == 0 || p[len] == ',')) |
12089155 KZ |
46 | return !no; |
47 | p = strchr(p,','); | |
48 | if (!p) | |
49 | break; | |
50 | p++; | |
51 | } | |
52 | return no; | |
53 | } |