summaryrefslogtreecommitdiffstats
path: root/src/basic/parse-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-03-21 22:27:19 +0100
committerLennart Poettering <lennart@poettering.net>2018-03-21 22:27:19 +0100
commit5ef56aa205b5c36e622ed0401d4c4c32be6bb47b (patch)
treef80778897fd33f77c4a1552c237444886665c249 /src/basic/parse-util.c
parentWhen mangling names, optionally emit a warning (#8400) (diff)
downloadsystemd-5ef56aa205b5c36e622ed0401d4c4c32be6bb47b.tar.xz
systemd-5ef56aa205b5c36e622ed0401d4c4c32be6bb47b.zip
parse-util: introduce safe_atou16_full()
safe_atou16_full() is like safe_atou16() but also takes a base parameter. safe_atou16() is then implemented as inline function on top of it, passing 0 as base. Similar safe_atoux16() is reworked as inline function too, with 16 as base.
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r--src/basic/parse-util.c29
1 files changed, 3 insertions, 26 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index fa5b4a353a..f0bf57916e 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -487,17 +487,18 @@ int safe_atou8(const char *s, uint8_t *ret) {
return 0;
}
-int safe_atou16(const char *s, uint16_t *ret) {
+int safe_atou16_full(const char *s, unsigned base, uint16_t *ret) {
char *x = NULL;
unsigned long l;
assert(s);
assert(ret);
+ assert(base <= 16);
s += strspn(s, WHITESPACE);
errno = 0;
- l = strtoul(s, &x, 0);
+ l = strtoul(s, &x, base);
if (errno > 0)
return -errno;
if (!x || x == s || *x != 0)
@@ -531,30 +532,6 @@ int safe_atoi16(const char *s, int16_t *ret) {
return 0;
}
-int safe_atoux16(const char *s, uint16_t *ret) {
- char *x = NULL;
- unsigned long l;
-
- assert(s);
- assert(ret);
-
- s += strspn(s, WHITESPACE);
-
- errno = 0;
- l = strtoul(s, &x, 16);
- if (errno > 0)
- return -errno;
- if (!x || x == s || *x != 0)
- return -EINVAL;
- if (s[0] == '-')
- return -ERANGE;
- if ((unsigned long) (uint16_t) l != l)
- return -ERANGE;
-
- *ret = (uint16_t) l;
- return 0;
-}
-
int safe_atod(const char *s, double *ret_d) {
_cleanup_(freelocalep) locale_t loc = (locale_t) 0;
char *x = NULL;