summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.c
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 00:42:49 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 00:42:49 -0500
commitccef261c077d31dce02aa92e519b23b3a2a58303 (patch)
tree582fafc98c76e98e912f453fb55ca57f29273d57 /src/basic/parse-util.c
parent5d4922bba91c6d60b3b9f38fb29fda0f6ba8338d (diff)
parent5fb2a20a29c2cc0494d5a31e175a8e3ff0b2d3e2 (diff)
Merge tag 'systemd/v232-4.parabola1' into systemd/parabola
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r--src/basic/parse-util.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index 503a895731..c98815b9bc 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -29,6 +29,7 @@
#include "extract-word.h"
#include "macro.h"
#include "parse-util.h"
+#include "process-util.h"
#include "string-util.h"
int parse_boolean(const char *v) {
@@ -533,7 +534,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;
@@ -546,8 +547,30 @@ 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;
+}
+
+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;
}