mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] libfile: Make use of write_full() in copy_file()
@ 2019-03-12  7:32 Andrey Smirnov
  2019-03-13  8:42 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Andrey Smirnov @ 2019-03-12  7:32 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

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

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libfile: Make use of write_full() in copy_file()
  2019-03-12  7:32 [PATCH] libfile: Make use of write_full() in copy_file() Andrey Smirnov
@ 2019-03-13  8:42 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-03-13  8:42 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Tue, Mar 12, 2019 at 12:32:07AM -0700, Andrey Smirnov wrote:
> Change copy_file() to rely on write_full() instead of re-implementing
> it locally.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  lib/libfile.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-13  8:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-12  7:32 [PATCH] libfile: Make use of write_full() in copy_file() Andrey Smirnov
2019-03-13  8:42 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox