From 10f0de325d016d7f0fcdbb07372292bd406fdb96 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 19 Jun 2025 12:23:27 +0200 Subject: [PATCH] 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 --- include/strutils.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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. */ -- 2.47.2