X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=util.c;h=a0f26762dc39b87b3f6cb3c24acb50db14849512;hp=03c60af98daa527222c87214cb14d60edc6c1a9b;hb=db12775d59ab709f8afc361eaa30c9d54a0a8d7c;hpb=2f357920ffd58e7b56940c64ab8d14a83a27b9f1 diff --git a/util.c b/util.c index 03c60af98..a0f26762d 100644 --- a/util.c +++ b/util.c @@ -611,6 +611,23 @@ char *strstrip(char *s) { } +char *delete_chars(char *s, const char *bad) { + char *f, *t; + + /* Drops all whitespace, regardless where in the string */ + + for (f = s, t = s; *f; f++) { + if (strchr(bad, *f)) + continue; + + *(t++) = *f; + } + + *t = 0; + + return s; +} + char *file_in_same_dir(const char *path, const char *filename) { char *e, *r; size_t k; @@ -1133,7 +1150,7 @@ int close_all_fds(const int except[], unsigned n_except) { return -errno; while ((de = readdir(d))) { - int fd; + int fd = -1; if (de->d_name[0] == '.') continue; @@ -1176,6 +1193,17 @@ finish: return r; } +bool chars_intersect(const char *a, const char *b) { + const char *p; + + /* Returns true if any of the chars in a are in b. */ + for (p = a; *p; p++) + if (strchr(b, *p)) + return true; + + return false; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime",