diff --git a/lib/copy_file.c b/lib/copy_file.c index 7083531..809befe 100644 --- a/lib/copy_file.c +++ b/lib/copy_file.c @@ -17,6 +17,7 @@ int srcfd = 0, dstfd = 0; int r, w; int ret = 1; + void *buf; rw_buf = xmalloc(RW_BUF_SIZE); @@ -40,10 +41,16 @@ } if (!r) break; - w = write(dstfd, rw_buf, r); - if (w < 0) { - perror("write"); - goto out; + + buf = rw_buf; + while (r) { + w = write(dstfd, buf, r); + if (w < 0) { + perror("write"); + goto out; + } + buf += w; + r -= w; } }