read syscall can return less bytes then requested - handle this.
This bug is triggered when reading from stdin that comes from remote host
Author: Hai Zaar <haizaar@haizaar.com>
@@ -218,6 +218,7 @@
int ret, readlen;
int oobinfochanged = 0;
struct nand_oobinfo old_oobinfo;
+ int readcnt = 0;
process_options(argc, argv);
@@ -405,12 +406,22 @@
}
/* Read Page Data from input file */
- if ((cnt = read(ifd, writebuf, readlen)) != readlen) {
- if (cnt == 0) // EOF
- break;
- perror ("File I/O error on input file");
- goto closeall;
+ readcnt = 0;
+ while (readcnt < readlen) {
+ if ((cnt = read(ifd, writebuf + readcnt, readlen - readcnt)) < 0) {
+ perror ("File I/O error on input file");
+ goto closeall;
+ } else {
+ if ((cnt == 0) && (readcnt == 0)) { // EOF
+ break;
+ } else {
+ readcnt += cnt;
+ }
+ }
+
}
+ if ((cnt == 0) && (readcnt == 0)) // EOF
+ break;
if (writeoob) {
/* Read OOB data from input file, exit on failure */