mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 6/7] copy_file: handle write return value correctly
Date: Mon, 11 Apr 2011 16:18:40 +0200	[thread overview]
Message-ID: <1302531521-7439-7-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1302531521-7439-1-git-send-email-s.hauer@pengutronix.de>

write() does not necessarily consume all input, handle this
case correctly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/copy_file.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

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 copy_file(const char *src, const char *dst)
 	int srcfd = 0, dstfd = 0;
 	int r, w;
 	int ret = 1;
+	void *buf;
 
 	rw_buf = xmalloc(RW_BUF_SIZE);
 
@@ -40,10 +41,16 @@ int copy_file(const char *src, const char *dst)
 		}
 		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;
 		}
 	}
 
-- 
1.7.2.3


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

  parent reply	other threads:[~2011-04-11 14:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 14:18 assorted patches Sascha Hauer
2011-04-11 14:18 ` [PATCH 1/7] eth: check the result of edev->get_ethaddr Sascha Hauer
2011-04-11 14:18 ` [PATCH 2/7] net: add a context to the packet handler Sascha Hauer
2011-04-11 14:18 ` [PATCH 3/7] environment: make default env path configurable Sascha Hauer
2011-04-11 14:18 ` [PATCH 4/7] move simple_itoa to libbb so that others can use it Sascha Hauer
2011-04-11 14:18 ` [PATCH 5/7] kfifo: kfifo_put takes a const buffer Sascha Hauer
2011-04-11 14:18 ` Sascha Hauer [this message]
2011-04-11 14:18 ` [PATCH 7/7] cp command: handle directories as last argument Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302531521-7439-7-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox