summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-10 14:43:06 +0200
committerLennart Poettering <lennart@poettering.net>2015-04-10 16:23:46 +0200
commit2ff7b0a54271c8480024d6d68edff4a92e781052 (patch)
tree4883cb0ad40483553e06d10a209475f757f273c8 /src/shared/util.c
parent6dd67163b8f173649e7dc73740f35274714caafc (diff)
util: unify how we parse mode_t strings
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;
+}