[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250423-nolibc-misc-v1-3-a925bf40297b@linutronix.de>
Date: Wed, 23 Apr 2025 17:01:33 +0200
From: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
To: Willy Tarreau <w@....eu>,
Thomas Weißschuh <linux@...ssschuh.net>,
Shuah Khan <shuah@...nel.org>
Cc: linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
Thomas Weißschuh <thomas.weissschuh@...utronix.de>
Subject: [PATCH 03/15] tools/nolibc: add more stat() variants
Add fstat(), fstatat() and lstat(). All of them use the existing implementation
based on statx().
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
---
tools/include/nolibc/sys/stat.h | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/tools/include/nolibc/sys/stat.h b/tools/include/nolibc/sys/stat.h
index 0eaf5496ce233a4d8b5a239eef5ecefe05a39dd6..53c5c8addc829e36b927c3dd39b2a24f3472dcf0 100644
--- a/tools/include/nolibc/sys/stat.h
+++ b/tools/include/nolibc/sys/stat.h
@@ -14,6 +14,9 @@
/*
* int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf);
* int stat(const char *path, struct stat *buf);
+ * int fstatat(int fd, const char *path, struct stat *buf, int flag);
+ * int fstat(int fildes, struct stat *buf);
+ * int lstat(const char *path, struct stat *buf);
*/
static __attribute__((unused))
@@ -34,12 +37,12 @@ int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *
static __attribute__((unused))
-int stat(const char *path, struct stat *buf)
+int fstatat(int fd, const char *path, struct stat *buf, int flag)
{
struct statx statx;
long ret;
- ret = __sysret(sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx));
+ ret = __sysret(sys_statx(fd, path, flag | AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx));
if (ret == -1)
return ret;
@@ -67,6 +70,24 @@ int stat(const char *path, struct stat *buf)
return 0;
}
+static __attribute__((unused))
+int stat(const char *path, struct stat *buf)
+{
+ return fstatat(AT_FDCWD, path, buf, 0);
+}
+
+static __attribute__((unused))
+int fstat(int fildes, struct stat *buf)
+{
+ return fstatat(fildes, "", buf, AT_EMPTY_PATH);
+}
+
+static __attribute__((unused))
+int lstat(const char *path, struct stat *buf)
+{
+ return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
+}
+
/* make sure to include all global symbols */
#include "../nolibc.h"
--
2.49.0
Powered by blists - more mailing lists