From 61e5093a0b751e1bcf281c4e8290dbb126d416cb Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 10 Oct 2011 19:40:56 +0000 Subject: [PATCH] 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 --- ChangeLog | 4 ++++ Documentation/README.html | 5 ++-- README.txt | 2 ++ arch/mips/src/pic32mx/pic32mx-irq.c | 2 +- configs/README.txt | 9 +++++++- lib/stdio/lib_fclose.c | 36 ++++++++++++++++++----------- lib/stdio/lib_libfflush.c | 2 +- 7 files changed, 41 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index c91093852f..5c8b5c5353 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/Documentation/README.html b/Documentation/README.html index 2cd1908c43..c8b740c23d 100755 --- a/Documentation/README.html +++ b/Documentation/README.html @@ -8,7 +8,7 @@

NuttX README Files

-

Last Updated: September 21, 2011

+

Last Updated: October 10, 2011

@@ -126,11 +126,12 @@ | | | `- README.txt | | |- pcblogic-pic32mx/ | | | `- README.txt + | | |- pic32-starterkit/ + | | | `- README.txt | | |- pjrc-8051/ | | | |- include/README.txt | | | |- src/README.txt | | | `- README.txt - | | |- qemu-i486/ | | | |- include/README.txt | | | |- src/README.txt diff --git a/README.txt b/README.txt index fe94337c48..63f78cd213 100755 --- a/README.txt +++ b/README.txt @@ -413,6 +413,8 @@ nuttx | | `- README.txt | |- pcblogic-pic32mx/ | | `- README.txt + | |- pic32-starterkit/ + | | `- README.txt | |- pjrc-8051/ | | |- include/README.txt | | |- src/README.txt diff --git a/arch/mips/src/pic32mx/pic32mx-irq.c b/arch/mips/src/pic32mx/pic32mx-irq.c index 75f7367ff9..98c554c784 100644 --- a/arch/mips/src/pic32mx/pic32mx-irq.c +++ b/arch/mips/src/pic32mx/pic32mx-irq.c @@ -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 diff --git a/configs/README.txt b/configs/README.txt index c18bde3210..f19fa28eea 100644 --- a/configs/README.txt +++ b/configs/README.txt @@ -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). diff --git a/lib/stdio/lib_fclose.c b/lib/stdio/lib_fclose.c index 06f970e11e..8cecb8af3c 100644 --- a/lib/stdio/lib_fclose.c +++ b/lib/stdio/lib_fclose.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fclose.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -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; diff --git a/lib/stdio/lib_libfflush.c b/lib/stdio/lib_libfflush.c index 3e9de538ab..ddfc6c8ff6 100644 --- a/lib/stdio/lib_libfflush.c +++ b/lib/stdio/lib_libfflush.c @@ -2,7 +2,7 @@ * lib/stdio/lib_libfflush.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions