summaryrefslogtreecommitdiffstats
path: root/src/basic/parse-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-09-05 18:08:16 +0200
committerLennart Poettering <lennart@poettering.net>2022-09-05 18:17:18 +0200
commit11a1ac5978eb7835bf485ef18ea3a10f09975cf9 (patch)
tree45555054de9546cf8dd1f10c87323caaea46f561 /src/basic/parse-util.c
parentparse-util: make safe_atou16_full() just a wrapper around safe_atou_full() (diff)
downloadsystemd-11a1ac5978eb7835bf485ef18ea3a10f09975cf9.tar.xz
systemd-11a1ac5978eb7835bf485ef18ea3a10f09975cf9.zip
parse-util: make safe_atou8() just a wrapper around safe_atou8_full()
As in the previous commit: it's just a wrapper around the same strtoul(), hence let's just share some more code.
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r--src/basic/parse-util.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index 247c84e618..3b3efb0ab8 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -476,29 +476,17 @@ int safe_atolli(const char *s, long long int *ret_lli) {
return 0;
}
-int safe_atou8(const char *s, uint8_t *ret) {
- unsigned base = 0;
- unsigned long l;
- char *x = NULL;
-
- assert(s);
-
- s += strspn(s, WHITESPACE);
- s = mangle_base(s, &base);
+int safe_atou8_full(const char *s, unsigned base, uint8_t *ret) {
+ unsigned u;
+ int r;
- errno = 0;
- l = strtoul(s, &x, base);
- if (errno > 0)
- return -errno;
- if (!x || x == s || *x != 0)
- return -EINVAL;
- if (l != 0 && s[0] == '-')
- return -ERANGE;
- if ((unsigned long) (uint8_t) l != l)
+ r = safe_atou_full(s, base, &u);
+ if (r < 0)
+ return r;
+ if (u > UINT8_MAX)
return -ERANGE;
- if (ret)
- *ret = (uint8_t) l;
+ *ret = (uint8_t) u;
return 0;
}