Merging upstream version 2.14.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
0d9181726f
commit
f268303a51
572 changed files with 4636 additions and 1730 deletions
16
util/json.c
16
util/json.c
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "json.h"
|
||||
#include "types.h"
|
||||
|
@ -135,3 +136,18 @@ void json_object_add_0nprix64(struct json_object *o, const char *k, uint64_t v,
|
|||
sprintf(str, "0x%0*"PRIx64"", width, v);
|
||||
json_object_add_value_string(o, k, str);
|
||||
}
|
||||
|
||||
void json_object_add_string(struct json_object *o, const char *k, const char *format, ...)
|
||||
{
|
||||
_cleanup_free_ char *value = NULL;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
if (vasprintf(&value, format, ap) < 0)
|
||||
value = NULL;
|
||||
|
||||
json_object_add_value_string(o, k, value ? value : "Could not allocate string");
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue