changeset 1546:b6cb710a33b6

* src/common/fileops.cxx (tmpnam): Only close if open() succeded.
author jlarmour
date Mon, 15 Mar 2004 16:31:57 +0000
parents 40a7aad7873c
children 008dfd864e5e
files packages/language/c/libc/stdio/current/ChangeLog packages/language/c/libc/stdio/current/src/common/fileops.cxx
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/packages/language/c/libc/stdio/current/ChangeLog
+++ b/packages/language/c/libc/stdio/current/ChangeLog
@@ -1,3 +1,7 @@
+2004-03-15  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* src/common/fileops.cxx (tmpnam): Only close if open() succeded.
+
 2004-03-12  Jonathan Larmour  <jifl@eCosCentric.com>
 
 	* src/input/vfscanf.cxx (vfscanf): Silence warning.
--- a/packages/language/c/libc/stdio/current/src/common/fileops.cxx
+++ b/packages/language/c/libc/stdio/current/src/common/fileops.cxx
@@ -201,8 +201,9 @@ CYG_MACRO_END
         // s now points to a name candidate
 #ifdef CYGPKG_LIBC_STDIO_FILEIO
         int fd = open( s, O_RDONLY );
-        close(fd);
-        if (fd < 0 && ENOENT == errno) // we have a winner
+        if (fd >= 0)
+            close(fd);
+        else if ( ENOENT == errno ) // we have a winner
             break;
 #else
         break; // no real filesystem, so just go with what we've come up with