summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-27 01:20:01 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-27 01:20:01 +0200
commite8988fc2a26cda58a2088c2884f4c3802c25dfc8 (patch)
tree6c0321acef22fe204e95d7657959c95f9e5471e2 /src/shared/util.c
parentada45c785fc7b0cbe0adb9cbf641943410f4953f (diff)
util: return the remaining string in startswith()
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index a73443d535..db8e75b628 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -216,45 +216,38 @@ char* endswith(const char *s, const char *postfix) {
return (char*) s + sl - pl;
}
-bool startswith(const char *s, const char *prefix) {
- size_t sl, pl;
+char* startswith(const char *s, const char *prefix) {
+ const char *a, *b;
assert(s);
assert(prefix);
- sl = strlen(s);
- pl = strlen(prefix);
-
- if (pl == 0)
- return true;
-
- if (sl < pl)
- return false;
+ a = s, b = prefix;
+ for (;;) {
+ if (*b == 0)
+ return (char*) a;
+ if (*a != *b)
+ return NULL;
- return memcmp(s, prefix, pl) == 0;
+ a++, b++;
+ }
}
-bool startswith_no_case(const char *s, const char *prefix) {
- size_t sl, pl;
- unsigned i;
+char* startswith_no_case(const char *s, const char *prefix) {
+ const char *a, *b;
assert(s);
assert(prefix);
- sl = strlen(s);
- pl = strlen(prefix);
-
- if (pl == 0)
- return true;
-
- if (sl < pl)
- return false;
-
- for(i = 0; i < pl; ++i)
- if (tolower(s[i]) != tolower(prefix[i]))
- return false;
+ a = s, b = prefix;
+ for (;;) {
+ if (*b == 0)
+ return (char*) a;
+ if (tolower(*a) != tolower(*b))
+ return NULL;
- return true;
+ a++, b++;
+ }
}
bool first_word(const char *s, const char *word) {