--- embedtools/src/imgupd.c 2014/02/05 22:53:12 1.4 +++ embedtools/src/imgupd.c 2014/02/05 23:31:26 1.5.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: imgupd.c,v 1.4 2014/02/05 22:53:12 misho Exp $ + * $Id: imgupd.c,v 1.5.2.1 2014/02/05 23:31:26 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -86,10 +86,10 @@ EmptyStore(int img) memset(buf, 0, sizeof buf); for (i = howmany(iSize, bufSize); i < howmany(imgSize, bufSize); i++) - if ((wlen = write(img, buf, sizeof buf)) == -1 || - wlen != sizeof buf) { - EERROR(EIO, "Error at chunk %d init %d bytes, should be %u\n", - i, wlen, sizeof buf); + if ((wlen = write(img, buf, bufSize)) == -1 || + (wlen && wlen != bufSize)) { + EERROR(EIO, "Error at chunk %d init %d bytes, " + "should be %u\n", i, wlen, bufSize); return -1; } else VERB(1) printf("+Written chunk #%d\n", i); @@ -110,7 +110,7 @@ FillStore(int img, int fd) for (j = 0, i = howmany(iSize, bufSize); i < howmany(imgSize, bufSize); i++, j++) { memset(buf, 0, sizeof buf); - rlen = read(fd, buf, sizeof buf); + rlen = read(fd, buf, bufSize); if (rlen == -1) { ESYSERR(0); return -1; @@ -123,7 +123,7 @@ FillStore(int img, int fd) if (wlen == -1) { ESYSERR(0); return -1; - } else if (!wlen || wlen != rlen) { + } else if (wlen && wlen != rlen) { EERROR(EIO, "Readed %d bytes are not equal to written %d bytes\n", rlen, wlen); } else