summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.h
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2020-06-04 02:13:29 -0700
committerAnita Zhang <the.anitazha@gmail.com>2020-10-07 16:17:24 -0700
commit510ca79cf2443bba5089f34e1fec2466cf5312ac (patch)
treea2701a5bfb07973a0f2e876a8191fde963fb3741 /src/basic/parse-util.h
parente30bbc90c9c2b12792894dbef877d7d96371cbda (diff)
downloadsystemd-510ca79cf2443bba5089f34e1fec2466cf5312ac.tar.gz
parse-util: add parse_loadavg_fixed_point
Diffstat (limited to 'src/basic/parse-util.h')
-rw-r--r--src/basic/parse-util.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h
index 2cee65c49a..f22a19c5c6 100644
--- a/src/basic/parse-util.h
+++ b/src/basic/parse-util.h
@@ -3,12 +3,15 @@
#include <inttypes.h>
#include <limits.h>
+#include <linux/loadavg.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include "macro.h"
+typedef unsigned long loadavg_t;
+
int parse_boolean(const char *v) _pure_;
int parse_dev(const char *s, dev_t *ret);
int parse_pid(const char *s, pid_t* ret_pid);
@@ -88,18 +91,18 @@ static inline int safe_atoux64(const char *s, uint64_t *ret) {
}
#if LONG_MAX == INT_MAX
-static inline int safe_atolu(const char *s, unsigned long *ret_u) {
+static inline int safe_atolu_full(const char *s, unsigned base, long unsigned *ret_u) {
assert_cc(sizeof(unsigned long) == sizeof(unsigned));
- return safe_atou(s, (unsigned*) ret_u);
+ return safe_atou_full(s, base, (unsigned*) ret_u);
}
static inline int safe_atoli(const char *s, long int *ret_u) {
assert_cc(sizeof(long int) == sizeof(int));
return safe_atoi(s, (int*) ret_u);
}
#else
-static inline int safe_atolu(const char *s, unsigned long *ret_u) {
+static inline int safe_atolu_full(const char *s, unsigned base, unsigned long *ret_u) {
assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
- return safe_atollu(s, (unsigned long long*) ret_u);
+ return safe_atollu_full(s, base, (unsigned long long*) ret_u);
}
static inline int safe_atoli(const char *s, long int *ret_u) {
assert_cc(sizeof(long int) == sizeof(long long int));
@@ -107,6 +110,10 @@ static inline int safe_atoli(const char *s, long int *ret_u) {
}
#endif
+static inline int safe_atolu(const char *s, unsigned long *ret_u) {
+ return safe_atolu_full(s, 0, ret_u);
+}
+
#if SIZE_MAX == UINT_MAX
static inline int safe_atozu(const char *s, size_t *ret_u) {
assert_cc(sizeof(size_t) == sizeof(unsigned));
@@ -137,3 +144,8 @@ int parse_ip_port_range(const char *s, uint16_t *low, uint16_t *high);
int parse_ip_prefix_length(const char *s, int *ret);
int parse_oom_score_adjust(const char *s, int *ret);
+
+/* Given a Linux load average (e.g. decimal number 34.89 where 34 is passed as i and 89 is passed as f), convert it
+ * to a loadavg_t. */
+int store_loadavg_fixed_point(unsigned long i, unsigned long f, loadavg_t *ret);
+int parse_loadavg_fixed_point(const char *s, loadavg_t *ret);