about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Jaeger <aj@suse.de>2011-08-20 09:12:49 -0400
committerAndreas Schwab <schwab@redhat.com>2011-09-07 11:43:38 +0200
commitfcec7096abfa39c586068fd0dd0e32fd1a7255b0 (patch)
tree64f97776fcd75eb0cc5d128c33e9f5a1b08bd3b3
parent9ddfa2b9adc84fd8318a3303f66e19f66e9d3084 (diff)
downloadglibc-fcec7096abfa39c586068fd0dd0e32fd1a7255b0.tar.gz
glibc-fcec7096abfa39c586068fd0dd0e32fd1a7255b0.tar.xz
glibc-fcec7096abfa39c586068fd0dd0e32fd1a7255b0.zip
Fix fopen (non-existing-file, "re") errno
(cherry picked from commit a101b025af141e956feb04042ee75e28997c0011)
-rw-r--r--ChangeLog6
-rw-r--r--libio/fileops.c24
2 files changed, 17 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 264d7255fd..e3021f900f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-08-19  Andreas Jaeger  <aj@suse.de>
+
+	[BZ #13114]
+	* libio/fileops.c (_IO_new_file_fopen): Fix handling of
+	non-existant file when using close-on-exec mode.
+
 2011-08-20  Ulrich Drepper  <drepper@gmail.com>
 
 	* sysdeps/x86_64/dl-trampoline.S (_dl_runtime_resolve): Fix CFI for
diff --git a/libio/fileops.c b/libio/fileops.c
index 30de460391..a6f7cbad82 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -345,23 +345,22 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
   result = _IO_file_open (fp, filename, omode|oflags, oprot, read_write,
 			  is32not64);
 
-#ifndef __ASSUME_O_CLOEXEC
-  if ((fp->_flags2 & _IO_FLAGS2_CLOEXEC) != 0 && __have_o_cloexec <= 0)
+  if (result != NULL)
     {
-      int fd = _IO_fileno (fp);
-      if (__have_o_cloexec == 0)
+#ifndef __ASSUME_O_CLOEXEC
+      if ((fp->_flags2 & _IO_FLAGS2_CLOEXEC) != 0 && __have_o_cloexec <= 0)
 	{
-	  int flags = __fcntl (fd, F_GETFD);
-	  __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
+	  int fd = _IO_fileno (fp);
+	  if (__have_o_cloexec == 0)
+	    {
+	      int flags = __fcntl (fd, F_GETFD);
+	      __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
+	    }
+	  if (__have_o_cloexec < 0)
+	    __fcntl (fd, F_SETFD, FD_CLOEXEC);
 	}
-      if (__have_o_cloexec < 0)
-	__fcntl (fd, F_SETFD, FD_CLOEXEC);
-    }
 #endif
 
-#ifdef _LIBC
-  if (result != NULL)
-    {
       /* Test whether the mode string specifies the conversion.  */
       cs = strstr (last_recognized + 1, ",ccs=");
       if (cs != NULL)
@@ -432,7 +431,6 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
 	  result->_mode = 1;
 	}
     }
-#endif	/* GNU libc */
 
   return result;
 }