summaryrefslogtreecommitdiff
path: root/tools/include/nolibc/dirent.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/include/nolibc/dirent.h')
-rw-r--r--tools/include/nolibc/dirent.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h
index 4e02ef25e72d..2dbf4052b85a 100644
--- a/tools/include/nolibc/dirent.h
+++ b/tools/include/nolibc/dirent.h
@@ -30,10 +30,23 @@ typedef struct {
static __attribute__((unused))
DIR *fdopendir(int fd)
{
+ struct stat buf;
+ int ret;
+
if (fd < 0) {
SET_ERRNO(EBADF);
return NULL;
}
+
+ ret = fstat(fd, &buf);
+ if (ret < 0)
+ return NULL;
+
+ if (!S_ISDIR(buf.st_mode)) {
+ SET_ERRNO(ENOTDIR);
+ return NULL;
+ }
+
return (DIR *)(intptr_t)~fd;
}
@@ -42,10 +55,11 @@ DIR *opendir(const char *name)
{
int fd;
- fd = open(name, O_RDONLY);
+ fd = open(name, O_RDONLY | O_DIRECTORY);
if (fd == -1)
return NULL;
- return fdopendir(fd);
+
+ return (DIR *)(intptr_t)~fd;
}
static __attribute__((unused))