Suggested patch: reset errno after isatty()
Ketil Froyn
ketil at froyn.name
Wed Nov 3 09:16:01 EDT 2010
On Wed, Nov 3, 2010 at 9:23 AM, Matthieu CASTET
<matthieu.castet at parrot.com> wrote:
> Why errno is checked when pread return 0 ?
> Errno should be checked only when return is -1.
Good point, and I guess that was why I was getting weird errors in the
first place, because errno was checked when no error had occurred. Odd
that pread() returned 0 when trying to read on my android device -
maybe a bionic bug?
This code has been rewritten, but the new master isn't working for me
(yet). This patch against v1.4.1 seems to have solved my problems for
now. I've just replaced pread() with read(), because it works, and
fixed up the error checking.
--- a/nanddump.c
+++ b/nanddump.c
@@ -412,10 +412,25 @@ int main(int argc, char * const argv[])
memset (readbuf, 0xff, bs);
} else {
/* Read page data and exit on failure */
- if (pread(fd, readbuf, bs, ofs) != bs) {
- perror("pread");
- goto closeall;
- }
+ do {
+ ret = read(fd, readbuf, bs);
+ if (ret == -1) {
+ if (errno == EAGAIN || errno == EINTR) {
+ continue;
+ }
+ perror("read");
+ goto closeall;
+ }
+ if (ret == 0) {
+ printf("No more data to read\n");
+ break;
+ }
+ if (ret != bs) {
+ fprintf(stderr, "read() got
wrong number of bytes: got %i, expected %i\n", ret, bs);
+ goto closeall;
+ }
+ break;
+ } while (1);
}
/* ECC stats available ? */
More information about the linux-mtd
mailing list