]> git.ipfire.org Git - pakfire.git/commitdiff
util: Add JSON helper function for unsigned integers
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 04:15:53 +0000 (04:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 04:15:53 +0000 (04:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/util.h
src/libpakfire/package.c
src/libpakfire/util.c

index 41095531ecc12cf17fbef602bb504e6d5fe8e966..c3d7499e239f210b4660cffb82d12a0bc711c760 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_int64(struct json_object* json, const char* name, int64_t value);
+int pakfire_json_add_uint64(struct json_object* json, const char* name, uint64_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);
 
index 41f3a9e858dcb5b1f7a2536d3b9d94b04a4c6486..f77cc873bacaae15673b291148d73a4f0229dd96 100644 (file)
@@ -2459,7 +2459,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Installed package size
        unsigned long long installsize = pakfire_package_get_num(pkg, PAKFIRE_PKG_INSTALLSIZE, 0);
 
-       r = pakfire_json_add_int64(md, "size", (uint64_t)installsize);
+       r = pakfire_json_add_uint64(md, "size", installsize);
        if (r)
                goto ERROR;
 
index 7f4afc438dfecbbde355d0c478ff694d7d92c365..852d7fdfd1bce33ceb2698624ca29c70d9e65344 100644 (file)
@@ -766,6 +766,18 @@ int pakfire_json_add_int64(struct json_object* json, const char* name, int64_t v
        return json_object_object_add(json, name, object);
 }
 
+int pakfire_json_add_uint64(struct json_object* json, const char* name, uint64_t value) {
+       struct json_object* object = NULL;
+
+       // Convert the value to JSON
+       object = json_object_new_uint64(value);
+       if (!object)
+               return -errno;
+
+       // Add the object
+       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;