[PATCH v3 2/3] tools/nolibc: Add dirfd()
From: Daniel Palmer
Date: Sat Oct 31 2026 - 00:30:41 EST
This is useful for things like fstatat() on children of a directory
opened with opendir().
Signed-off-by: Daniel Palmer <daniel@xxxxxxxxx>
---
tools/include/nolibc/dirent.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h
index 7666dc69506f..76331ed65560 100644
--- a/tools/include/nolibc/dirent.h
+++ b/tools/include/nolibc/dirent.h
@@ -74,6 +74,19 @@ DIR *opendir(const char *name)
return (DIR *)(intptr_t)~fd;
}
+static __attribute__((unused))
+int dirfd(DIR *dirp)
+{
+ int fd = __nolibc_dirfd(dirp);
+
+ if (fd < 0) {
+ SET_ERRNO(EINVAL);
+ return -1;
+ }
+
+ return fd;
+}
+
static __attribute__((unused))
int closedir(DIR *dirp)
{
--
2.53.0