From: Karel Zak Date: Thu, 19 Jun 2025 10:23:27 +0000 (+0200) Subject: include/strutils: Add startswithpath() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=10f0de325d016d7f0fcdbb07372292bd406fdb96;p=thirdparty%2Futil-linux.git include/strutils: Add startswithpath() 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 --- diff --git a/include/strutils.h b/include/strutils.h index 70f97f0c8..7cb365254 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -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. */