Merge pull request #29224 from keszybz/netdev-config-parsing
Use a helper to simplify parsing of ranges in netdev config and related changes
This commit is contained in:
@@ -425,6 +425,21 @@ int safe_atou_full(const char *s, unsigned base, unsigned *ret_u) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safe_atou_bounded(const char *s, unsigned min, unsigned max, unsigned *ret) {
|
||||
unsigned v;
|
||||
int r;
|
||||
|
||||
r = safe_atou(s, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (v < min || v > max)
|
||||
return -ERANGE;
|
||||
|
||||
*ret = v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safe_atoi(const char *s, int *ret_i) {
|
||||
unsigned base = 0;
|
||||
char *x = NULL;
|
||||
|
||||
@@ -30,11 +30,12 @@ int parse_fd(const char *t);
|
||||
#define SAFE_ATO_MASK_FLAGS(base) ((base) & ~SAFE_ATO_ALL_FLAGS)
|
||||
|
||||
int safe_atou_full(const char *s, unsigned base, unsigned *ret_u);
|
||||
|
||||
static inline int safe_atou(const char *s, unsigned *ret_u) {
|
||||
return safe_atou_full(s, 0, ret_u);
|
||||
}
|
||||
|
||||
int safe_atou_bounded(const char *s, unsigned min, unsigned max, unsigned *ret);
|
||||
|
||||
int safe_atoi(const char *s, int *ret_i);
|
||||
int safe_atolli(const char *s, long long int *ret_i);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user