X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=util.c;h=8042214c8fae7fdd40494691d216624a26cfeee8;hb=aa4112670b37f2ca1cd64a63337575d45e0d7f36;hp=eed9aa7f84e598a5d92ed8fac733fd030ec3b695;hpb=6c78be3c3c63b59f18311b2d2b0e8d745f6ba131;p=elogind.git diff --git a/util.c b/util.c index eed9aa7f8..8042214c8 100644 --- a/util.c +++ b/util.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "macro.h" #include "util.h" @@ -141,6 +142,30 @@ bool startswith(const char *s, const char *prefix) { return memcmp(s, prefix, pl) == 0; } +bool startswith_no_case(const char *s, const char *prefix) { + size_t sl, pl; + unsigned i; + + 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; + } + + return true; +} + bool first_word(const char *s, const char *word) { size_t sl, wl;