Misc generic code changes
Jonathan Larmour
jifl@eCosCentric.com
Mon Mar 15 16:31:00 GMT 2004
Andrew Lunn wrote:
>>+
>>+ // 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
>>+ break;
>>+#else
>>+ break; // no real filesystem, so just go with what we've come up with
>>+#endif
>
>
> Wouldn't it be better to close just the winner and not close all the
> loosers who should have an fd of -1 making the close pointless and a
> waste of time.
Yep, you're right. Done!
Jifl
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/ChangeLog,v
retrieving revision 1.25
diff -u -5 -p -r1.25 ChangeLog
--- ChangeLog 15 Mar 2004 15:21:43 -0000 1.25
+++ ChangeLog 15 Mar 2004 16:31:21 -0000
@@ -1,5 +1,9 @@
+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.
* include/stdio.h:
Index: src/common/fileops.cxx
===================================================================
RCS file:
/cvs/ecos/ecos/packages/language/c/libc/stdio/current/src/common/fileops.cxx,v
retrieving revision 1.1
diff -u -5 -p -r1.1 fileops.cxx
--- src/common/fileops.cxx 15 Mar 2004 15:21:44 -0000 1.1
+++ src/common/fileops.cxx 15 Mar 2004 16:31:21 -0000
@@ -199,12 +199,13 @@ __externC char *tmpnam( char *s ) __THRO
totaliters++;
// 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
#endif
}
Jifl
--
eCosCentric http://www.eCosCentric.com/ The eCos and RedBoot experts
>>>>> Visit us in booth 2527 at the Embedded Systems Conference 2004 <<<<<
March 30 - April 1, San Francisco http://www.esconline.com/electronicaUSA/
--["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine
More information about the Ecos-patches
mailing list