diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-06-20 08:21:04 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-06-20 08:21:04 -0600 |
commit | 3e67155c8e7aa779b38f8515ebff2c2630d46bd7 (patch) | |
tree | 454c129c450e5aacb1df79d7062b2b7b58e7b860 /misc/uClibc++/include | |
parent | 65568d1c0333b35cc2e7af26dca197989deef24f (diff) | |
download | nuttx-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/uClibc++/include')
-rw-r--r-- | misc/uClibc++/include/uClibc++/fstream | 35 |
1 files changed, 17 insertions, 18 deletions
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(); } |