parse-util: add parse_loadavg_fixed_point
This commit is contained in:
+16
-4
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user