summaryrefslogtreecommitdiff
path: root/libc/misc/dirent/opendir.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2006-02-04 02:19:23 +0000
committerMike Frysinger <vapier@gentoo.org>2006-02-04 02:19:23 +0000
commitf4bfb87ce5efc8d6e0794fffa453df6c55e0b7e7 (patch)
treed5ce532b34fd614f5eda74e25e926d8375f2adb5 /libc/misc/dirent/opendir.c
parent772b1913c781e54eeb8f8588bd9b66b4d2d3e4c4 (diff)
use O_DIRECTORY when possible, saves us from having to use stat() thus cutting codesize/race condition
Diffstat (limited to 'libc/misc/dirent/opendir.c')
-rw-r--r--libc/misc/dirent/opendir.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libc/misc/dirent/opendir.c b/libc/misc/dirent/opendir.c
index 6bd1da81d..5c78252b1 100644
--- a/libc/misc/dirent/opendir.c
+++ b/libc/misc/dirent/opendir.c
@@ -7,6 +7,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/dir.h>
@@ -29,13 +30,17 @@ DIR *opendir(const char *name)
char *buf;
DIR *ptr;
+#ifndef O_DIRECTORY
+ /* O_DIRECTORY is linux specific and has been around since like 2.1.x */
if (stat(name, &statbuf))
return NULL;
if (!S_ISDIR(statbuf.st_mode)) {
__set_errno(ENOTDIR);
return NULL;
}
- if ((fd = open(name, O_RDONLY)) < 0)
+# define O_DIRECTORY 0
+#endif
+ if ((fd = open(name, O_RDONLY|O_NDELAY|O_DIRECTORY)) < 0)
return NULL;
/* According to POSIX, directory streams should be closed when
* exec. From "Anna Pluzhnikov" <besp@midway.uchicago.edu>.