]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Update.
authorUlrich Drepper <drepper@redhat.com>
Mon, 19 Oct 1998 16:30:28 +0000 (16:30 +0000)
committerUlrich Drepper <drepper@redhat.com>
Mon, 19 Oct 1998 16:30:28 +0000 (16:30 +0000)
1998-10-19  Ulrich Drepper  <drepper@cygnus.com>

* sysdeps/unix/opendir.c (__opendir): Add back fstat call to make
sure that descriptor is in any case for a directory.

ChangeLog
sysdeps/unix/opendir.c

index 13e3a1793b759151fce8ea8124055f20f4584e3d..c02c3a78ccc5336011e1e8b34e1837c09076c628 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+1998-10-19  Ulrich Drepper  <drepper@cygnus.com>
+
+       * sysdeps/unix/opendir.c (__opendir): Add back fstat call to make
+       sure that descriptor is in any case for a directory.
+
 1998-10-19 18:59 -0400  Zack Weinberg  <zack@rabi.phys.columbia.edu>
 
        * math/tgmath.h (__TGMATH_UNARY_REAL_IMAG): Fix typo: val -> Val.
index 657ad176a8823178643ffdd72a9976bdf7ebaac1..067dc2cb59bedac970ca2503ff9524714aae4110 100644 (file)
 #include <dirstream.h>
 
 
-/* We want to be really safe the file we opened is a directory.  Some systems
-   have support for this, others don't.  */
-#ifdef O_DIRECTORY
-# define OPENDIR(NAME) \
-  do {                                                                       \
-    fd = __open (NAME, O_RDONLY|O_NDELAY|O_DIRECTORY);                       \
-    if (fd < 0)                                                                      \
-      return NULL;                                                           \
-  } while (0)
-#else
-# define OPENDIR(NAME) \
-  do {                                                                       \
-    fd = __open (NAME, O_RDONLY|O_NDELAY);                                   \
-    if (fd < 0 || __fstat (fd, &statbuf) < 0 || ! S_ISDIR (statbuf.st_mode))  \
-      {                                                                              \
-       if (fd >= 0)                                                          \
-         __close (fd);                                                       \
-       return NULL;                                                          \
-      }                                                                              \
-  } while (0)
+#ifndef O_DIRECTORY
+# define O_DIRECTORY   0
 #endif
 
 
@@ -74,7 +56,7 @@ __opendir (const char *name)
   /* We first have to check whether the name is for a directory.  We
      cannot do this after the open() call since the open/close operation
      performed on, say, a tape device might have undesirable effects.  */
-  if (stat (name, &statbuf) < 0)
+  if (__stat (name, &statbuf) < 0)
     return NULL;
   if (! S_ISDIR (statbuf.st_mode))
     {
@@ -82,7 +64,19 @@ __opendir (const char *name)
       return NULL;
     }
 
-  OPENDIR (name);
+  fd = __open (name, O_RDONLY|O_NDELAY|O_DIRECTORY);
+  if (fd < 0)
+    return NULL;
+
+  /* Now make sure this really is a directory and nothing changed since
+     the `stat' call.  */
+  if (__fstat (fd, &statbuf) < 0)
+    goto lose;
+  if (! S_ISDIR (statbuf.st_mode))
+    {
+      save_errno = ENOTDIR;
+      goto lose;
+    }
 
   if (__fcntl (fd, F_SETFD, FD_CLOEXEC) < 0)
     goto lose;