mirror of
https://github.com/systemd/systemd.git
synced 2025-09-12 01:44:46 +03:00
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.
This commit is contained in:
@@ -476,29 +476,17 @@ int safe_atolli(const char *s, long long int *ret_lli) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int safe_atou8(const char *s, uint8_t *ret) {
|
int safe_atou8_full(const char *s, unsigned base, uint8_t *ret) {
|
||||||
unsigned base = 0;
|
unsigned u;
|
||||||
unsigned long l;
|
int r;
|
||||||
char *x = NULL;
|
|
||||||
|
|
||||||
assert(s);
|
r = safe_atou_full(s, base, &u);
|
||||||
|
if (r < 0)
|
||||||
s += strspn(s, WHITESPACE);
|
return r;
|
||||||
s = mangle_base(s, &base);
|
if (u > UINT8_MAX)
|
||||||
|
|
||||||
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)
|
|
||||||
return -ERANGE;
|
return -ERANGE;
|
||||||
|
|
||||||
if (ret)
|
*ret = (uint8_t) u;
|
||||||
*ret = (uint8_t) l;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,7 +36,11 @@ static inline int safe_atou(const char *s, unsigned *ret_u) {
|
|||||||
int safe_atoi(const char *s, int *ret_i);
|
int safe_atoi(const char *s, int *ret_i);
|
||||||
int safe_atolli(const char *s, long long int *ret_i);
|
int safe_atolli(const char *s, long long int *ret_i);
|
||||||
|
|
||||||
int safe_atou8(const char *s, uint8_t *ret);
|
int safe_atou8_full(const char *s, unsigned base, uint8_t *ret);
|
||||||
|
|
||||||
|
static inline int safe_atou8(const char *s, uint8_t *ret) {
|
||||||
|
return safe_atou8_full(s, 0, ret);
|
||||||
|
}
|
||||||
|
|
||||||
int safe_atou16_full(const char *s, unsigned base, uint16_t *ret);
|
int safe_atou16_full(const char *s, unsigned base, uint16_t *ret);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user