]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib,match: split match_fstype() from libmount
authorKarel Zak <kzak@redhat.com>
Tue, 15 Nov 2011 14:17:19 +0000 (15:17 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 15 Nov 2011 14:17:19 +0000 (15:17 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/match.h [new file with mode: 0644]
lib/match.c [new file with mode: 0644]
libmount/src/Makefile.am
libmount/src/utils.c

diff --git a/include/match.h b/include/match.h
new file mode 100644 (file)
index 0000000..94440c2
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Copyright (C) 2011 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+#ifndef UTIL_LINUX_MATCH_H
+#define UTIL_LINUX_MATCH_H
+
+extern int match_fstype(const char *type, const char *pattern);
+
+#endif /* UTIL_LINUX_MATCH_H */
diff --git a/lib/match.c b/lib/match.c
new file mode 100644 (file)
index 0000000..c5c48a0
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+
+#include <string.h>
+
+/*
+ * match_fstype:
+ * @type: filesystem type
+ * @pattern: filesystem name or comma delimited list of names
+ *
+ * The @pattern list of filesystem can be prefixed with a global
+ * "no" prefix to invert matching of the whole list. The "no" could
+ * also be used for individual items in the @pattern list. So,
+ * "nofoo,bar" has the same meaning as "nofoo,nobar".
+ */
+int match_fstype(const char *type, const char *pattern)
+{
+       int no = 0;             /* negated types list */
+       int len;
+       const char *p;
+
+       if (!pattern && !type)
+               return 1;
+       if (!pattern)
+               return 0;
+
+       if (!strncmp(pattern, "no", 2)) {
+               no = 1;
+               pattern += 2;
+       }
+
+       /* Does type occur in types, separated by commas? */
+       len = strlen(type);
+       p = pattern;
+       while(1) {
+               if (!strncmp(p, "no", 2) && !strncmp(p+2, type, len) &&
+                   (p[len+2] == 0 || p[len+2] == ','))
+                       return 0;
+               if (strncmp(p, type, len) == 0 && (p[len] == 0 || p[len] == ','))
+                       return !no;
+               p = strchr(p,',');
+               if (!p)
+                       break;
+               p++;
+       }
+       return no;
+}
index 5525ba279e8f8739102b695341764e48650b385d..edf766e1fe674e855f87446a3a0bc4884cdd8c51 100644 (file)
@@ -16,6 +16,7 @@ libmount_la_SOURCES = mountP.h version.c utils.c test.c init.c cache.c \
                        context_loopdev.c \
                        $(mountinc_HEADERS) \
                        $(top_srcdir)/lib/at.c \
+                       $(top_srcdir)/lib/match.c \
                        $(top_srcdir)/include/list.h \
                        $(top_srcdir)/lib/mangle.c \
                        $(top_srcdir)/lib/canonicalize.c \
index 239e587fe439137bbc595a124b0b1fc46cc1fab3..7cd50ec3a8ec03b2f53fb64a8b23cc9610d49cdd 100644 (file)
@@ -245,35 +245,7 @@ int mnt_fstype_is_netfs(const char *type)
  */
 int mnt_match_fstype(const char *type, const char *pattern)
 {
-       int no = 0;             /* negated types list */
-       int len;
-       const char *p;
-
-       if (!pattern && !type)
-               return 1;
-       if (!pattern)
-               return 0;
-
-       if (!strncmp(pattern, "no", 2)) {
-               no = 1;
-               pattern += 2;
-       }
-
-       /* Does type occur in types, separated by commas? */
-       len = strlen(type);
-       p = pattern;
-       while(1) {
-               if (!strncmp(p, "no", 2) && !strncmp(p+2, type, len) &&
-                   (p[len+2] == 0 || p[len+2] == ','))
-                       return 0;
-               if (strncmp(p, type, len) == 0 && (p[len] == 0 || p[len] == ','))
-                       return !no;
-               p = strchr(p,',');
-               if (!p)
-                       break;
-               p++;
-       }
-       return no;
+       return match_fstype(type, pattern);
 }