From 1a45153e46297451d7a79c4708d823ff64c8c514 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 13 May 2024 21:01:16 +0200 Subject: [PATCH] lib/path: introduce ul_path_vreadf_buffer MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Weißschuh --- include/path.h | 2 ++ lib/path.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/path.h b/include/path.h index 4c84dd31f..f413ea3f9 100644 --- a/include/path.h +++ b/include/path.h @@ -95,6 +95,8 @@ int ul_path_readf_string(struct path_cxt *pc, char **str, const char *path, ...) int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path); int ul_path_readf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...) __attribute__ ((__format__ (__printf__, 4, 5))); +int ul_path_vreadf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, va_list ap) + __attribute__ ((__format__ (__printf__, 4, 0))); int ul_path_scanf(struct path_cxt *pc, const char *path, const char *fmt, ...) __attribute__ ((__format__ (__scanf__, 3, 4))); diff --git a/lib/path.c b/lib/path.c index 6381cc5d8..6a70ad45f 100644 --- a/lib/path.c +++ b/lib/path.c @@ -701,16 +701,25 @@ int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char return rc; } -int ul_path_readf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...) +int ul_path_vreadf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, va_list ap) { const char *p; + + p = ul_path_mkpath(pc, path, ap); + + return !p ? -errno : ul_path_read_buffer(pc, buf, bufsz, p); +} + +int ul_path_readf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...) +{ va_list ap; + int rc; va_start(ap, path); - p = ul_path_mkpath(pc, path, ap); + rc = ul_path_vreadf_buffer(pc, buf, bufsz, path, ap); va_end(ap); - return !p ? -errno : ul_path_read_buffer(pc, buf, bufsz, p); + return rc; } int ul_path_scanf(struct path_cxt *pc, const char *path, const char *fmt, ...) -- 2.47.3