2 * This file contains the ini and command liner parser main.
14 static unsigned long get_mult_time(char c)
31 static unsigned long get_mult_bytes(char c)
42 return 1024 * 1024 * 1024;
49 * convert string after '=' into decimal value, noting any size suffix
51 static int str_to_decimal(char *p, unsigned long long *val, int kilo)
63 *val = strtoul(str, NULL, 10);
64 if (*val == ULONG_MAX && errno == ERANGE)
68 *val *= get_mult_bytes(str[len - 1]);
70 *val *= get_mult_time(str[len - 1]);
74 int check_str_bytes(char *p, char *name, unsigned long long *val)
76 if (strncmp(p, name, strlen(name) - 1))
79 return str_to_decimal(p, val, 1);
82 int check_str_time(char *p, char *name, unsigned long long *val)
84 if (strncmp(p, name, strlen(name) - 1))
87 return str_to_decimal(p, val, 0);
90 void strip_blank_front(char **p)
98 void strip_blank_end(char *p)
100 char *s = p + strlen(p) - 1;
102 while (isspace(*s) || iscntrl(*s))
108 int check_str(char *p, char *name, str_cb_fn *cb, void *data)
112 if (strncmp(p, name, strlen(name)))
124 strip_blank_front(&s);
128 int check_strstore(char *p, char *name, char *dest)
132 if (strncmp(p, name, strlen(name)))
144 strip_blank_front(&s);
150 static int __check_range_bytes(char *str, unsigned long *val)
154 if (sscanf(str, "%lu%c", val, &suffix) == 2) {
155 *val *= get_mult_bytes(suffix);
159 if (sscanf(str, "%lu", val) == 1)
165 int check_range_bytes(char *p, char *name, unsigned long *s, unsigned long *e)
170 if (strncmp(p, name, strlen(name)))
176 str = strstr(p, name);
182 str = strchr(p, '=');
187 * 'p' now holds whatever is after the '=' sign
192 * terminate p1 at the '-' sign
201 if (!__check_range_bytes(p1, s) && !__check_range_bytes(p2, e))
207 int check_int(char *p, char *name, unsigned int *val)
211 if (strncmp(p, name, strlen(name)))
214 str = strstr(p, name);
218 str = strchr(p, '=');
224 if (sscanf(str, "%u", val) == 1)
230 int check_strset(char *p, char *name)
232 return strncmp(p, name, strlen(name));