1
0
Fork 0

Merging upstream version 2.12.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-03-20 08:10:44 +01:00
parent 078c0dbcc0
commit 635faa7346
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
571 changed files with 10718 additions and 2738 deletions

View file

@ -4,6 +4,7 @@
#include "json.h"
#include "types.h"
#include "cleanup.h"
struct json_object *util_json_object_new_double(long double d)
{
@ -72,3 +73,65 @@ uint64_t util_json_object_get_uint64(struct json_object *obj)
return val;
}
void json_object_add_uint_02x(struct json_object *o, const char *k, __u32 v)
{
json_object_add_uint_0nx(o, k, v, 2);
}
void json_object_add_uint_0x(struct json_object *o, const char *k, __u32 v)
{
char str[STR_LEN];
sprintf(str, "0x%x", v);
json_object_add_value_string(o, k, str);
}
void json_object_add_byte_array(struct json_object *o, const char *k, unsigned char *buf, int len)
{
int i;
_cleanup_free_ char *value = NULL;
if (!buf || !len) {
json_object_add_value_string(o, k, "No information provided");
return;
}
value = calloc(1, (len + 1) * 2 + 1);
if (!value) {
json_object_add_value_string(o, k, "Could not allocate string");
return;
}
sprintf(value, "0x");
for (i = 1; i <= len; i++)
sprintf(&value[i * 2], "%02x", buf[len - i]);
json_object_add_value_string(o, k, value);
}
void json_object_add_nprix64(struct json_object *o, const char *k, uint64_t v)
{
char str[STR_LEN];
sprintf(str, "%#"PRIx64"", v);
json_object_add_value_string(o, k, str);
}
void json_object_add_uint_0nx(struct json_object *o, const char *k, __u32 v, int width)
{
char str[STR_LEN];
sprintf(str, "0x%0*x", width, v);
json_object_add_value_string(o, k, str);
}
void json_object_add_0nprix64(struct json_object *o, const char *k, uint64_t v, int width)
{
char str[STR_LEN];
sprintf(str, "0x%0*"PRIx64"", width, v);
json_object_add_value_string(o, k, str);
}