chiark / gitweb /
util: change endswith() to return a pointer to the suffix
authorLennart Poettering <lennart@poettering.net>
Fri, 19 Oct 2012 02:52:51 +0000 (04:52 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 19 Oct 2012 02:53:46 +0000 (04:53 +0200)
src/shared/util.c
src/shared/util.h

index ef30cb2dab15b2dfade9be5dde7d7e101fa9f31a..42a2e27308f9e42b46268a4b4de1dcf0d9fcffaf 100644 (file)
@@ -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) {
index affb66998c1977c78b53bd8b142f2c2cf1b0bcc2..77d28751f0a40937e455748542c6480e0cac074d 100644 (file)
@@ -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);