Skip to content
Snippets Groups Projects
Commit 61e5093a authored by patacongo's avatar patacongo
Browse files

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
parent 4ad3944c
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......@@ -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>
......
......@@ -413,6 +413,8 @@ nuttx
| | `- README.txt
| |- pcblogic-pic32mx/
| | `- README.txt
| |- pic32-starterkit/
| | `- README.txt
| |- pjrc-8051/
| | |- include/README.txt
| | |- src/README.txt
......
......@@ -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
......
......@@ -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).
......
......@@ -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;
/* Check that the underlying file descriptor corresponds to an an open
* file.
*/
ret = OK;
if (stream->fs_filedes >= 0)
{
/* If the stream was opened for writing, then flush the stream */
/* Close the underlying file descriptor */
if ((stream->fs_oflags & O_WROK) != 0)
{
ret = lib_fflush(stream, true);
err = errno;
}
if (stream->fs_filedes > 0)
{
/* Close the file and save the return status */
/* Close the underlying file descriptor and save the return status */
int status = close(stream->fs_filedes);
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 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;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment