From: Thomas Weißschuh Date: Mon, 13 May 2024 19:01:16 +0000 (+0200) Subject: lib/path: introduce ul_path_vreadf_buffer X-Git-Tag: v2.42-start~344 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1a45153e46297451d7a79c4708d823ff64c8c514;p=thirdparty%2Futil-linux.git lib/path: introduce ul_path_vreadf_buffer Signed-off-by: Thomas Weißschuh --- 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, ...)