Fix fclose() return value when closing read-only file

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4036 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-10-10 19:40:56 +00:00
parent 4ad3944c1f
commit 61e5093a0b
7 changed files with 41 additions and 19 deletions

View file

@ -2155,4 +2155,8 @@
do not work with R61580 LCD.
* configs/pic32-starterkit: Beginning of a configuratin for the Microchip
PIC32 Ethernet Starter Kit.
* lib/stdio/lib_fclose.c: fclose() always returns an error (EOF) when it
closes a read-only file. This is because it calls flush() which will
fail on read-only files. No harm is done other that a bad value is
returned.

View file

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttX README Files</i></font></big></h1>
<p>Last Updated: September 21, 2011</p>
<p>Last Updated: October 10, 2011</p>
</td>
</tr>
</table>
@ -126,11 +126,12 @@
| | | `- <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/configs/olimex-strp711/README.txt?view=log"><b><i>README.txt</i></b></a>
| | |- pcblogic-pic32mx/
| | | `- <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/configs/pcblogic-pic32mx/README.txt?view=log"><b><i>README.txt</i></b></a>
| | |- pic32-starterkit/
| | | `- <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/configs/pic32-starterkit/README.txt?view=log"><b><i>README.txt</i></b></a>
| | |- pjrc-8051/
| | | |- <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/configs/pjrc-8051/include/README.txt?view=log">include/README.txt</a>
| | | |- <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/configs/pjrc-8051/src/README.txt?view=log">src/README.txt</a>
| | | `- <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/configs/pjrc-8051/README.txt?view=log"><b><i>README.txt</i></b></a>
| | |- qemu-i486/
| | | |- <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/configs/qemu-i486/include/README.txt?view=log">include/README.txt</a>
| | | |- <a href="http://nuttx.svn.sourceforge.net/viewvc/nuttx/trunk/nuttx/configs/qemu-i486/src/README.txt?view=log">src/README.txt</a>

View file

@ -413,6 +413,8 @@ nuttx
| | `- README.txt
| |- pcblogic-pic32mx/
| | `- README.txt
| |- pic32-starterkit/
| | `- README.txt
| |- pjrc-8051/
| | |- include/README.txt
| | |- src/README.txt

View file

@ -97,7 +97,7 @@ void up_irqinitialize(void)
putreg32(0xffff, PIC32MX_INT_IEC0CLR);
putreg32(0xffff, PIC32MX_INT_IEC1CLR);
#ifdef PIC32MX_INT_IEC1CLR
#ifdef PIC32MX_INT_IEC2CLR
putreg32(0xffff, PIC32MX_INT_IEC2CLR);
#endif

View file

@ -1321,7 +1321,14 @@ configs/pcblogic-pic32mx
STATUS: Code complete but testing has been stalled due to tool related problems
(PICkit 2 does not work with the PIC32).
confgis/qemu-i486
configs/pic32-starterkit
This README file discusses the port of NuttX to the Microchip PIC32 Ethernet
Starter Kit (DM320004) with the Multimedia Expansion Board (MEB, DM320005).
Advanced USB Storage. See www.microchip.com for further information.
configs/qemu-i486
Port of NuttX to QEMU in i486 mode. This port will also run on real i486
hardwared (Google the Bifferboard).

View file

@ -2,7 +2,7 @@
* lib/stdio/lib_fclose.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -41,6 +41,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
@ -70,29 +71,36 @@ int fclose(FAR FILE *stream)
{
int err = EINVAL;
int ret = ERROR;
int status;
/* 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)
/* Check that the underlying file descriptor corresponds to an an open
* file.
*/
ret = OK;
if (stream->fs_filedes >= 0)
{
/* Close the file and save the return status */
/* If the stream was opened for writing, then flush the stream */
int status = close(stream->fs_filedes);
if ((stream->fs_oflags & O_WROK) != 0)
{
ret = lib_fflush(stream, true);
err = errno;
}
/* If close() returns an error but flush() did not then make
* sure that we return the close() error condition.
/* Close the underlying file descriptor and save the return status */
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)
if (ret == OK)
{
ret = status;
err = errno;

View file

@ -2,7 +2,7 @@
* lib/stdio/lib_libfflush.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions