about summary refs log tree commit diff
path: root/sysdeps/unix/opendir.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-10-13 15:12:27 +0000
committerUlrich Drepper <drepper@redhat.com>1998-10-13 15:12:27 +0000
commit99e46354d96d9dc70c7b5ae7ed1a3d7ff0dbb77f (patch)
treecc97f13ce989554a0bd4f67c1fbcb3982e99fac6 /sysdeps/unix/opendir.c
parent1622fda9c034eb332f27453d6458ea6d30b119c0 (diff)
downloadglibc-99e46354d96d9dc70c7b5ae7ed1a3d7ff0dbb77f.tar.gz
glibc-99e46354d96d9dc70c7b5ae7ed1a3d7ff0dbb77f.tar.xz
glibc-99e46354d96d9dc70c7b5ae7ed1a3d7ff0dbb77f.zip
Update.
1998-10-13  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c: Include
	string.h to get memcpy prototype and NULL definition.

1998-10-12  Andreas Schwab  <schwab@issan.cs.uni-dortmund.de>

	* misc/sys/cdefs.h (__THROW): New macro.
	* argp/argp.h: Use it to replace the kludgey __P in inline
	function definitions.
	* sysdeps/unix/sysv/linux/bits/socket.h: Likewise.
	* stdlib/stdlib.h: Likewise.
	* wcsmbs/wchar.h: Likewise.
	* libio/stdio.h: Likewise.
	* stdio/stdio.h: Likewise.
	* sysdeps/wordsize-64/inttypes.h: Likewise.
	* sysdeps/wordsize-32/inttypes.h: Likewise.
	* string/argz.h: Likewise.
	* io/sys/stat.h: Likewise.

1998-10-12  Andreas Schwab  <schwab@issan.cs.uni-dortmund.de>

	* Rules (stdio_lim): New variable.
	($(stdio_lim:h=st)): Use this as intermediate stamp file, depend
	on Rules and config.make, use $(move-if-change) to avoid unnessary
	recompilations, and cleanup command.
	(common-generated): Add bits/stdio_lim.st.
Diffstat (limited to 'sysdeps/unix/opendir.c')
-rw-r--r--sysdeps/unix/opendir.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/sysdeps/unix/opendir.c b/sysdeps/unix/opendir.c
index ef7bc84866..4df06ed7b8 100644
--- a/sysdeps/unix/opendir.c
+++ b/sysdeps/unix/opendir.c
@@ -47,6 +47,17 @@ __opendir (const char *name)
       return NULL;
     }
 
+  /* 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)
+    return NULL;
+  if (! S_ISDIR (statbuf.st_mode))
+    {
+      __set_errno (ENOTDIR);
+      return NULL;
+    }
+
   fd = __open (name, O_RDONLY|O_NDELAY);
   if (fd < 0)
     return NULL;
@@ -54,14 +65,6 @@ __opendir (const char *name)
   if (__fcntl (fd, F_SETFD, FD_CLOEXEC) < 0)
     goto lose;
 
-  if (fstat (fd, &statbuf) < 0)
-    goto lose;
-  if (! S_ISDIR (statbuf.st_mode))
-    {
-      save_errno = ENOTDIR;
-      goto lose2;
-    }
-
 #ifdef _STATBUF_ST_BLKSIZE
   if (statbuf.st_blksize < sizeof (struct dirent))
     allocation = sizeof (struct dirent);