chiark / gitweb /
add first_word() call
authorLennart Poettering <lennart@poettering.net>
Sat, 30 Jan 2010 00:52:44 +0000 (01:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 30 Jan 2010 00:52:44 +0000 (01:52 +0100)
util.c
util.h

diff --git a/util.c b/util.c
index 3ce506b0c64f6265e173ab4af3dbf10899300835..4847310aee57d084d5009c0cf0132002ee260e8b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -88,6 +88,25 @@ bool startswith(const char *s, const char *prefix) {
         return memcmp(s, prefix, pl) == 0;
 }
 
+bool first_word(const char *s, const char *word) {
+        size_t sl, wl;
+
+        assert(s);
+        assert(word);
+
+        sl = strlen(s);
+        wl = strlen(word);
+
+        if (sl < wl)
+                return false;
+
+        if (memcmp(s, word, wl) != 0)
+                return false;
+
+        return (s[wl] == 0 ||
+                strchr(WHITESPACE, s[wl]));
+}
+
 int close_nointr(int fd) {
         assert(fd >= 0);
 
diff --git a/util.h b/util.h
index 476b5ae8abefe68e84b959adb0379f33d348c45b..a9c430f722f8b0749cf2e4ed43cb5932ca528515 100644 (file)
--- a/util.h
+++ b/util.h
@@ -60,6 +60,8 @@ static inline bool is_path_absolute(const char *p) {
 bool endswith(const char *s, const char *postfix);
 bool startswith(const char *s, const char *prefix);
 
+bool first_word(const char *s, const char *word);
+
 int close_nointr(int fd);
 void close_nointr_nofail(int fd);