about summary refs log tree commit diff
path: root/sysdeps/unix
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-10-14 21:11:09 +0000
committerUlrich Drepper <drepper@redhat.com>2005-10-14 21:11:09 +0000
commit18b8e054cf34f78f100b74b37e54673730530249 (patch)
tree9a05507b0557ed4c0b7f08549903e069d026f863 /sysdeps/unix
parentf9126cc23e355dcad375942312e7068b44740d6c (diff)
downloadglibc-18b8e054cf34f78f100b74b37e54673730530249.tar.gz
glibc-18b8e054cf34f78f100b74b37e54673730530249.tar.xz
glibc-18b8e054cf34f78f100b74b37e54673730530249.zip
* sysdeps/unix/opendir.c (__opendir): Pass extra argument to
	__alloc_dir.
	(__alloc_dir): Only close descriptor on error if new parameter is true.
	* sysdeps/unix/fdopendir.c (fdopendir): Pass extra argument to
	__alloc_dir.  Don't close fd on error.
	* include/dirent.h (__alloc_dir): Adjust prototype.

	* include/sys/mman.h (__mremap): Add ellipsis.
	* malloc/memusage.c: Adjust mremap wrapper for optional additional
	parameter.
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/fdopendir.c6
-rw-r--r--sysdeps/unix/opendir.c13
2 files changed, 10 insertions, 9 deletions
diff --git a/sysdeps/unix/fdopendir.c b/sysdeps/unix/fdopendir.c
index 3c481fcf0d..ef6c97c308 100644
--- a/sysdeps/unix/fdopendir.c
+++ b/sysdeps/unix/fdopendir.c
@@ -29,14 +29,12 @@ fdopendir (int fd)
   struct stat64 statbuf;
 
   if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0)
-    goto out;
+    return NULL;
   if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0))
     {
       __set_errno (ENOTDIR);
-    out:
-      close_not_cancel_no_status (fd);
       return NULL;
     }
 
-  return __alloc_dir (fd, &statbuf);
+  return __alloc_dir (fd, false, &statbuf);
 }
diff --git a/sysdeps/unix/opendir.c b/sysdeps/unix/opendir.c
index 366670b79c..98fb4ca5c8 100644
--- a/sysdeps/unix/opendir.c
+++ b/sysdeps/unix/opendir.c
@@ -132,14 +132,14 @@ __opendir (const char *name)
 	}
     }
 
-  return __alloc_dir (fd, &statbuf);
+  return __alloc_dir (fd, true, &statbuf);
 }
 weak_alias (__opendir, opendir)
 
 
 DIR *
 internal_function
-__alloc_dir (int fd, struct stat64 *statp)
+__alloc_dir (int fd, bool close_fd, struct stat64 *statp)
 {
   if (__builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0)
     goto lose;
@@ -160,9 +160,12 @@ __alloc_dir (int fd, struct stat64 *statp)
   if (dirp == NULL)
   lose:
     {
-      int save_errno = errno;
-      close_not_cancel_no_status (fd);
-      __set_errno (save_errno);
+      if (close_fd)
+	{
+	  int save_errno = errno;
+	  close_not_cancel_no_status (fd);
+	  __set_errno (save_errno);
+	}
       return NULL;
     }
   memset (dirp, '\0', sizeof (DIR));