mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 21:33:02 +02:00
confd: Add wrapper for sr_set_item
This allows the xpath to be built using format string.
This commit is contained in:
committed by
Joachim Wiberg
parent
2259e108e4
commit
54200eaba9
@@ -3,6 +3,28 @@
|
||||
#include <stdarg.h>
|
||||
#include "core.h"
|
||||
|
||||
int srx_set_item(sr_session_ctx_t *session, const sr_val_t *val, sr_edit_options_t opts,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
char *xpath;
|
||||
va_list ap;
|
||||
size_t len;
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = vsnprintf(NULL, 0, fmt, ap) + 1;
|
||||
va_end(ap);
|
||||
|
||||
xpath = alloca(len);
|
||||
if (!val)
|
||||
return -1;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(xpath, len, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return sr_set_item(session, xpath, val, opts);
|
||||
}
|
||||
|
||||
int lydx_new_path(const struct ly_ctx *ctx, struct lyd_node **parent, int *first,
|
||||
char *xpath_base, char *node, const char *fmt, ...)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#define SRX_GET_UINT8(s,v,fmt,...) srx_get_int(s, &v, SR_UINT8_T, fmt, ##__VA_ARGS__)
|
||||
#define SRX_GET_UINT32(s,v,fmt,...) srx_get_int(s, &v, SR_UINT32_T, fmt, ##__VA_ARGS__)
|
||||
|
||||
int srx_set_item(sr_session_ctx_t *session, const sr_val_t *val, sr_edit_options_t opts,
|
||||
const char *fmt, ...) __attribute__ ((format (printf, 4, 5)));
|
||||
int lydx_new_path(const struct ly_ctx *ctx, struct lyd_node **parent, int *first, char *xpath_base,
|
||||
char *node, const char *fmt, ...);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user