diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-08-21 16:10:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-08-21 17:24:21 +0200 |
commit | 11adc1aef7a1a6e9ba3fda8eb34eb5fadedc0385 (patch) | |
tree | df0a121bd4f3db89e9d7bc7afd3d6276277581a5 | |
parent | 3fdbc8205885f117b7dea289b44217310663e731 (diff) |
util: change return value of startswith() to non-const
This way we can use it on non-const strings, and don't end up with a
const'ified result.
This is similar to libc's strstr() which also takes a const string but
returns a non-const one.
-rw-r--r-- | src/shared/util.h | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/shared/util.h b/src/shared/util.h index 87ad317319..8cd47b8294 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -158,15 +158,23 @@ static inline bool isempty(const char *p) { return !p || !p[0]; } -static inline const char *startswith(const char *s, const char *prefix) { - if (strncmp(s, prefix, strlen(prefix)) == 0) - return s + strlen(prefix); +static inline char *startswith(const char *s, const char *prefix) { + size_t l; + + l = strlen(prefix); + if (strncmp(s, prefix, l) == 0) + return (char*) s + l; + return NULL; } -static inline const char *startswith_no_case(const char *s, const char *prefix) { - if (strncasecmp(s, prefix, strlen(prefix)) == 0) - return s + strlen(prefix); +static inline char *startswith_no_case(const char *s, const char *prefix) { + size_t l; + + l = strlen(prefix); + if (strncasecmp(s, prefix, l) == 0) + return (char*) s + l; + return NULL; } |