From 3e67155c8e7aa779b38f8515ebff2c2630d46bd7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 20 Jun 2013 08:21:04 -0600 Subject: Change use of ferror() in uClibc++ so that is does not use more capability than is currently supported by the NuttX ferror() --- misc/uClibc++/ChangeLog.txt | 7 +++++++ misc/uClibc++/include/uClibc++/fstream | 35 +++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'misc') 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 David for the RGMP team. uClibc++-1.1 2011-xx-xx + + * 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::egptr() - basic_streambuf::gptr() + basic_streambuf::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::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(); } -- cgit v1.2.3