Since `off` and `nr` approach each other, the for-loop ends prematurely
when at least half of the buffer was written. I think under certain
conditions this could cause the copy to be incomplete.
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
char buf[8 * 1024];
while ((nr = read(from, buf, sizeof(buf))) > 0)
- for (off = 0; off < nr; nr -= nw, off += nw)
+ for (off = 0; nr > 0; nr -= nw, off += nw)
if ((nw = write(to, buf + off, nr)) < 0)
pw_error(tmp_file, 1, 1);