diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-11-02 23:57:21 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-11-03 00:02:00 +0100 |
commit | 6ad623a3f77e087e308f334525fd4046811f2a9a (patch) | |
tree | 1030c9d7eb6e88cc605c36ed50901d4527a4fcf1 /src/basic/parse-util.c | |
parent | 6a37c684695befff2d2ce7e0fcce90e25e2e252c (diff) |
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.
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r-- | src/basic/parse-util.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 1ee5783680..b6358c459a 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -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 |