chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(from parent 1:
e558336
)
util: properly handle empty word suffixes/prefixes in startswith()/endswith()
author
Lennart Poettering
<lennart@poettering.net>
Fri, 23 Apr 2010 18:29:15 +0000
(20:29 +0200)
committer
Lennart Poettering
<lennart@poettering.net>
Fri, 23 Apr 2010 18:29:15 +0000
(20:29 +0200)
util.c
patch
|
blob
|
history
diff --git
a/util.c
b/util.c
index 83e819a0cb769decb718148ab02af4a3bb9b8f61..fd991cf807253b88d4cc90e509dee2725bc7a96c 100644
(file)
--- a/
util.c
+++ b/
util.c
@@
-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) {