[PATCH] libfile: Make use of write_full() in copy_file()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change copy_file() to rely on write_full() instead of re-implementing
it locally.

Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
---
 lib/libfile.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index c069aee40..b42753c2b 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -329,10 +329,9 @@ int copy_file(const char *src, const char *dst, int verbose)
 {
 	char *rw_buf = NULL;
 	int srcfd = 0, dstfd = 0;
-	int r, w;
+	int r;
 	int ret = 1, err1 = 0;
 	int mode;
-	void *buf;
 	int total = 0;
 	struct stat srcstat, dststat;
 
@@ -376,18 +375,13 @@ int copy_file(const char *src, const char *dst, int verbose)
 		if (!r)
 			break;
 
-		buf = rw_buf;
-		while (r) {
-			w = write(dstfd, buf, r);
-			if (w < 0) {
-				perror("write");
-				goto out;
-			}
-			buf += w;
-			r -= w;
-			total += w;
+		if (write_full(dstfd, rw_buf, r) < 0) {
+			perror("write");
+			goto out;
 		}
 
+		total += r;
+
 		if (verbose) {
 			if (srcstat.st_size && srcstat.st_size != FILESIZE_MAX)
 				show_progress(total);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux