blob: 9be82b0cc2c8bd5fe87796dbac30fed2a7d6551b [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
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
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 */
22int 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) {
42 if (!strncmp(p, "no", 2) && !strncmp(p+2, type, len) &&
43 (p[len+2] == 0 || p[len+2] == ','))
44 return 0;
45 if (strncmp(p, type, len) == 0 && (p[len] == 0 || p[len] == ','))
46 return !no;
47 p = strchr(p,',');
48 if (!p)
49 break;
50 p++;
51 }
52 return no;
53}