[systemd-devel] [PATCH] inline static endswith()

WANG Chao chaowang at redhat.com
Fri Aug 23 00:36:51 PDT 2013


---
 src/shared/util.c | 21 ---------------------
 src/shared/util.h |  9 ++++++++-
 2 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index 1dde8af..3a22000 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -107,27 +107,6 @@ bool streq_ptr(const char *a, const char *b) {
         return false;
 }
 
-char* endswith(const char *s, const char *postfix) {
-        size_t sl, pl;
-
-        assert(s);
-        assert(postfix);
-
-        sl = strlen(s);
-        pl = strlen(postfix);
-
-        if (pl == 0)
-                return (char*) s + sl;
-
-        if (sl < pl)
-                return NULL;
-
-        if (memcmp(s + sl - pl, postfix, pl) != 0)
-                return NULL;
-
-        return (char*) s + sl - pl;
-}
-
 bool first_word(const char *s, const char *word) {
         size_t sl, wl;
 
diff --git a/src/shared/util.h b/src/shared/util.h
index 63f4e3d..0dab4cb 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -118,7 +118,14 @@ static inline const char *startswith_no_case(const char *s, const char *prefix)
         return NULL;
 }
 
-char *endswith(const char *s, const char *postfix) _pure_;
+static inline char *endswith(const char *s, const char *postfix) {
+        size_t sl = strlen(s);
+        size_t pl = strlen(postfix);
+
+        if (sl > pl && strncmp(s + sl -pl, postfix, pl) == 0)
+                return (char *) s + sl -pl;
+        return NULL;
+}
 
 bool first_word(const char *s, const char *word) _pure_;
 
-- 
1.8.3.1



More information about the systemd-devel mailing list