diff options
author | dota17 <chenguopingdota@163.com> | 2020-02-20 15:17:05 +0800 |
---|---|---|
committer | dota17 <chenguopingdota@163.com> | 2020-02-25 14:51:35 +0800 |
commit | 3c3b5920f77c751471cd46b92f9d3f5aa6ff2557 (patch) | |
tree | 72950e90387b3a90163162c71c37c92f416e8f1e /json_util.c | |
parent | 518f337ce81317525eb2ca1d11eac2b68a4b227c (diff) | |
download | json-c-3c3b5920f77c751471cd46b92f9d3f5aa6ff2557.tar.gz |
add uint64 data to json-c
Diffstat (limited to 'json_util.c')
-rw-r--r-- | json_util.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/json_util.c b/json_util.c index 3ff631d..8902d31 100644 --- a/json_util.c +++ b/json_util.c @@ -40,8 +40,9 @@ #ifdef WIN32 # if MSC_VER < 1800 -/* strtoll is available only since Visual Studio 2013 */ +/* strtoll/strtoull is available only since Visual Studio 2013 */ # define strtoll _strtoi64 +# define strtoull _strtoui64 # endif # define WIN32_LEAN_AND_MEAN # include <windows.h> @@ -230,6 +231,23 @@ int json_parse_int64(const char *buf, int64_t *retval) return ((val == 0 && errno != 0) || (end == buf)) ? 1 : 0; } +int json_parse_uint64(const char *buf, uint64_t *retval) +{ + char *end = NULL; + uint64_t val; + errno = 1; + + while (*buf == ' ') { + buf++; + } + if (*buf == '-') errno = 0; + + val = strtoull(buf, &end, 10); + if (end != buf) + *retval = val; + return ((errno == 0) || (end == buf)) ? 1 : 0; +} + #ifndef HAVE_REALLOC void* rpl_realloc(void* p, size_t n) { @@ -248,6 +266,7 @@ static const char* json_type_name[] = { "boolean", "double", "int", + "uint", "object", "array", "string", |