chiark / gitweb /
Allow braceless variables to be expanded
[elogind.git] / src / basic / parse-util.c
index 90bae7149559ee6001bf25b69341fd1da765b583..2daa797a5025dc888f8f764d589944e905498f12 100644 (file)
@@ -33,6 +33,9 @@
 #include "parse-util.h"
 #include "string-util.h"
 
+/// Additional includes needed by elogind
+#include "musl_missing.h"
+
 int parse_boolean(const char *v) {
         assert(v);
 
@@ -537,7 +540,7 @@ int parse_fractional_part_u(const char **p, size_t digits, unsigned *res) {
         return 0;
 }
 
-int parse_percent(const char *p) {
+int parse_percent_unbounded(const char *p) {
         const char *pc, *n;
         unsigned v;
         int r;
@@ -550,8 +553,48 @@ int parse_percent(const char *p) {
         r = safe_atou(n, &v);
         if (r < 0)
                 return r;
+
+        return (int) v;
+}
+
+int parse_percent(const char *p) {
+        int v;
+
+        v = parse_percent_unbounded(p);
         if (v > 100)
                 return -ERANGE;
 
-        return (int) v;
+        return v;
+}
+
+#if 0 /// UNNEEDED by elogind
+int parse_nice(const char *p, int *ret) {
+        int n, r;
+
+        r = safe_atoi(p, &n);
+        if (r < 0)
+                return r;
+
+        if (!nice_is_valid(n))
+                return -ERANGE;
+
+        *ret = n;
+        return 0;
+}
+#endif // 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;
 }