aboutsummaryrefslogtreecommitdiff
path: root/libbb/copy_file_chunk.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-04-11 16:23:35 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-04-11 16:23:35 +0000
commit4949faf4b2090ca23c2aeb34535fdbe57754913a (patch)
treeb292a499341d3c0314283e2822a93241a1c4e1dd /libbb/copy_file_chunk.c
parent5b20d02ea98c41bbd8a49cdbb84f425fa9ef446e (diff)
downloadbusybox-w32-4949faf4b2090ca23c2aeb34535fdbe57754913a.tar.gz
busybox-w32-4949faf4b2090ca23c2aeb34535fdbe57754913a.tar.bz2
busybox-w32-4949faf4b2090ca23c2aeb34535fdbe57754913a.zip
copy_file_chunk uses streams now.
Diffstat (limited to 'libbb/copy_file_chunk.c')
-rw-r--r--libbb/copy_file_chunk.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/libbb/copy_file_chunk.c b/libbb/copy_file_chunk.c
index bf0b06e1a..e887cbe9f 100644
--- a/libbb/copy_file_chunk.c
+++ b/libbb/copy_file_chunk.c
@@ -32,24 +32,29 @@
32/* 32/*
33 * Copy chunksize bytes between two file descriptors 33 * Copy chunksize bytes between two file descriptors
34 */ 34 */
35int copy_file_chunk(int srcfd, int dstfd, off_t chunksize) 35extern int copy_file_chunk(FILE *src_file, FILE *dst_file, off_t chunksize)
36{ 36{
37 off_t size; 37 off_t size, amount_written;
38 char buffer[BUFSIZ]; /* BUFSIZ is declared in stdio.h */ 38 char buffer[BUFSIZ]; /* BUFSIZ is declared in stdio.h */
39 39
40 while (chunksize > 0) { 40 clearerr(src_file);
41 if (chunksize > BUFSIZ) 41 clearerr(dst_file);
42 size = BUFSIZ; 42 while (chunksize > 0) {
43 else 43 if (chunksize > BUFSIZ) {
44 size = chunksize; 44 size = BUFSIZ;
45 if (full_write(dstfd, buffer, full_read(srcfd, buffer, size)) < size) 45 } else {
46 return(FALSE); 46 size = chunksize;
47 chunksize -= size; 47 }
48 } 48 amount_written = fwrite(buffer, 1, fread(buffer, 1, size, src_file), dst_file);
49 return (TRUE); 49 if (amount_written != size) {
50 error_msg("Couldnt write correct amount");
51 return(FALSE);
52 }
53 chunksize -= amount_written;
54 }
55 return (TRUE);
50} 56}
51 57
52
53/* END CODE */ 58/* END CODE */
54/* 59/*
55Local Variables: 60Local Variables: