summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-06-20 08:21:04 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-06-20 08:21:04 -0600
commit3e67155c8e7aa779b38f8515ebff2c2630d46bd7 (patch)
tree454c129c450e5aacb1df79d7062b2b7b58e7b860 /misc
parent65568d1c0333b35cc2e7af26dca197989deef24f (diff)
downloadnuttx-3e67155c8e7aa779b38f8515ebff2c2630d46bd7.tar.gz
nuttx-3e67155c8e7aa779b38f8515ebff2c2630d46bd7.tar.bz2
nuttx-3e67155c8e7aa779b38f8515ebff2c2630d46bd7.zip
Change use of ferror() in uClibc++ so that is does not use more capability than is currently supported by the NuttX ferror()
Diffstat (limited to 'misc')
-rw-r--r--misc/uClibc++/ChangeLog.txt7
-rw-r--r--misc/uClibc++/include/uClibc++/fstream35
2 files changed, 24 insertions, 18 deletions
diff --git a/misc/uClibc++/ChangeLog.txt b/misc/uClibc++/ChangeLog.txt
index 8c680392c..2de53129c 100644
--- a/misc/uClibc++/ChangeLog.txt
+++ b/misc/uClibc++/ChangeLog.txt
@@ -5,3 +5,10 @@ uClibc++-1.0 2011-11-05 <gnutt@nuttx.org>
David for the RGMP team.
uClibc++-1.1 2011-xx-xx <gnutt@nuttx.org>
+
+ * misc/uClibc++/include/uClibc++/fstream: Remove move of ferror()
+ and feof() to determine if fopen() and fread() were successful.
+ The NuttX version of ferror() is only fragmentary. The usage of
+ ferror() in this file exceeds the capability of the current
+ implementatino (2013-6-20).
+
diff --git a/misc/uClibc++/include/uClibc++/fstream b/misc/uClibc++/include/uClibc++/fstream
index 0f0388e5d..8bfeb9781 100644
--- a/misc/uClibc++/include/uClibc++/fstream
+++ b/misc/uClibc++/include/uClibc++/fstream
@@ -176,15 +176,10 @@ namespace std
fp = fopen(s, "w+b");
}
- if (fp == 0)
- {
- return 0;
- }
+ // Check for a failure to open the file
- if (ferror(fp))
+ if (fp == 0)
{
- fclose(fp);
- fp = 0;
return 0;
}
@@ -272,9 +267,14 @@ namespace std
charT c;
int retval;
+
+ // Read one element of size sizeof(charT)
+
retval = fread(&c, sizeof(charT), 1, fp);
- if (retval == 0 || feof(fp) || ferror(fp))
+ // retval will be less than 1 only if an error or end-of-file is encountered
+
+ if (retval <= 0)
{
return traits::eof();
}
@@ -318,18 +318,13 @@ namespace std
offset,
fp);
- // Clear problems where we didn't read in enough characters
-
- if (EAGAIN == errno)
- {
- clearerr(fp);
- }
-
// Restore file descriptor clase
fcntl(fileno(fp), F_SETFL, fcntl_flags);
- // Now we are going to make sure that we read in at least one character. The hard way.
+ // fread() will return a value < offset if an error or end-of-file
+ // occurred. If nothing was read, make sure that we read in at least
+ // one character. The hard way.
if (retval == 0)
{
@@ -339,6 +334,8 @@ namespace std
fcntl(fileno(fp), F_SETFL, fcntl_flags & ~O_NONBLOCK);
+ // Read one element of size sizeof(charT)
+
retval = fread(basic_streambuf<charT,traits>::egptr() -
basic_streambuf<charT,traits>::gptr() + basic_streambuf<charT,traits>::eback(),
sizeof(charT),
@@ -350,7 +347,7 @@ namespace std
fcntl(fileno(fp), F_SETFL, fcntl_flags);
}
- if (retval !=offset)
+ if (retval != offset)
{
// Slide buffer forward again
@@ -363,7 +360,9 @@ namespace std
basic_streambuf<charT,traits>::mgnext -= retval;
- if ((retval <= 0 && feof(fp)) || ferror(fp))
+ // retval will be less than 1 only if an error or end-of-file is encountered
+
+ if ((retval <= 0)
{
return traits::eof();
}