From 52779d2ec6391a122cb2822c147d8c1f86e8b6ba Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 24 Feb 2015 11:13:38 +0100 Subject: Introduce starts_with() and starts_with_ci() Create user-defined functions to check whether a string contains a certain prefix instead of messing around with strncmp() and strncasecmp(). Signed-off-by: Lukas Fleischer --- src/utils.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index c7dc61c..ec5a1ea 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1602,3 +1602,15 @@ asprintf(char **str, const char *format, ...) return n; } + +int starts_with(const char *s, const char *p) +{ + for (; *p && *p == *s; s++, p++); + return (*p == '\0'); +} + +int starts_with_ci(const char *s, const char *p) +{ + for (; *p && tolower(*p) == tolower(*s); s++, p++); + return (*p == '\0'); +} -- cgit v1.2.3