summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-03-31 09:39:10 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-03-31 09:39:10 -0600
commitd32187047743c8cd8ecf76ba06cd71ca8ff9e04d (patch)
treebab40f053f1d13464c39c9eac2f93cda0882e760
parentdf394c157f4a0f7e82efa15f873cfe5a05daabae (diff)
downloadnuttx-d32187047743c8cd8ecf76ba06cd71ca8ff9e04d.tar.gz
nuttx-d32187047743c8cd8ecf76ba06cd71ca8ff9e04d.tar.bz2
nuttx-d32187047743c8cd8ecf76ba06cd71ca8ff9e04d.zip
Complete fragmentary support for ferror(). From Macs N
-rw-r--r--nuttx/ChangeLog4
-rw-r--r--nuttx/TODO19
-rw-r--r--nuttx/libc/stdio/lib_ferror.c16
-rw-r--r--nuttx/libc/stdio/lib_fread.c3
-rw-r--r--nuttx/libc/stdio/lib_libfflush.c9
-rw-r--r--nuttx/libc/stdio/lib_libfread.c5
-rw-r--r--nuttx/libc/stdio/lib_libfwrite.c18
7 files changed, 28 insertions, 46 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 6957d7b9a..9a439dcb5 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -7089,4 +7089,6 @@
return EOF if no values were converted (2014-3-30).
* include/time.h and sched/clock_settime(): Add support for
CLOCK_REALTIME. From Macs N (2014-3-31).
-
+ * libc/stdio/lib_ferror.c, lib_fread.c, lib_libfflush.c,
+ lib_libfread.c, and lib_libfwrite.c: Finish incomplete support
+ for ferror(). From Macs N (2014-3-14).
diff --git a/nuttx/TODO b/nuttx/TODO
index 0a1272e9f..275c7e759 100644
--- a/nuttx/TODO
+++ b/nuttx/TODO
@@ -17,7 +17,7 @@ nuttx/
(6) Binary loaders (binfmt/)
(17) Network (net/, drivers/net)
(4) USB (drivers/usbdev, drivers/usbhost)
- (11) Libraries (libc/, )
+ (10) Libraries (libc/, )
(12) File system/Generic drivers (fs/, drivers/)
(5) Graphics subystem (graphics/)
(1) Pascal add-on (pcode/)
@@ -1099,23 +1099,6 @@ o Libraries (libc/)
Status: Open
Priority: Low
- Title: FERROR()
- Description: ferror(), feof(), and clearerror() are present, but the
- implementation of ferror() is limited. There are flags in the
- stream structure to indicate EOF and error conditions but nothing
- in the code currently sets the error indication. This is a
- trivial change to many interfaces and has not yet been done.
- Instead, for now, ferror() is equivalent to !feof(). If an
- interface can failure because of an error or and EOF and you
- only want to distinguish between an error and the EOF then
- this ferror() will work. However, if no error is reported then
- this ferror() cannot tell you if an error has occurred or not.
- Status: Open
- Priority: Meidum to Low: Some applications use ferror() and not the
- return value to determine if an error occurred. Those
- applications will fail with this limited implementation of
- ferror().
-
Title: CONCURRENT STREAM READ/WRITE
Description: NuttX only supports a single file pointer so reads and writes
must be from the same position. This prohibits implementation
diff --git a/nuttx/libc/stdio/lib_ferror.c b/nuttx/libc/stdio/lib_ferror.c
index a977394cb..4d324c808 100644
--- a/nuttx/libc/stdio/lib_ferror.c
+++ b/nuttx/libc/stdio/lib_ferror.c
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/stdio/lib_ferror.c
*
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -64,26 +64,12 @@
int ferror(FILE *stream)
{
-#if 0
/* If an error is encountered by any of the C-buffered I/O functions, they
* should set the __FS_FLAG_ERROR in the fs_flags field of struct
* file_struct.
*/
return (stream->fs_flags & __FS_FLAG_ERROR) != 0;
-#else
- /* However, nothing currenlty sets the __FS_FLAG_ERROR flag (that is a job
- * for another day). The __FS_FLAG_EOF is set by operations that perform
- * read operations. Since ferror() is probably only called to disambiguate
- * the meaning of other functions that return EOF, to indicate either EOF or
- * an error, just testing for not EOF is probably sufficient for now.
- *
- * This approach would not work if ferror() is called in other contexts. In
- * those cases, ferror() will always report an error.
- */
-
- return (stream->fs_flags & __FS_FLAG_EOF) == 0;
-#endif
}
#endif /* CONFIG_NFILE_STREAMS */
diff --git a/nuttx/libc/stdio/lib_fread.c b/nuttx/libc/stdio/lib_fread.c
index 4cdc19c0b..3bfac6995 100644
--- a/nuttx/libc/stdio/lib_fread.c
+++ b/nuttx/libc/stdio/lib_fread.c
@@ -45,7 +45,7 @@
#include "lib_internal.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/****************************************************************************
@@ -95,5 +95,6 @@ size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream)
items_read = bytes_read / size;
}
+
return items_read;
}
diff --git a/nuttx/libc/stdio/lib_libfflush.c b/nuttx/libc/stdio/lib_libfflush.c
index 07b230b54..842de018a 100644
--- a/nuttx/libc/stdio/lib_libfflush.c
+++ b/nuttx/libc/stdio/lib_libfflush.c
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/stdio/lib_libfflush.c
*
- * Copyright (C) 2007-2008, 2011-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2008, 2011-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -34,10 +34,6 @@
****************************************************************************/
/****************************************************************************
- * Compilation Switches
- ****************************************************************************/
-
-/****************************************************************************
* Included Files
****************************************************************************/
@@ -54,7 +50,7 @@
#include "lib_internal.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/****************************************************************************
@@ -157,6 +153,7 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
* returned the negated errno value.
*/
+ stream->fs_flags |= __FS_FLAG_ERROR;
lib_give_semaphore(stream);
return -get_errno();
}
diff --git a/nuttx/libc/stdio/lib_libfread.c b/nuttx/libc/stdio/lib_libfread.c
index 08c5bd5f2..684f33b74 100644
--- a/nuttx/libc/stdio/lib_libfread.c
+++ b/nuttx/libc/stdio/lib_libfread.c
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/stdio/lib_libfread.c
*
- * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -37,7 +37,7 @@
* Included Files
****************************************************************************/
-#include <nuttx/config.h> /* for CONFIG_STDIO_BUFFER_SIZE */
+#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
@@ -312,6 +312,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
/* Error exits */
errout_with_errno:
+ stream->fs_flags |= __FS_FLAG_ERROR;
lib_give_semaphore(stream);
return -get_errno();
}
diff --git a/nuttx/libc/stdio/lib_libfwrite.c b/nuttx/libc/stdio/lib_libfwrite.c
index e7443f996..ea75da6d7 100644
--- a/nuttx/libc/stdio/lib_libfwrite.c
+++ b/nuttx/libc/stdio/lib_libfwrite.c
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/stdio/lib_libfwrite.c
*
- * Copyright (C) 2007-2009, 2011, 2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011, 2013-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -37,7 +37,7 @@
* Included Files
****************************************************************************/
-#include <nuttx/config.h> /* for CONFIG_STDIO_BUFFER_SIZE */
+#include <nuttx/config.h>
#include <sys/types.h>
#include <stdbool.h>
@@ -145,6 +145,7 @@ ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream)
{
*dest++ = *src++;
}
+
stream->fs_bufpos = dest;
/* Is the buffer full? */
@@ -169,10 +170,21 @@ errout_with_semaphore:
lib_give_semaphore(stream);
errout:
+ if (ret < 0)
+ {
+ stream->fs_flags |= __FS_FLAG_ERROR;
+ }
+
return ret;
}
#else
{
- return write(stream->fs_fd, ptr, count);
+ ssize_t ret = write(stream->fs_fd, ptr, count);
+ if (ret < 0)
+ {
+ stream->fs_flags |= __FS_FLAG_ERROR;
+ }
+
+ return ret;
}
#endif /* CONFIG_STDIO_BUFFER_SIZE */