From: Olivier Matz Date: Sun, 2 Jan 2011 20:34:00 +0000 (+0100) Subject: cmdline: support parsing of 64-bit values X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e5ca055e8b19eaa2335d554357f04e4a6fddb38a;p=libcmdline.git cmdline: support parsing of 64-bit values Signed-off-by: Ivan Boule --- diff --git a/src/lib/cmdline_parse_num.c b/src/lib/cmdline_parse_num.c index 1332efc..f6eeb8b 100644 --- a/src/lib/cmdline_parse_num.c +++ b/src/lib/cmdline_parse_num.c @@ -102,22 +102,22 @@ enum num_parse_state_t { /* Keep it sync with enum in .h */ static const char * num_help[] = { - "UINT8", "UINT16", "UINT32", - "INT8", "INT16", "INT32", + "UINT8", "UINT16", "UINT32", "UINT64", + "INT8", "INT16", "INT32", "INT64", #ifdef CMDLINE_HAVE_FLOAT "FLOAT", #endif }; static inline int -add_to_res(unsigned int c, uint32_t *res, unsigned int base) +add_to_res(unsigned int c, uint64_t *res, unsigned int base) { /* overflow */ - if ( (UINT32_MAX - c) / base < *res ) { + if ( (UINT64_MAX - c) / base < *res ) { return -1; } - *res = *res * base + c ; + *res = (uint64_t) (*res * base + c); return 0; } @@ -130,9 +130,9 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) enum num_parse_state_t st = START; const char * buf = srcbuf; char c = *buf; - uint32_t res1 = 0; + uint64_t res1 = 0; #ifdef CMDLINE_HAVE_FLOAT - uint32_t res2 = 0, res3 = 1; + uint64_t res2 = 0, res3 = 1; #endif memcpy(&nd, &((struct cmdline_token_num *)tk)->num_data, sizeof(nd)); @@ -389,6 +389,11 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) *(uint32_t *)res = (uint32_t) res1; return (buf-srcbuf); } + else if ( nd.type == UINT64 ) { + if (res) + *(uint64_t *)res = res1; + return (buf-srcbuf); + } #ifdef CMDLINE_HAVE_FLOAT else if ( nd.type == FLOAT ) { if (res) diff --git a/src/lib/cmdline_parse_num.h b/src/lib/cmdline_parse_num.h index 7e47a65..26a0d40 100644 --- a/src/lib/cmdline_parse_num.h +++ b/src/lib/cmdline_parse_num.h @@ -68,9 +68,11 @@ enum cmdline_numtype { UINT8 = 0, UINT16, UINT32, + UINT64, INT8, INT16, - INT32 + INT32, + INT64 #ifndef NO_PARSE_FLOAT ,FLOAT #endif