#define _GNU_SOURCE #include #include #include #include #include #include #include #include "__dirent.h" DIR *opendir(const char *name) { int fd; DIR *dir; if ((fd = open(name, O_RDONLY|O_DIRECTORY)) < 0) return 0; fcntl(fd, F_SETFD, FD_CLOEXEC); if (!(dir = calloc(1, sizeof *dir))) { close(fd); return 0; } dir->fd = fd; return dir; }