#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-//#include <xlocale.h>
+#if defined(__GLIBC__)
+# include <xlocale.h>
+#endif // defined(__GLIBC__)
#include "alloc-util.h"
//#include "extract-word.h"
return 0;
}
+
+int parse_percent(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;
+ if (v > 100)
+ return -ERANGE;
+
+ return (int) v;
+}