diff options
author | Jeremy Allison <jra@samba.org> | 2002-01-03 21:48:17 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-01-03 21:48:17 +0000 |
commit | 35fff73f1025906eb4a714dd8bd89d263c5f9ee5 (patch) | |
tree | 20c48f6f4e05ff79c68d3bfe941b190afb7dc793 /source3 | |
parent | 894e87cb32542414c51f5e70c89f68abf3d9a312 (diff) | |
download | samba-35fff73f1025906eb4a714dd8bd89d263c5f9ee5.tar.gz samba-35fff73f1025906eb4a714dd8bd89d263c5f9ee5.tar.bz2 samba-35fff73f1025906eb4a714dd8bd89d263c5f9ee5.zip |
Don't use static memory, malloc it...
Jeremy.
(This used to be commit 8aee8211cddb6705c9aa545fc57ece2c721ef448)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/util.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index c7b4ab8ed1..2f2affffe9 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -565,22 +565,30 @@ int set_blocking(int fd, BOOL set) Transfer some data between two fd's. ****************************************************************************/ +#ifndef TRANSFER_BUF_SIZE +#define TRANSFER_BUF_SIZE 65536 +#endif + ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)(int, void *, size_t), ssize_t (*write_fn)(int, const void *, size_t)) { - static char buf[16384]; + char *buf; size_t total = 0; ssize_t read_ret; ssize_t write_ret; size_t num_to_read_thistime; size_t num_written = 0; + if ((buf = malloc(TRANSFER_BUF_SIZE)) == NULL) + return -1; + while (total < n) { - num_to_read_thistime = MIN((n - total), sizeof(buf)); + num_to_read_thistime = MIN((n - total), TRANSFER_BUF_SIZE); read_ret = (*read_fn)(infd, buf, num_to_read_thistime); if (read_ret == -1) { DEBUG(0,("transfer_file_internal: read failure. Error = %s\n", strerror(errno) )); + SAFE_FREE(buf); return -1; } if (read_ret == 0) @@ -593,6 +601,7 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn) if (write_ret == -1) { DEBUG(0,("transfer_file_internal: write failure. Error = %s\n", strerror(errno) )); + SAFE_FREE(buf); return -1; } if (write_ret == 0) @@ -604,6 +613,7 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn) total += (size_t)read_ret; } + SAFE_FREE(buf); return (ssize_t)total; } |