]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/strutils: Add startswithpath()
authorKarel Zak <kzak@redhat.com>
Thu, 19 Jun 2025 10:23:27 +0000 (12:23 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 19 Jun 2025 10:23:27 +0000 (12:23 +0200)
This is similar to startswith() but checks if the prefix is a complete
path or a complete subdirectory (needs to end with '/').

Signed-off-by: Karel Zak <kzak@redhat.com>
include/strutils.h

index 70f97f0c866f80eaf5a029a5a3440ece44d65172..7cb3652540353a73288edbfc5d484e5e3f120914 100644 (file)
@@ -288,6 +288,19 @@ static inline const char *startswith_no_case(const char *s, const char *prefix)
        return NULL;
 }
 
+/*
+ * Match path beginning
+ */
+static inline const char *startswithpath(const char *s, const char *prefix)
+{
+       const char *p = startswith(s, prefix);
+
+       if (p && (*p == '/' || *p == '\0'))
+               return p;
+
+       return NULL;
+}
+
 /*
  * Match string ending.
  */