#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-//#include <xlocale.h>
#include "alloc-util.h"
//#include "extract-word.h"
#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);
*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;
s = *p;
/* accept any number of digits, strtoull is limted to 19 */
- for(i=0; i < digits; i++,s++) {
+ for (i=0; i < digits; i++,s++) {
if (*s < '0' || *s > '9') {
if (i == 0)
return -EINVAL;
return 0;
}
+
+int parse_percent_unbounded(const char *p) {
+ const char *pc, *n;
+ unsigned v;
+ int r;
+
+ pc = endswith(p, "%");
+ if (!pc)
+ return -EINVAL;
+
+ n = strndupa(p, pc - 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 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;
+}
+
+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