]> git.ipfire.org Git - pakfire.git/commitdiff
util: Add new helper function to add double values to JSON objects
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 04:12:09 +0000 (04:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 04:12:09 +0000 (04:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/util.h
src/libpakfire/util.c

index 2661fca2aca38932ca8a3c0d5d0cdcd041da44d1..701b1375a0ac8f77f861605fcbfde970b0b73fce 100644 (file)
@@ -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
index 79962526b3dccb25cd007c53fb925da1dc5d978b..406d5d937e5219b62fd7dd11e332a72fa47de3c9 100644 (file)
@@ -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) {