Merge pull request #9185 from marckleinebudde/can
networkd: add support to configure CAN devices
This commit is contained in:
@@ -632,6 +632,58 @@ int parse_percent(const char *p) {
|
||||
return v;
|
||||
}
|
||||
|
||||
int parse_permille_unbounded(const char *p) {
|
||||
const char *pc, *pm, *dot, *n;
|
||||
int r, q, v;
|
||||
|
||||
pm = endswith(p, "‰");
|
||||
if (pm) {
|
||||
n = strndupa(p, pm - p);
|
||||
r = safe_atoi(n, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else {
|
||||
pc = endswith(p, "%");
|
||||
if (!pc)
|
||||
return -EINVAL;
|
||||
|
||||
dot = memchr(p, '.', pc - p);
|
||||
if (dot) {
|
||||
if (dot + 2 != pc)
|
||||
return -EINVAL;
|
||||
if (dot[1] < '0' || dot[1] > '9')
|
||||
return -EINVAL;
|
||||
q = dot[1] - '0';
|
||||
n = strndupa(p, dot - p);
|
||||
} else {
|
||||
q = 0;
|
||||
n = strndupa(p, pc - p);
|
||||
}
|
||||
r = safe_atoi(n, &v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (v > ((INT_MAX - q) / 10))
|
||||
return -ERANGE;
|
||||
|
||||
v = v * 10 + q;
|
||||
}
|
||||
|
||||
if (v < 0)
|
||||
return -ERANGE;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
int parse_permille(const char *p) {
|
||||
int v;
|
||||
|
||||
v = parse_permille_unbounded(p);
|
||||
if (v > 1000)
|
||||
return -ERANGE;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
int parse_nice(const char *p, int *ret) {
|
||||
int n, r;
|
||||
|
||||
|
||||
@@ -115,6 +115,9 @@ int parse_fractional_part_u(const char **s, size_t digits, unsigned *res);
|
||||
int parse_percent_unbounded(const char *p);
|
||||
int parse_percent(const char *p);
|
||||
|
||||
int parse_permille_unbounded(const char *p);
|
||||
int parse_permille(const char *p);
|
||||
|
||||
int parse_nice(const char *p, int *ret);
|
||||
|
||||
int parse_ip_port(const char *s, uint16_t *ret);
|
||||
|
||||
Reference in New Issue
Block a user