--- embedtools/src/imgupd.c 2014/02/06 01:23:56 1.6.2.4 +++ embedtools/src/imgupd.c 2014/02/06 09:19:51 1.6.2.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: imgupd.c,v 1.6.2.4 2014/02/06 01:23:56 misho Exp $ + * $Id: imgupd.c,v 1.6.2.5 2014/02/06 09:19:51 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -109,22 +109,24 @@ static int FillStore(int img, int fd) { register int i, j; - u_char buf[bufSize]; - ssize_t rlen, wlen; + u_char *pos, buf[bufSize]; + ssize_t rlen, wlen, len; VERB(1) printf("Fill store %s from image file %s\n", imgName, imgFile); for (j = 0, i = howmany(iSize, bufSize); i < howmany(imgSize, bufSize); i++, j++) { memset(buf, 0, sizeof buf); - rlen = read(fd, buf, bufSize); - if (rlen == -1) { - ESYSERR(0); - return -1; - } else if (!rlen) - break; - else - VERB(1) printf("+Readed %d bytes for chunk #%d\n", rlen, j); + for (len = bufSize, pos = buf; len > 0; len -= rlen, pos += rlen) { + rlen = read(fd, pos, len); + if (rlen == -1) { + ESYSERR(0); + return -1; + } else if (!rlen) + break; + else + VERB(1) printf("+Readed %d bytes for chunk #%d\n", rlen, j); + } wlen = write(img, buf, bufSize); if (wlen == -1) {