This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: STDIO - proposed fix for fread()


On Thu, 2003-03-06 at 12:41, Jonathan Larmour wrote:
> Gary Thomas wrote:
> > The 'fread()' function works differently on eCos than it does on Linux. 
> > Thusly, some programs which work fine on Linux fail on eCos.  The 
> > problem is that fread() sets ferror() when it gets to the end of the 
> > file (as well as setting feof()).  This patch fixes it, and also adds a 
> > test for the condition.
> > 
> > Does it make sense?  Shall I commit?
> 
> Well those programs are using unspecified behaviour so strictly they are 
> non-portable. Checking for ferror()  without a reported error is as porr 
> practice as checking for errno without a reported error.
> 
> But we may as well probably deal with this although I'm not particularly 
> happy about adding a test for something that only non-portable programs 
> use. But still it's the least worst option :-).
> 
> If you could add a comment in the test saying as much that would be nice, 
> i.e. standard doesn't require it, but we'll be nice to programs anyway.
> 

I'll add a comment, but I'm not convinced how wrong/non-portable this
usage is.  The [Linux] man page for 'fread' explicitly states that it
does not distinguish between EOF and error conditions and that an 
application must use feof() and ferror() to ferret it out.

BTW, without my change, fread() does return the error EAGAIN.

> > +#include <cyg/fileio/fileio.h>
> 
> Probably need not include this.
> 

This brought in the prototype for mount().

> You should also probably do a clearerr() first before anything else.
> 
> You may as well do a CYG_TEST_CHECK of the fclose() and fseek() return 
> codes too. Maybe also quickly check fprintf returns >0 too. This is a test 
> after all so we may as well be thorough :-).
> 
> And instead of CYG_TEST_FAIL("..."); return; throughout, you should use 
> CYG_TEST_FAIL_FINISH().
> 

OK on all this.

> Other than that, good stuff! Go for it.

Thanks.

> 
> Jifl
> -- 
> eCosCentric    http://www.eCosCentric.com/    The eCos and RedBoot experts
> --[ "You can complain because roses have thorns, or you ]--
> --[  can rejoice because thorns have roses." -Lincoln   ]-- Opinions==mine
-- 
------------------------------------------------------------
Gary Thomas                 |
MLB Associates              |  Consulting for the
+1 (970) 229-1963           |    Embedded world
http://www.mlbassoc.com/    |
email: <gary at mlbassoc dot com>  |
gpg: http://www.chez-thomas.org/gary/gpg_key.asc
------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]