git.droids-corp.org
/
libcmdline.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cmdline: support parsing of 64-bit values
[libcmdline.git]
/
src
/
lib
/
cmdline_parse_num.c
diff --git
a/src/lib/cmdline_parse_num.c
b/src/lib/cmdline_parse_num.c
index
1332efc
..
f6eeb8b
100644
(file)
--- 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[] = {
/* 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
#ifdef CMDLINE_HAVE_FLOAT
"FLOAT",
#endif
};
static inline int
-add_to_res(unsigned int c, uint
32
_t *res, unsigned int base)
+add_to_res(unsigned int c, uint
64
_t *res, unsigned int base)
{
/* overflow */
{
/* overflow */
- if ( (UINT
32
_MAX - c) / base < *res ) {
+ if ( (UINT
64
_MAX - c) / base < *res ) {
return -1;
}
return -1;
}
- *res =
*res * base + c
;
+ *res =
(uint64_t) (*res * base + c)
;
return 0;
}
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;
enum num_parse_state_t st = START;
const char * buf = srcbuf;
char c = *buf;
- uint
32
_t res1 = 0;
+ uint
64
_t res1 = 0;
#ifdef CMDLINE_HAVE_FLOAT
#ifdef CMDLINE_HAVE_FLOAT
- uint
32
_t res2 = 0, res3 = 1;
+ uint
64
_t res2 = 0, res3 = 1;
#endif
memcpy(&nd, &((struct cmdline_token_num *)tk)->num_data, sizeof(nd));
#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);
}
*(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)
#ifdef CMDLINE_HAVE_FLOAT
else if ( nd.type == FLOAT ) {
if (res)