about summary refs log tree commit diff
path: root/sysdeps/unix/opendir.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-05-08 00:48:30 -0400
committerUlrich Drepper <drepper@gmail.com>2011-05-08 00:48:30 -0400
commit28377d1bf58625172a1734b92e835591d4d23a18 (patch)
tree4a05343e1493965e45971e6f3a7d5566da23596f /sysdeps/unix/opendir.c
parent66bdbaa4522f561d4ea90a77af243c004ecf642c (diff)
downloadglibc-28377d1bf58625172a1734b92e835591d4d23a18.tar.gz
glibc-28377d1bf58625172a1734b92e835591d4d23a18.tar.xz
glibc-28377d1bf58625172a1734b92e835591d4d23a18.zip
Optimize fdopendir a bit.
Don't call fcntl(F_SETFD) unnecessarily.
Diffstat (limited to 'sysdeps/unix/opendir.c')
-rw-r--r--sysdeps/unix/opendir.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/sysdeps/unix/opendir.c b/sysdeps/unix/opendir.c
index fbf14f5eec..c2d1ddaf88 100644
--- a/sysdeps/unix/opendir.c
+++ b/sysdeps/unix/opendir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-1996,98,2000-2003,2005,2007,2009
+/* Copyright (C) 1991-1996,98,2000-2003,2005,2007,2009,2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -138,7 +138,7 @@ __opendir (const char *name)
       statp = &statbuf;
     }
 
-  return __alloc_dir (fd, true, statp);
+  return __alloc_dir (fd, true, 0, statp);
 }
 weak_alias (__opendir, opendir)
 
@@ -158,13 +158,14 @@ check_have_o_cloexec (int fd)
 
 DIR *
 internal_function
-__alloc_dir (int fd, bool close_fd, const struct stat64 *statp)
+__alloc_dir (int fd, bool close_fd, int flags, const struct stat64 *statp)
 {
   /* We always have to set the close-on-exit flag if the user provided
      the file descriptor.  Otherwise only if we have no working
      O_CLOEXEC support.  */
 #ifdef O_CLOEXEC
-  if (! close_fd || ! check_have_o_cloexec (fd))
+  if ((! close_fd && (flags & O_CLOEXEC) == 0)
+      || ! check_have_o_cloexec (fd))
 #endif
     {
       if (__builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0)