diff --git a/ChangeLog b/ChangeLog index 919f34062e..981e047179 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1749,4 +1749,6 @@ configuration for RGMP. RGMP is a project for running GPOS and RTOS simultaneously on multi-processor platforms. See http://rgmp.sourceforge.net/wiki/index.php/Main_Page for further - information about RGMP. \ No newline at end of file + information about RGMP. + * lib/stdio/lib_fclose.c: Must flush all buffered data when the file is closed. + Instead, it was discarding the buffered data. diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index e6c5a824d3..592fff318d 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -8,7 +8,7 @@

NuttX RTOS

-

Last Updated: May 12, 2011

+

Last Updated: May 13, 2011

@@ -2209,6 +2209,13 @@ nuttx-6.3 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> nxbe_colormap was change to nxbe_configure... apparently "search-and-replace" error. This error was not noticed before because most NX platforms do not use colormapping. + * arch/rgmp and configs/rgmp. Add architecture support and build + configuration for RGMP. RGMP is a project for running GPOS and + RTOS simultaneously on multi-processor platforms. See + http://rgmp.sourceforge.net/wiki/index.php/Main_Page for further + information about RGMP. + * lib/stdio/lib_fclose.c: Must flush all buffered data when the file is closed. + Instead, it was discarding the buffered data. apps-6.3 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> @@ -2221,6 +2228,11 @@ apps-6.3 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> then a make error occurs because tools/mkdep.sh is called with no files. * system/free: Move Uros' custom free command from vsn/free * system/install: Add a new install command submitted by Uros Platise. + * examples/rgmpp. Add a placeholder for an RGMP build example. + RGMP is a project for running GPOS and RTOS simultaneously on + multi-processor platforms. See http://rgmp.sourceforge.net/wiki/index.php/Main_Page + for further information about RGMP. NOTE: This is an empty example + on initial check-in. pascal-3.0 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/lib/stdio/lib_fclose.c b/lib/stdio/lib_fclose.c index 8d53b387be..06f970e11e 100644 --- a/lib/stdio/lib_fclose.c +++ b/lib/stdio/lib_fclose.c @@ -50,14 +50,53 @@ * Global Functions ****************************************************************************/ +/**************************************************************************** + * Name: fclose + * + * Description + * The fclose() function will flush the stream pointed to by stream + * (writing any buffered output data using lib_fflush()) and close the + * underlying file descriptor. + * + * Returned Value: + * Upon successful completion 0 is returned. Otherwise, EOF is returned + * and the global variable errno is set to indicate the error. In either + * case any further access (including another call to fclose()) to the + * stream results in undefined behaviour. + * + ****************************************************************************/ + int fclose(FAR FILE *stream) { - int ret = OK; + int err = EINVAL; + int ret = ERROR; + + /* Verify that a stream was provided. */ + if (stream) { + /* Flush the stream */ + + ret = lib_fflush(stream, true); + err = errno; + + /* Close the underlying file descriptor */ + if (stream->fs_filedes > 0) { - ret = close(stream->fs_filedes); + /* Close the file and save the return status */ + + int status = close(stream->fs_filedes); + + /* If close() returns an error but flush() did not then make + * sure that we return the close() error condition. + */ + + if (ret == 0) + { + ret = status; + err = errno; + } } #if CONFIG_STDIO_BUFFER_SIZE > 0 @@ -65,7 +104,7 @@ int fclose(FAR FILE *stream) sem_destroy(&stream->fs_sem); - /* release the buffer */ + /* Release the buffer */ if (stream->fs_bufstart) { @@ -90,6 +129,18 @@ int fclose(FAR FILE *stream) stream->fs_filedes = -1; } - return ret; + /* On an error, reset the errno to the first error encountered and return + * EOF. + */ + + if (ret != OK) + { + set_errno(err); + return EOF; + } + + /* Return success */ + + return OK; }