summaryrefslogtreecommitdiff
path: root/fileio.c
diff options
context:
space:
mode:
authorJ.W. Schultz <jw@samba.org>2003-05-22 23:24:44 +0000
committerJ.W. Schultz <jw@samba.org>2003-05-22 23:24:44 +0000
commit9533e15a7996c5e01fff60a754c39d4fae5461f6 (patch)
treead4e7d7520d0930bd88d2485adae5499baa8e481 /fileio.c
parent8dc74608a3dd156c7e86fa4e0c96b6700572d987 (diff)
downloadrsync-9533e15a7996c5e01fff60a754c39d4fae5461f6.tar.gz
Changed write file to cope with partial writes by looping
until complete or errno is set. (John Van Essen)
Diffstat (limited to 'fileio.c')
-rw-r--r--fileio.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/fileio.c b/fileio.c
index 92631bc7..e8eaa100 100644
--- a/fileio.c
+++ b/fileio.c
@@ -69,19 +69,22 @@ static int write_sparse(int f,char *buf,size_t len)
return len;
}
-
-
+/*
+ * write_file does not allow incomplete writes. It loops internally
+ * until len bytes are written or errno is set.
+ */
int write_file(int f,char *buf,size_t len)
{
int ret = 0;
- if (!sparse_files) {
- return write(f,buf,len);
- }
-
while (len>0) {
- int len1 = MIN(len, SPARSE_WRITE_SIZE);
- int r1 = write_sparse(f, buf, len1);
+ int r1;
+ if (sparse_files) {
+ int len1 = MIN(len, SPARSE_WRITE_SIZE);
+ r1 = write_sparse(f, buf, len1);
+ } else {
+ r1 = write(f, buf, len);
+ }
if (r1 <= 0) {
if (ret > 0) return ret;
return r1;