[PATCH v4 03/13] parseopt: make OPT_INTEGER support hexadecimal as well
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
parse-options.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index f0098eb..7c9109d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -139,7 +139,10 @@ static int get_value(struct parse_opt_ctx_t *p,
}
if (get_arg(p, opt, flags, &arg))
return -1;
- *(int *)opt->value = strtol(arg, (char **)&s, 10);
+ if (!prefixcmp(arg, "0x") || !prefixcmp(arg, "0X"))
+ *(int *)opt->value = strtol(arg + 2, (char **)&s, 16);
+ else
+ *(int *)opt->value = strtol(arg, (char **)&s, 10);
if (*s)
return opterror(opt, "expects a numerical value", flags);
return 0;
--
1.7.8.36.g69ee2