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