1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-22 09:57:34 +03:00

util: properly handle empty word suffixes/prefixes in startswith()/endswith()

This commit is contained in:
Lennart Poettering 2010-04-23 20:29:15 +02:00
parent e558336f7b
commit d4d0d4db93

13
util.c
View File

@ -114,6 +114,9 @@ bool endswith(const char *s, const char *postfix) {
sl = strlen(s);
pl = strlen(postfix);
if (pl == 0)
return true;
if (sl < pl)
return false;
@ -129,6 +132,9 @@ bool startswith(const char *s, const char *prefix) {
sl = strlen(s);
pl = strlen(prefix);
if (pl == 0)
return true;
if (sl < pl)
return false;
@ -147,11 +153,14 @@ bool first_word(const char *s, const char *word) {
if (sl < wl)
return false;
if (wl == 0)
return true;
if (memcmp(s, word, wl) != 0)
return false;
return (s[wl] == 0 ||
strchr(WHITESPACE, s[wl]));
return s[wl] == 0 ||
strchr(WHITESPACE, s[wl]);
}
int close_nointr(int fd) {