summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 8372038d4d..df5f8d1088 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -8159,3 +8159,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;
+}