From: Karel Zak Date: Thu, 2 May 2024 13:56:29 +0000 (+0200) Subject: lib/path: add ul_path_statf() and ul_path_vstatf() X-Git-Tag: v2.42-start~354^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f962f511dfbdd446b4e93a77792b3413b5539c2;p=thirdparty%2Futil-linux.git lib/path: add ul_path_statf() and ul_path_vstatf() Signed-off-by: Karel Zak (cherry picked from commit 9b47899495e229ace482afca9e14b9b95ef6fde9) --- diff --git a/include/path.h b/include/path.h index e523f1781..4c84dd31f 100644 --- a/include/path.h +++ b/include/path.h @@ -53,6 +53,9 @@ char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const ch __attribute__ ((__format__ (__printf__, 4, 5))); int ul_path_stat(struct path_cxt *pc, struct stat *sb, int flags, const char *path); +int ul_path_vstatf(struct path_cxt *pc, struct stat *sb, int flags, const char *path, va_list ap); +int ul_path_statf(struct path_cxt *pc, struct stat *sb, int flags, const char *path, ...); + int ul_path_access(struct path_cxt *pc, int mode, const char *path); int ul_path_accessf(struct path_cxt *pc, int mode, const char *path, ...) __attribute__ ((__format__ (__printf__, 3, 4))); diff --git a/lib/path.c b/lib/path.c index 202f19ac4..fec20187f 100644 --- a/lib/path.c +++ b/lib/path.c @@ -370,6 +370,25 @@ int ul_path_stat(struct path_cxt *pc, struct stat *sb, int flags, const char *pa return rc; } +int ul_path_vstatf(struct path_cxt *pc, struct stat *sb, int flags, const char *path, va_list ap) +{ + const char *p = ul_path_mkpath(pc, path, ap); + + return !p ? -errno : ul_path_stat(pc, sb, flags, p); +} + +int ul_path_statf(struct path_cxt *pc, struct stat *sb, int flags, const char *path, ...) +{ + va_list ap; + int rc; + + va_start(ap, path); + rc = ul_path_vstatf(pc, sb, flags, path, ap); + va_end(ap); + + return rc; +} + int ul_path_open(struct path_cxt *pc, int flags, const char *path) { int fd;