summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-04-10 19:00:37 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2011-04-12 09:54:56 +0200
commit583fe4fc0e2651532cb9d56d9c012c86a539250c (patch)
tree33c6eec53eb03aef38873e763a942a5e7122362f /lib
parentd354cee3d01d10ffdce1568e671e679527d33d22 (diff)
downloadbarebox-583fe4fc0e2651532cb9d56d9c012c86a539250c.tar.gz
barebox-583fe4fc0e2651532cb9d56d9c012c86a539250c.tar.xz
copy_file: handle write return value correctly
write() does not necessarily consume all input, handle this case correctly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/copy_file.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/copy_file.c b/lib/copy_file.c
index 70835319b6..809befe369 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;
}
}