]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: add wrapers for statx(2)
authorMasatake YAMATO <yamato@redhat.com>
Thu, 8 Jan 2026 21:57:45 +0000 (06:57 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 12 Jan 2026 18:39:31 +0000 (03:39 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
include/path.h
lib/path.c

index 7f86b775ba8771a2cd2b4522aa37ccb915e85b1b..60a6162df518052bcfe904f750594d7c8dbb4782 100644 (file)
@@ -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)));
index 67527f5e9f09ca975221d4826af9f5d47151cd4f..7edc2079bfc4c47066727298dc0367c8d6d8a32a 100644 (file)
@@ -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)
 {