From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/dirent/opendir.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/dirent/opendir.c (limited to 'src/dirent/opendir.c') diff --git a/src/dirent/opendir.c b/src/dirent/opendir.c new file mode 100644 index 0000000..5cb84e3 --- /dev/null +++ b/src/dirent/opendir.c @@ -0,0 +1,21 @@ +#define _GNU_SOURCE +#include +#include +#include +#include "__dirent.h" +#include "syscall.h" + +DIR *opendir(const char *name) +{ + int fd; + DIR *dir; + + if ((fd = open(name, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) < 0) + return 0; + if (!(dir = calloc(1, sizeof *dir))) { + __syscall(SYS_close, fd); + return 0; + } + dir->fd = fd; + return dir; +} -- cgit v1.2.3