initial check-in, version 0.5.0
[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
11 DIR *opendir(const char *name)
12 {
13         int fd;
14         DIR *dir;
15
16         if ((fd = open(name, O_RDONLY|O_DIRECTORY)) < 0)
17                 return 0;
18         fcntl(fd, F_SETFD, FD_CLOEXEC);
19         if (!(dir = calloc(1, sizeof *dir))) {
20                 close(fd);
21                 return 0;
22         }
23         dir->fd = fd;
24         return dir;
25 }