diff options
author | Thomas Weißschuh <thomas.weissschuh@linutronix.de> | 2025-04-28 14:40:04 +0200 |
---|---|---|
committer | Thomas Weißschuh <linux@weissschuh.net> | 2025-05-21 15:32:02 +0200 |
commit | 2337d39f7233fc3fb9d90489f0d48904eb129a2e (patch) | |
tree | babafe494118a0adb671dbceddbb79467568039d /tools/include | |
parent | 7a7cd445d9275be8e4650d390156595685c3ac03 (diff) |
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@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-3-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Diffstat (limited to 'tools/include')
-rw-r--r-- | tools/include/nolibc/sys/stat.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/tools/include/nolibc/sys/stat.h b/tools/include/nolibc/sys/stat.h index 987c8bb52502..8b4d80e3ea03 100644 --- a/tools/include/nolibc/sys/stat.h +++ b/tools/include/nolibc/sys/stat.h @@ -17,6 +17,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)) @@ -37,12 +40,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; @@ -70,4 +73,22 @@ 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); +} + #endif /* _NOLIBC_SYS_STAT_H */ |