diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-07-19 12:42:17 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2018-07-19 12:42:17 -0400 |
commit | 021fdbe02956e745b579f49fc0585747c2aec458 (patch) | |
tree | d74b6c6eaa8130e55e9b52f310acb23fcc033d73 /src/basic/parse-util.c | |
parent | d54b7826fa34ee1af5d28023f1847f3ae55ff10c (diff) | |
parent | 8e0c6d2655f83927ffdce8ed2edf6d7b80423178 (diff) |
Merge tag 'systemd/v238.0-3.parabola1' into systemd/parabola
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r-- | src/basic/parse-util.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 2c22753dea..fa5b4a353a 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -531,6 +531,30 @@ 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; |