hush: HUSH_READONLY depends on HUSH
[oweals/busybox.git] / libbb / match_fstype.c
index 99e2767848e902b3c3d82a3c65f29b3cee873611..6046bc6db882a822bcf986243d6077b5302c3d44 100644 (file)
@@ -5,40 +5,37 @@
  * This allows us to match fstypes that start with no like so
  *   mount -at ,noddy
  *
- * Returns 0 for a match, otherwise -1
+ * Returns 1 for a match, otherwise 0
  *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 #include "libbb.h"
 
-int FAST_FUNC match_fstype(const struct mntent *mt, const char *fstype)
+int FAST_FUNC fstype_matches(const char *fstype, const char *comma_list)
 {
-       int no = 0;
-       int len;
+       int match = 1;
 
-       if (!mt)
-               return -1;
+       if (!comma_list)
+               return match;
 
-       if (!fstype)
-               return 0;
-
-       if (fstype[0] == 'n' && fstype[1] == 'o') {
-               no = -1;
-               fstype += 2;
+       if (comma_list[0] == 'n' && comma_list[1] == 'o') {
+               match--;
+               comma_list += 2;
        }
 
-       len = strlen(mt->mnt_type);
-       while (fstype) {
-               if (!strncmp(mt->mnt_type, fstype, len)
-                && (!fstype[len] || fstype[len] == ',')
+       while (1) {
+               char *after_mnt_type = is_prefixed_with(comma_list, fstype);
+               if (after_mnt_type
+                && (*after_mnt_type == '\0' || *after_mnt_type == ',')
                ) {
-                       return no;
+                       return match;
                }
-               fstype = strchr(fstype, ',');
-               if (fstype)
-                       fstype++;
+               comma_list = strchr(comma_list, ',');
+               if (!comma_list)
+                       break;
+               comma_list++;
        }
 
-       return -(no + 1);
+       return !match;
 }