Add json_object_add_int functions

This commit is contained in:
Juraj Vijtiuk
2017-09-14 08:05:33 -04:00
parent dc79d94c38
commit 1110e84cce
6 changed files with 107 additions and 0 deletions

View File

@@ -666,6 +666,19 @@ int json_object_set_int(struct json_object *jso,int new_value){
return 1;
}
int json_object_add_int(struct json_object *jso, int val) {
if (!jso || jso->o_type != json_type_int)
return 0;
if (val > 0 && jso->o.c_int64 > INT32_MAX - val) {
jso->o.c_int64 = INT32_MAX;
} else if (val < 0 && jso->o.c_int64 < INT32_MIN - val) {
jso->o.c_int64 = INT32_MIN;
} else {
jso->o.c_int64 += val;
}
return 1;
}
struct json_object* json_object_new_int64(int64_t i)
{
@@ -711,6 +724,19 @@ int json_object_set_int64(struct json_object *jso,int64_t new_value){
return 1;
}
int json_object_add_int64(struct json_object *jso, int64_t val) {
if (!jso || jso->o_type != json_type_int)
return 0;
if (val > 0 && jso->o.c_int64 > INT64_MAX - val) {
jso->o.c_int64 = INT64_MAX;
} else if (val < 0 && jso->o.c_int64 < INT64_MIN - val) {
jso->o.c_int64 = INT64_MIN;
} else {
jso->o.c_int64 += val;
}
return 1;
}
/* json_object_double */
#if defined(HAVE___THREAD)