summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/lib/util.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index d635078f37..44eaa85ab0 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -919,34 +919,41 @@ ssize_t transfer_file_internal(void *in_file,
size_t num_to_read_thistime;
size_t num_written = 0;
- if ((buf = SMB_MALLOC_ARRAY(char, TRANSFER_BUF_SIZE)) == NULL)
+ if ((buf = SMB_MALLOC_ARRAY(char, TRANSFER_BUF_SIZE)) == NULL) {
return -1;
+ }
while (total < n) {
num_to_read_thistime = MIN((n - total), TRANSFER_BUF_SIZE);
read_ret = (*read_fn)(in_file, buf, num_to_read_thistime);
if (read_ret == -1) {
- DEBUG(0,("transfer_file_internal: read failure. Error = %s\n", strerror(errno) ));
+ DEBUG(0,("transfer_file_internal: read failure. "
+ "Error = %s\n", strerror(errno) ));
SAFE_FREE(buf);
return -1;
}
- if (read_ret == 0)
+ if (read_ret == 0) {
break;
+ }
num_written = 0;
-
+
while (num_written < read_ret) {
- write_ret = (*write_fn)(out_file, buf + num_written, read_ret - num_written);
-
+ write_ret = (*write_fn)(out_file, buf + num_written,
+ read_ret - num_written);
+
if (write_ret == -1) {
- DEBUG(0,("transfer_file_internal: write failure. Error = %s\n", strerror(errno) ));
+ DEBUG(0,("transfer_file_internal: "
+ "write failure. Error = %s\n",
+ strerror(errno) ));
SAFE_FREE(buf);
return -1;
}
- if (write_ret == 0)
+ if (write_ret == 0) {
return (ssize_t)total;
-
+ }
+
num_written += (size_t)write_ret;
}
@@ -954,7 +961,7 @@ ssize_t transfer_file_internal(void *in_file,
}
SAFE_FREE(buf);
- return (ssize_t)total;
+ return (ssize_t)total;
}
static ssize_t sys_read_fn(void *file, void *buf, size_t len)
@@ -971,9 +978,10 @@ static ssize_t sys_write_fn(void *file, void *buf, size_t len)
return sys_write(*fd, buf, len);
}
-SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n)
+SMB_OFF_T transfer_file(int infd, int outfd, SMB_OFF_T n)
{
- return (SMB_OFF_T)transfer_file_internal(&infd, &outfd, (size_t)n, sys_read_fn, sys_write_fn);
+ return (SMB_OFF_T)transfer_file_internal(&infd, &outfd, (size_t)n,
+ sys_read_fn, sys_write_fn);
}
/*******************************************************************