summaryrefslogtreecommitdiff
path: root/src/dirent/opendir.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dirent/opendir.c')
-rw-r--r--src/dirent/opendir.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/dirent/opendir.c b/src/dirent/opendir.c
index 3e1d1c87..98a5df54 100644
--- a/src/dirent/opendir.c
+++ b/src/dirent/opendir.c
@@ -1,10 +1,34 @@
#include <dirent.h>
-#include "stddef.h"
+#include "errno.h"
+#include "sys/types.h"
+#include "stdlib.h"
+#include "fcntl.h"
+#include "_dirent.h"
+
+#ifndef O_DIRECTORY
+#define O_DIRECTORY O_RDONLY
+#endif
+
+#ifndef O_SEARCH
+#define O_SEARCH O_RDONLY
+#endif
DIR * opendir(const char * dirname)
{
- (void)dirname;
- return NULL;
+ DIR *dir = malloc(sizeof(*dir));
+ if (dir == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ dir->fd = open(dirname, O_DIRECTORY | O_SEARCH);
+ if (dir->fd == -1) {
+ free(dir);
+ return NULL;
+ }
+ fcntl(dir->fd, F_SETFD, FD_CLOEXEC);
+
+ return dir;
}
/*