From: Lennart Poettering Date: Fri, 19 Oct 2012 02:52:51 +0000 (+0200) Subject: util: change endswith() to return a pointer to the suffix X-Git-Tag: v195~40 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=8c7c140fcab0592735d22168657a143969a4c2bf util: change endswith() to return a pointer to the suffix --- diff --git a/src/shared/util.c b/src/shared/util.c index ef30cb2da..42a2e2730 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -195,7 +195,7 @@ struct timeval *timeval_store(struct timeval *tv, usec_t u) { return tv; } -bool endswith(const char *s, const char *postfix) { +char* endswith(const char *s, const char *postfix) { size_t sl, pl; assert(s); @@ -205,12 +205,15 @@ bool endswith(const char *s, const char *postfix) { pl = strlen(postfix); if (pl == 0) - return true; + return (char*) s + sl; if (sl < pl) - return false; + return NULL; + + if (memcmp(s + sl - pl, postfix, pl) != 0) + return NULL; - return memcmp(s + sl - pl, postfix, pl) == 0; + return (char*) s + sl - pl; } bool startswith(const char *s, const char *prefix) { diff --git a/src/shared/util.h b/src/shared/util.h index affb66998..77d28751f 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -141,7 +141,7 @@ static inline bool isempty(const char *p) { return !p || !p[0]; } -bool endswith(const char *s, const char *postfix); +char *endswith(const char *s, const char *postfix); bool startswith(const char *s, const char *prefix); bool startswith_no_case(const char *s, const char *prefix);