STDIO - proposed fix for fread()
Jonathan Larmour
jifl@eCosCentric.com
Thu Mar 6 19:41:00 GMT 2003
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.
> +#include <cyg/fileio/fileio.h>
Probably need not include this.
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().
Other than that, good stuff! Go for it.
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
More information about the Ecos-patches
mailing list