1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

Fixed embarressing 16k strack trashing bug :-(.

Jeremy.
(This used to be commit b52c3219d6)
This commit is contained in:
Jeremy Allison 2002-01-03 19:57:12 +00:00
parent 9e0297b3ed
commit 791433434e

View File

@ -571,13 +571,14 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)
static char buf[16384]; static char buf[16384];
size_t total = 0; size_t total = 0;
ssize_t read_ret; ssize_t read_ret;
size_t write_total = 0; ssize_t write_ret;
ssize_t write_ret; size_t num_to_read_thistime;
size_t num_written = 0;
while (total < n) { while (total < n) {
size_t num_to_read_thistime = MIN((n - total), sizeof(buf)); num_to_read_thistime = MIN((n - total), sizeof(buf));
read_ret = (*read_fn)(infd, buf + total, num_to_read_thistime); read_ret = (*read_fn)(infd, buf, num_to_read_thistime);
if (read_ret == -1) { 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) ));
return -1; return -1;
@ -585,10 +586,10 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)
if (read_ret == 0) if (read_ret == 0)
break; break;
write_total = 0; num_written = 0;
while (write_total < read_ret) { while (num_written < read_ret) {
write_ret = (*write_fn)(outfd,buf + total, read_ret); write_ret = (*write_fn)(outfd,buf + num_written, read_ret);
if (write_ret == -1) { 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) ));
@ -597,7 +598,7 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)
if (write_ret == 0) if (write_ret == 0)
return (ssize_t)total; return (ssize_t)total;
write_total += (size_t)write_ret; num_written += (size_t)write_ret;
} }
total += (size_t)read_ret; total += (size_t)read_ret;