parse-util: introduce parse_dev() helper

This commit is contained in:
Franck Bui
2017-06-06 22:42:35 +02:00
parent 9bfc0df113
commit fbcc7f4168
3 changed files with 30 additions and 0 deletions
+15
View File
@@ -589,3 +589,18 @@ int parse_ip_port(const char *s, uint16_t *ret) {
return 0;
}
int parse_dev(const char *s, dev_t *ret) {
unsigned x, y;
dev_t d;
if (sscanf(s, "%u:%u", &x, &y) != 2)
return -EINVAL;
d = makedev(x, y);
if ((unsigned) major(d) != x || (unsigned) minor(d) != y)
return -EINVAL;
*ret = d;
return 0;
}
+1
View File
@@ -30,6 +30,7 @@
#define MODE_INVALID ((mode_t) -1)
int parse_boolean(const char *v) _pure_;
int parse_dev(const char *s, dev_t *ret);
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);