/src/util-linux/lib/match.c
Line | Count | Source |
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 | | |
10 | | #include "match.h" |
11 | | #include "cctype.h" |
12 | | |
13 | | /* |
14 | | * match_fstype: |
15 | | * @type: filesystem type |
16 | | * @pattern: filesystem name or comma delimited list of names |
17 | | * |
18 | | * The @pattern list of filesystem can be prefixed with a global |
19 | | * "no" prefix to invert matching of the whole list. The "no" could |
20 | | * also be used for individual items in the @pattern list. So, |
21 | | * "nofoo,bar" has the same meaning as "nofoo,nobar". |
22 | | */ |
23 | | int match_fstype(const char *type, const char *pattern) |
24 | 0 | { |
25 | 0 | int no = 0; /* negated types list */ |
26 | 0 | int len; |
27 | 0 | const char *p; |
28 | |
|
29 | 0 | if (!pattern && !type) |
30 | 0 | return 1; |
31 | 0 | if (!pattern) |
32 | 0 | return 0; |
33 | | |
34 | 0 | if (!strncmp(pattern, "no", 2)) { |
35 | 0 | no = 1; |
36 | 0 | pattern += 2; |
37 | 0 | } |
38 | | |
39 | | /* Does type occur in types, separated by commas? */ |
40 | 0 | len = strlen(type); |
41 | 0 | p = pattern; |
42 | 0 | while(1) { |
43 | 0 | if (!strncmp(p, "no", 2) && !c_strncasecmp(p+2, type, len) && |
44 | 0 | (p[len+2] == 0 || p[len+2] == ',')) |
45 | 0 | return 0; |
46 | 0 | if (c_strncasecmp(p, type, len) == 0 && (p[len] == 0 || p[len] == ',')) |
47 | 0 | return !no; |
48 | 0 | p = strchr(p,','); |
49 | 0 | if (!p) |
50 | 0 | break; |
51 | 0 | p++; |
52 | 0 | } |
53 | 0 | return no; |
54 | 0 | } |