X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=2d4a4c1102bd2f082c247f2c38dc27e873321210;hp=db8e75b6280635356ee69b24ea66253a1617fec0;hb=6524990fdc98370ecba5d9f73e67161e8798c010;hpb=2001208c2ab631a69896d1f670c26846b70d1fb7 diff --git a/src/shared/util.c b/src/shared/util.c index db8e75b62..2d4a4c110 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5691,6 +5691,30 @@ int can_sleep(const char *type) { return false; } +int can_sleep_disk(const char *type) { + char *w, *state; + size_t l, k; + int r; + _cleanup_free_ char *p = NULL; + + assert(type); + + r = read_one_line_file("/sys/power/disk", &p); + if (r < 0) + return r == -ENOENT ? 0 : r; + + k = strlen(type); + FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) { + if (l == k && memcmp(w, type, l) == 0) + return true; + + if (l == k + 2 && w[0] == '[' && memcmp(w + 1, type, l - 2) == 0 && w[l-1] == ']') + return true; + } + + return false; +} + bool is_valid_documentation_url(const char *url) { assert(url);