From: Michael Tremer Date: Sun, 15 Sep 2024 04:15:53 +0000 (+0000) Subject: util: Add JSON helper function for unsigned integers X-Git-Tag: 0.9.30~1187 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2792185f54b33300d2bdea7be6db85134310bce2;p=pakfire.git util: Add JSON helper function for unsigned integers Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 41095531e..c3d7499e2 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_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); diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 41f3a9e85..f77cc873b 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -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; diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 7f4afc438..852d7fdfd 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -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;