Thread (29 messages) flat view 29 messages, 1 author, 2016-06-15
STALE3721d

[PATCH v4 03/13] parseopt: make OPT_INTEGER support hexadecimal as well

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:52:55
Subsystem: the rest · Maintainer: Linus Torvalds

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help