From: Michael Tremer Date: Sun, 15 Sep 2024 04:12:09 +0000 (+0000) Subject: util: Add new helper function to add double values to JSON objects X-Git-Tag: 0.9.30~1189 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5111f88798a5c94473dab2f0105e1ee176658201;p=pakfire.git util: Add new helper function to add double values to JSON objects Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 2661fca2a..701b1375a 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -90,6 +90,7 @@ struct json_object* pakfire_json_parse(struct pakfire_ctx* ctx, struct json_object* pakfire_json_parse_from_file(struct pakfire_ctx* ctx, const char* path); int pakfire_json_add_string(struct json_object* json, const char* name, const char* value); int pakfire_json_add_integer(struct json_object* json, const char* name, int64_t value); +int pakfire_json_add_double(struct json_object* json, const char* name, double value); int pakfire_json_add_string_array(struct json_object* json, const char* name, char** array); // Resource Limits diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 79962526b..406d5d937 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -767,6 +767,18 @@ int pakfire_json_add_integer(struct json_object* json, return json_object_object_add(json, name, object); } +int pakfire_json_add_double(struct json_object* json, const char* name, double value) { + struct json_object* object = NULL; + + // Convert the value to JSON + object = json_object_new_double(value); + if (!object) + return -errno; + + // Add the object + return json_object_object_add(json, name, object); +} + // Resource Limits int pakfire_rlimit_set(struct pakfire* pakfire, int limit) {