From: Masatake YAMATO Date: Thu, 8 Jan 2026 21:57:45 +0000 (+0900) Subject: lib/path: add wrapers for statx(2) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f55c1c092add6bea2fc34e61e4b85651934c26cc;p=thirdparty%2Futil-linux.git lib/path: add wrapers for statx(2) Signed-off-by: Masatake YAMATO --- diff --git a/include/path.h b/include/path.h index 7f86b775b..60a6162df 100644 --- a/include/path.h +++ b/include/path.h @@ -58,6 +58,16 @@ int ul_path_vstatf(struct path_cxt *pc, struct stat *sb, int flags, const char * int ul_path_statf(struct path_cxt *pc, struct stat *sb, int flags, const char *path, ...) __attribute__ ((__format__ (__printf__, 4, 5))); +#ifndef HAVE_STATX_H +struct statx; +#endif /* HAVE_STATX_H */ +int ul_path_statx(struct path_cxt *pc, struct statx *stx, int flags, unsigned int mask, + const char *path); +int ul_path_vstatxf(struct path_cxt *pc, struct statx *stx, int flags, unsigned int mask, + const char *path, va_list ap) __attribute__ ((__format__ (__printf__, 5, 0))); +int ul_path_statxf(struct path_cxt *pc, struct statx *stx, int flags, unsigned int mask, + const char *path, ...) __attribute__ ((__format__ (__printf__, 5, 6))); + 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 67527f5e9..7edc2079b 100644 --- a/lib/path.c +++ b/lib/path.c @@ -388,6 +388,60 @@ int ul_path_statf(struct path_cxt *pc, struct stat *sb, int flags, const char *p return rc; } +#ifdef HAVE_STATX +int ul_path_statx(struct path_cxt *pc, struct statx *stx, int flags, unsigned int mask, + const char *path) +{ + int rc; + + if (!pc) + rc = path ? statx(AT_FDCWD, path, flags, mask, stx) : - EINVAL; + else { + int dir = ul_path_get_dirfd(pc); + if (dir < 0) + return dir; + if (path) { + if (*path == '/') + path++; + } + + rc = statx(dir, path, flags, mask, stx); + } + + return rc; +} +#else +int ul_path_statx(struct path_cxt *pc __attribute__((__unused__)), + struct statx *stx __attribute__((__unused__)), + int flags __attribute__((__unused__)), + unsigned int mask __attribute__((__unused__)), + const char *path __attribute__((__unused__))) +{ + errno = ENOSYS; + return -1; +} +#endif /* HAVE_STATX */ + +int ul_path_vstatxf(struct path_cxt *pc, struct statx *stx, int flags, unsigned int mask, + const char *path, va_list ap) +{ + const char *p = ul_path_mkpath(pc, path, ap); + + return !p ? -errno : ul_path_statx(pc, stx, flags, mask, p); +} + +int ul_path_statxf(struct path_cxt *pc, struct statx *stx, int flags, unsigned int mask, + const char *path, ...) +{ + va_list ap; + int rc; + + va_start(ap, path); + rc = ul_path_vstatxf(pc, stx, flags, mask, path, ap); + va_end(ap); + + return rc; +} int ul_path_open(struct path_cxt *pc, int flags, const char *path) {