X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=util.c;h=a0f26762dc39b87b3f6cb3c24acb50db14849512;hb=db12775d59ab709f8afc361eaa30c9d54a0a8d7c;hp=f3af9567cf49cb79043977511e52b2112e0361b9;hpb=a0d40ac588701010ea6a9366f6a874e83844858e;p=elogind.git diff --git a/util.c b/util.c index f3af9567c..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; @@ -1162,15 +1179,31 @@ int close_all_fds(const int except[], unsigned n_except) { continue; } - if ((r = close_nointr(fd)) < 0) - goto finish; + if ((r = close_nointr(fd)) < 0) { + /* Valgrind has its own FD and doesn't want to have it closed */ + if (errno != EBADF) + goto finish; + } } + r = 0; + finish: closedir(d); 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",