From 5cb36f41f01cf4b1f4395abfffd1b33116591e58 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 1 Aug 2014 17:03:28 +0200 Subject: resolved: read the system /etc/resolv.conf unless we wrote it ourselves This way we integrate nicely with foreign network management stacks, such as NM. --- src/shared/util.c | 24 ++++++++++++++++++------ src/shared/util.h | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src/shared') diff --git a/src/shared/util.c b/src/shared/util.c index 4c30a98318..e2c955bc07 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -140,26 +140,38 @@ char* endswith(const char *s, const char *postfix) { return (char*) s + sl - pl; } -bool first_word(const char *s, const char *word) { +char* first_word(const char *s, const char *word) { size_t sl, wl; + const char *p; assert(s); assert(word); + /* Checks if the string starts with the specified word, either + * followed by NUL or by whitespace. Returns a pointer to the + * NUL or the first character after the whitespace. */ + sl = strlen(s); wl = strlen(word); if (sl < wl) - return false; + return NULL; if (wl == 0) - return true; + return (char*) s; if (memcmp(s, word, wl) != 0) - return false; + return NULL; + + p = s + wl; + if (*p == 0) + return (char*) p; + + if (!strchr(WHITESPACE, *p)) + return NULL; - return s[wl] == 0 || - strchr(WHITESPACE, s[wl]); + p += strspn(p, WHITESPACE); + return (char*) p; } int close_nointr(int fd) { diff --git a/src/shared/util.h b/src/shared/util.h index 45294800e4..fd999bd942 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -169,7 +169,7 @@ static inline const char *startswith_no_case(const char *s, const char *prefix) char *endswith(const char *s, const char *postfix) _pure_; -bool first_word(const char *s, const char *word) _pure_; +char *first_word(const char *s, const char *word) _pure_; int close_nointr(int fd); int safe_close(int fd); -- cgit v1.2.3-54-g00ecf