json: add va_arg versions for write_string and write_named_string
Change-Id: I22ca6db43f797d9e615208b251923d9ce61acec6 Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-on: https://review.gerrithub.io/401024 Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
This commit is contained in:
parent
488e6418a5
commit
a5cfd43036
@ -225,6 +225,8 @@ int spdk_json_write_string_utf16le_raw(struct spdk_json_write_ctx *w, const uint
|
||||
|
||||
int spdk_json_write_string_fmt(struct spdk_json_write_ctx *w, const char *fmt,
|
||||
...) __attribute__((__format__(__printf__, 2, 3)));
|
||||
int spdk_json_write_string_fmt_v(struct spdk_json_write_ctx *w, const char *fmt, va_list args);
|
||||
|
||||
int spdk_json_write_array_begin(struct spdk_json_write_ctx *w);
|
||||
int spdk_json_write_array_end(struct spdk_json_write_ctx *w);
|
||||
int spdk_json_write_object_begin(struct spdk_json_write_ctx *w);
|
||||
@ -251,6 +253,9 @@ int spdk_json_write_named_int64(struct spdk_json_write_ctx *w, const char *name,
|
||||
int spdk_json_write_named_string(struct spdk_json_write_ctx *w, const char *name, const char *val);
|
||||
int spdk_json_write_named_string_fmt(struct spdk_json_write_ctx *w, const char *name,
|
||||
const char *fmt, ...) __attribute__((__format__(__printf__, 3, 4)));
|
||||
int spdk_json_write_named_string_fmt_v(struct spdk_json_write_ctx *w, const char *name,
|
||||
const char *fmt, va_list args);
|
||||
|
||||
int spdk_json_write_named_array_begin(struct spdk_json_write_ctx *w, const char *name);
|
||||
int spdk_json_write_named_object_begin(struct spdk_json_write_ctx *w, const char *name);
|
||||
|
||||
|
@ -431,14 +431,23 @@ spdk_json_write_string_utf16le(struct spdk_json_write_ctx *w, const uint16_t *va
|
||||
int
|
||||
spdk_json_write_string_fmt(struct spdk_json_write_ctx *w, const char *fmt, ...)
|
||||
{
|
||||
char *s;
|
||||
va_list args;
|
||||
int rc;
|
||||
|
||||
va_start(args, fmt);
|
||||
s = spdk_vsprintf_alloc(fmt, args);
|
||||
rc = spdk_json_write_string_fmt_v(w, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_json_write_string_fmt_v(struct spdk_json_write_ctx *w, const char *fmt, va_list args)
|
||||
{
|
||||
char *s;
|
||||
int rc;
|
||||
|
||||
s = spdk_vsprintf_alloc(fmt, args);
|
||||
if (s == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -631,18 +640,28 @@ int spdk_json_write_named_string(struct spdk_json_write_ctx *w, const char *name
|
||||
int spdk_json_write_named_string_fmt(struct spdk_json_write_ctx *w, const char *name,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
char *s;
|
||||
va_list args;
|
||||
int rc;
|
||||
|
||||
va_start(args, fmt);
|
||||
rc = spdk_json_write_named_string_fmt_v(w, name, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int spdk_json_write_named_string_fmt_v(struct spdk_json_write_ctx *w, const char *name,
|
||||
const char *fmt, va_list args)
|
||||
{
|
||||
char *s;
|
||||
int rc;
|
||||
|
||||
rc = spdk_json_write_name(w, name);
|
||||
if (rc) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
va_start(args, fmt);
|
||||
s = spdk_vsprintf_alloc(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
if (s == NULL) {
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user