parse-util: introduce parse_ifindex() and make use of it everywhere

We have enough places where we parse an ifindex, hence introduce a
proper parsing function for it, that verifies all parameters.
This commit is contained in:
Lennart Poettering
2015-11-03 00:02:00 +01:00
parent 6a37c68469
commit 6ad623a3f7
8 changed files with 22 additions and 18 deletions
+13
View File
@@ -81,6 +81,19 @@ int parse_mode(const char *s, mode_t *ret) {
return 0;
}
int parse_ifindex(const char *s, int *ret) {
int ifi, r;
r = safe_atoi(s, &ifi);
if (r < 0)
return r;
if (ifi <= 0)
return -EINVAL;
*ret = ifi;
return 0;
}
int parse_size(const char *t, uint64_t base, uint64_t *size) {
/* Soo, sometimes we want to parse IEC binary suffixes, and
+1
View File
@@ -31,6 +31,7 @@
int parse_boolean(const char *v) _pure_;
int parse_pid(const char *s, pid_t* ret_pid);
int parse_mode(const char *s, mode_t *ret);
int parse_ifindex(const char *s, int *ret);
int parse_size(const char *t, uint64_t base, uint64_t *size);
int parse_range(const char *t, unsigned *lower, unsigned *upper);