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;
}