summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-05-03 12:53:52 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-06-24 11:36:28 +0200
commit3e94938068169d29b55355f22b2671262df69305 (patch)
tree8273694ab67373d3239cdae304929f1f1eb7be2b
parentcd4bc69126f6f97ea3647c8538514e4a2c4d65eb (diff)
downloadbarebox-3e94938068169d29b55355f22b2671262df69305.tar.gz
barebox-3e94938068169d29b55355f22b2671262df69305.tar.xz
memcpy cmd: Do not expect to read/write the whole chunk at once
read() does not necessarily return the number of bytes we want to read, so deal with less bytes. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/mem.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/commands/mem.c b/commands/mem.c
index 6192466522..bd1d3493c0 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -455,27 +455,35 @@ static int do_mem_cp(struct command *cmdtp, int argc, char *argv[])
}
while (count > 0) {
- int now, r, w;
+ int now, r, w, tmp;
now = min(RW_BUF_SIZE, count);
- if ((r = read(sourcefd, rw_buf, now)) < 0) {
+ r = read(sourcefd, rw_buf, now);
+ if (r < 0) {
perror("read");
goto out;
}
- if ((w = write(destfd, rw_buf, r)) < 0) {
- perror("write");
- goto out;
- }
-
- if (r < now)
+ if (!r)
break;
- if (w < r)
- break;
+ tmp = 0;
+ now = r;
+ while (now) {
+ w = write(destfd, rw_buf + tmp, now);
+ if (w < 0) {
+ perror("write");
+ goto out;
+ }
+ if (!w)
+ break;
- count -= now;
+ now -= w;
+ tmp += w;
+ }
+
+ count -= r;
}
if (count) {