#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"
*upper = u;
return 0;
}
+#endif // 0
char *format_bytes(char *buf, size_t l, uint64_t t) {
unsigned i;
return buf;
}
-#endif // 0
int safe_atou(const char *s, unsigned *ret_u) {
char *x = NULL;
*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;
+}