chiark / gitweb /
tests: add tests for environment serialization
[elogind.git] / src / basic / parse-util.c
index b1cad55e7c1915090ff5f980f3d2ebe8677bdee6..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"
@@ -273,6 +270,7 @@ int parse_range(const char *t, unsigned *lower, unsigned *upper) {
         *upper = u;
         return 0;
 }
+#endif // 0
 
 char *format_bytes(char *buf, size_t l, uint64_t t) {
         unsigned i;
@@ -314,7 +312,6 @@ finish:
         return buf;
 
 }
-#endif // 0
 
 int safe_atou(const char *s, unsigned *ret_u) {
         char *x = NULL;
@@ -581,4 +578,35 @@ int parse_nice(const char *p, int *ret) {
         *ret = n;
         return 0;
 }
+
+int parse_ip_port(const char *s, uint16_t *ret) {
+        uint16_t l;
+        int r;
+
+        r = safe_atou16(s, &l);
+        if (r < 0)
+                return r;
+
+        if (l == 0)
+                return -EINVAL;
+
+        *ret = (uint16_t) l;
+
+        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;
+}