about summary refs log tree commit diff
path: root/sysdeps/unix/fdopendir.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-01-20 21:12:34 +0000
committerUlrich Drepper <drepper@redhat.com>2006-01-20 21:12:34 +0000
commita4f17630670ecf9177b370f9edca4020c5e4131d (patch)
tree025a64a57e0a5e04d1dfb3a09fa4c96671a38d06 /sysdeps/unix/fdopendir.c
parent437d7853496eb27ab7c8c3eb7e9315c4b810c6db (diff)
downloadglibc-a4f17630670ecf9177b370f9edca4020c5e4131d.tar.gz
glibc-a4f17630670ecf9177b370f9edca4020c5e4131d.tar.xz
glibc-a4f17630670ecf9177b370f9edca4020c5e4131d.zip
* sysdeps/unix/fdopendir.c (fdopendir): If O_DIRECTORY is
	available, avoid stat call, use fcntl result to determine whether
	descriptor is for a directory or not.
	* dirent/Makefile (tests): Add tst-fdopendir2.
	* dirent/tst-fdopendir2.c: New file.
Diffstat (limited to 'sysdeps/unix/fdopendir.c')
-rw-r--r--sysdeps/unix/fdopendir.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/sysdeps/unix/fdopendir.c b/sysdeps/unix/fdopendir.c
index 23d08fd7fd..b586e58ca4 100644
--- a/sysdeps/unix/fdopendir.c
+++ b/sysdeps/unix/fdopendir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -29,6 +29,7 @@ fdopendir (int fd)
 {
   struct stat64 statbuf;
 
+#ifndef O_DIRECTORY
   if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0)
     return NULL;
   if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0))
@@ -36,10 +37,20 @@ fdopendir (int fd)
       __set_errno (ENOTDIR);
       return NULL;
     }
-  /* Make sure the descriptor allows for reading.  */
+#endif
+
+  /* Make sure the descriptor allows for reading (and eventually that
+     the descriptor is for a directory).  */
   int flags = __fcntl (fd, F_GETFL);
   if (__builtin_expect (flags == -1, 0))
     return NULL;
+#ifdef O_DIRECTORY
+  if (__builtin_expect ((flags & O_DIRECTORY) == 0, 0))
+    {
+      __set_errno (ENOTDIR);
+      return NULL;
+    }
+#endif
   if (__builtin_expect ((flags & O_ACCMODE) == O_WRONLY, 0))
     {
       __set_errno (EINVAL);