diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-10-06 14:15:47 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2020-10-06 16:04:14 +0200 |
commit | 27fbc658293db97775385f6cc54a36bf0d6c454d (patch) | |
tree | c841aa74578c0656a0b725a3d0943e8fffc80cec /src/json.c | |
parent | d89d6c6ce749f0d7dd89e3f6fabe2772f01b8b41 (diff) |
#941 Add og_json_parse_string_copy(...) function
This function provides an easy way to copy the content of a json string
into a regular C string.
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -18,6 +18,21 @@ int og_json_parse_string(json_t *element, const char **str) return 0; } +int og_json_parse_string_copy(json_t *element, char *str, size_t size) +{ + const char *reference_str; + int err = 0; + + err = og_json_parse_string(element, &reference_str); + if (err != 0) + return err; + + err = snprintf(str, size, "%s", reference_str); + if (err >= size) + return -1; + return 0; +} + int og_json_parse_uint64(json_t *element, uint64_t *integer) { if (json_typeof(element) != JSON_INTEGER) |