From 7f3a8c90b09c50fcced850f504db5d154faf2537 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 11 Jul 2011 14:32:02 -0700 Subject: [PATCH] fix copy_file fail Change-Id: I46e31ee17255e76a3c64a9e661dc74e636a345ec --- dedupe/dedupe.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c index d41b8ac..ed11491 100644 --- a/dedupe/dedupe.c +++ b/dedupe/dedupe.c @@ -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);