mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
common: add routine to get double from JSON.
I don't like it, but we do expose some times like this :( Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Alex Myers
parent
eb6b8551d4
commit
9589ea0240
@@ -101,6 +101,22 @@ bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num)
|
||||
return json_to_u64(buffer, &temp, num);
|
||||
}
|
||||
|
||||
bool json_to_double(const char *buffer, const jsmntok_t *tok, double *num)
|
||||
{
|
||||
char *end;
|
||||
|
||||
errno = 0;
|
||||
*num = strtod(buffer + tok->start, &end);
|
||||
if (end != buffer + tok->end)
|
||||
return false;
|
||||
|
||||
/* Check for overflow */
|
||||
if (errno == ERANGE)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool json_to_u32(const char *buffer, const jsmntok_t *tok, u32 *num)
|
||||
{
|
||||
uint64_t u64;
|
||||
|
||||
Reference in New Issue
Block a user