fix copy_file fail

Change-Id: I46e31ee17255e76a3c64a9e661dc74e636a345ec
This commit is contained in:
Koushik Dutta 2011-07-11 14:32:02 -07:00
parent e8bdefda33
commit 7f3a8c90b0

View File

@ -38,16 +38,12 @@ static int copy_file(const char *dst, const char *src) {
return 4;
}
do {
total_read += bytes_read = read(srcfd, buf, 4096);
if (!bytes_read)
break;
if (bytes_read < 4096)
memset(&buf[bytes_read], 0, 4096 - bytes_read);
if (write(dstfd, buf, 4096) < 4096)
while (bytes_read = read(srcfd, buf, 4096)) {
total_read += bytes_read;
if (write(dstfd, buf, bytes_read) != bytes_read)
return 5;
} while(bytes_read == 4096);
}
close(dstfd);
close(srcfd);