X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=util.c;h=f5f1b3a45e642655217be276d8c7700c058c88a4;hb=afb757b1a8a416b3c692728330a266b3915eef41;hp=8556ea12cd153d6899f3b98a8cc803e80b61f401;hpb=57cd2192d0085737bbc745756b97a40a20711b80;p=elogind.git diff --git a/util.c b/util.c index 8556ea12c..f5f1b3a45 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; @@ -1199,6 +1224,7 @@ bool ignore_file(const char *filename) { return filename[0] == '.' || + streq(filename, "lost+found") || endswith(filename, "~") || endswith(filename, ".rpmnew") || endswith(filename, ".rpmsave") || @@ -1571,7 +1597,7 @@ int flush_fd(int fd) { } int acquire_terminal(const char *name, bool fail, bool force) { - int fd = -1, notify = -1, r, wd; + int fd = -1, notify = -1, r, wd = -1; assert(name);