summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/util.c b/util.c
index 3ce506b0c6..4847310aee 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);