X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=b1f4e309d8a69fefb31dbdf8714752247cf99e81;hb=01c94c5d0aff09b4c0e429d483c8eeba40017071;hp=a82ac25f6fb9c1ac15a92b28858425d01cfb506d;hpb=f9713158cbee03f37bc288a41ea6ca83c4968021;p=elogind.git diff --git a/src/shared/util.c b/src/shared/util.c index a82ac25f6..b1f4e309d 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -92,6 +92,7 @@ #include "virt.h" #include "def.h" #include "sparse-endian.h" +#include "formats-util.h" /* Put this test here for a lack of better place */ assert_cc(EAGAIN == EWOULDBLOCK); @@ -150,27 +151,6 @@ char* endswith(const char *s, const char *postfix) { return (char*) s + sl - pl; } -char* endswith_no_case(const char *s, const char *postfix) { - size_t sl, pl; - - assert(s); - assert(postfix); - - sl = strlen(s); - pl = strlen(postfix); - - if (pl == 0) - return (char*) s + sl; - - if (sl < pl) - return NULL; - - if (strcasecmp(s + sl - pl, postfix) != 0) - return NULL; - - return (char*) s + sl - pl; -} - char* first_word(const char *s, const char *word) { size_t sl, wl; const char *p; @@ -3696,36 +3676,6 @@ static char *unquote(const char *s, const char* quotes) { return strdup(s); } -char *normalize_env_assignment(const char *s) { - _cleanup_free_ char *value = NULL; - const char *eq; - char *p, *name; - - eq = strchr(s, '='); - if (!eq) { - char *r, *t; - - r = strdup(s); - if (!r) - return NULL; - - t = strstrip(r); - if (t != r) - memmove(r, t, strlen(t) + 1); - - return r; - } - - name = strndupa(s, eq - s); - p = strdupa(eq + 1); - - value = unquote(strstrip(p), QUOTES); - if (!value) - return NULL; - - return strjoin(strstrip(name), "=", value, NULL); -} - int wait_for_terminate(pid_t pid, siginfo_t *status) { siginfo_t dummy; @@ -8145,3 +8095,24 @@ char *shell_maybe_quote(const char *s) { return r; } + +int parse_mode(const char *s, mode_t *ret) { + char *x; + long l; + + assert(s); + assert(ret); + + errno = 0; + l = strtol(s, &x, 8); + if (errno != 0) + return -errno; + + if (!x || x == s || *x) + return -EINVAL; + if (l < 0 || l > 07777) + return -ERANGE; + + *ret = (mode_t) l; + return 0; +}