about summary refs log tree commit diff
path: root/sysdeps/unix
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/opendir.c19
-rw-r--r--sysdeps/unix/sysv/linux/bits/socket.h2
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c1
3 files changed, 13 insertions, 9 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);
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index 47d70611f1..30ba59fc57 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -200,7 +200,7 @@ struct cmsghdr
 extern struct cmsghdr *__cmsg_nxthdr __P ((struct msghdr *__mhdr,
 					   struct cmsghdr *__cmsg));
 _EXTERN_INLINE struct cmsghdr *
-__cmsg_nxthdr __P ((struct msghdr *__mhdr, struct cmsghdr *__cmsg))
+__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg) __THROW
 {
   if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
     /* The kernel header does this so there may be a reason.  */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c b/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c
index ae44328fad..e18ffa818d 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c
@@ -18,6 +18,7 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+#include <string.h>
 #include <syscall.h>
 #include <sys/signal.h>
 #include <errno.h>