refactor headers, especially alltypes.h, and improve C++ ABI compat
[musl] / src / dirent / opendir.c
1 #define _GNU_SOURCE
2 #include <dirent.h>
3 #include <fcntl.h>
4 #include <sys/stat.h>
5 #include <errno.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <limits.h>
9 #include "__dirent.h"
10 #include "syscall.h"
11
12 DIR *opendir(const char *name)
13 {
14         int fd;
15         DIR *dir;
16
17         if ((fd = open(name, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) < 0)
18                 return 0;
19         if (!(dir = calloc(1, sizeof *dir))) {
20                 __syscall(SYS_close, fd);
21                 return 0;
22         }
23         dir->fd = fd;
24         return dir;
25 }