From 79d6d8160834fdfc964f4b8b2a6b7fb32c7b36c9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 30 Jan 2010 01:52:44 +0100 Subject: [PATCH] add first_word() call --- util.c | 19 +++++++++++++++++++ util.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/util.c b/util.c index 3ce506b0..4847310a 100644 --- 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 476b5ae8..a9c430f7 100644 --- 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); -- 2.39.5