mirror of
https://github.com/pengutronix/genimage.git
synced 2024-11-23 17:53:52 +08:00
config: allow parsing percentages
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
This commit is contained in:
parent
28152c298b
commit
e2f88d5af0
17
config.c
17
config.c
@ -152,7 +152,22 @@ unsigned long long cfg_getint_suffix(cfg_t *sec, const char *name)
|
||||
unsigned long long val = 0;
|
||||
|
||||
if (str)
|
||||
val = strtoul_suffix(str, NULL, 0);
|
||||
val = strtoul_suffix(str, NULL, NULL);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Like cfg_getint_suffix() but allow '%' as suffix as well
|
||||
*/
|
||||
unsigned long long cfg_getint_suffix_percent(cfg_t *sec, const char *name,
|
||||
cfg_bool_t *percent)
|
||||
{
|
||||
const char *str = cfg_getstr(sec, name);
|
||||
unsigned long long val = 0;
|
||||
|
||||
if (str)
|
||||
val = strtoul_suffix(str, NULL, percent);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -124,7 +124,8 @@ extern struct image_handler fit_handler;
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
void *xzalloc(size_t n);
|
||||
unsigned long long strtoul_suffix(const char *str, char **endp, int base);
|
||||
unsigned long long strtoul_suffix(const char *str, char **endp,
|
||||
cfg_bool_t *percent);
|
||||
|
||||
int init_config(void);
|
||||
cfg_opt_t *get_confuse_opts(void);
|
||||
@ -144,6 +145,8 @@ int insert_data(struct image *image, const char *data, const char *outfile,
|
||||
int reload_partitions(struct image *image);
|
||||
|
||||
unsigned long long cfg_getint_suffix(cfg_t *sec, const char *name);
|
||||
unsigned long long cfg_getint_suffix_percent(cfg_t *sec, const char *name,
|
||||
cfg_bool_t *percent);
|
||||
|
||||
static inline const char *imageoutfile(const struct image *image)
|
||||
{
|
||||
|
14
util.c
14
util.c
@ -251,12 +251,16 @@ void *xzalloc(size_t n)
|
||||
* Like simple_strtoul() but handles an optional G, M, K or k
|
||||
* suffix for Gigabyte, Megabyte or Kilobyte
|
||||
*/
|
||||
unsigned long long strtoul_suffix(const char *str, char **endp, int base)
|
||||
unsigned long long strtoul_suffix(const char *str, char **endp,
|
||||
cfg_bool_t *percent)
|
||||
{
|
||||
unsigned long long val;
|
||||
char *end;
|
||||
|
||||
val = strtoull(str, &end, base);
|
||||
val = strtoull(str, &end, 0);
|
||||
|
||||
if (percent)
|
||||
*percent = cfg_false;
|
||||
|
||||
switch (*end) {
|
||||
case 'G':
|
||||
@ -271,6 +275,12 @@ unsigned long long strtoul_suffix(const char *str, char **endp, int base)
|
||||
end++;
|
||||
case '\0':
|
||||
break;
|
||||
case '%':
|
||||
if (percent) {
|
||||
*percent = cfg_true;
|
||||
break;
|
||||
}
|
||||
/* fall-through */
|
||||
default:
|
||||
error("Invalid size suffix '%s' in '%s'\n", end, str);
|
||||
exit(1);
|
||||
|
Loading…
Reference in New Issue
Block a user