Suggested patch: reset errno after isatty()

Mike Frysinger vapier.adi at gmail.com
Sat Nov 6 04:54:20 EDT 2010


On Wed, Nov 3, 2010 at 09:16, Ketil Froyn wrote:
> On Wed, Nov 3, 2010 at 9:23 AM, Matthieu CASTET wrote:
> 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);
>                }

doesnt libmtd provide read functions already ?
-mike


More information about the linux-mtd mailing list