chiark / gitweb /
random-util: always cast from smaller to bigger type when comparing
[elogind.git] / src / basic / parse-util.c
index cfdb29aba0a4f538a6d63358e7014fdab3793c3c..01135596244836f690e31945e1a6e77761cc7734 100644 (file)
@@ -23,9 +23,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#if defined(__GLIBC__)
-#  include <xlocale.h>
-#endif // defined(__GLIBC__)
 
 #include "alloc-util.h"
 //#include "extract-word.h"
@@ -598,3 +595,18 @@ int parse_ip_port(const char *s, uint16_t *ret) {
         return 0;
 }
 #endif // 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;
+}