summaryrefslogtreecommitdiff
path: root/libbb/copy_file_chunk.c
diff options
context:
space:
mode:
authorGlenn L McGrath2001-04-11 16:23:35 +0000
committerGlenn L McGrath2001-04-11 16:23:35 +0000
commit4949faf4b2090ca23c2aeb34535fdbe57754913a (patch)
treeb292a499341d3c0314283e2822a93241a1c4e1dd /libbb/copy_file_chunk.c
parent5b20d02ea98c41bbd8a49cdbb84f425fa9ef446e (diff)
downloadbusybox-4949faf4b2090ca23c2aeb34535fdbe57754913a.zip
busybox-4949faf4b2090ca23c2aeb34535fdbe57754913a.tar.gz
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 bf0b06e..e887cbe 100644
--- a/libbb/copy_file_chunk.c
+++ b/libbb/copy_file_chunk.c
@@ -32,24 +32,29 @@
/*
* Copy chunksize bytes between two file descriptors
*/
-int copy_file_chunk(int srcfd, int dstfd, off_t chunksize)
+extern int copy_file_chunk(FILE *src_file, FILE *dst_file, off_t chunksize)
{
- off_t size;
- char buffer[BUFSIZ]; /* BUFSIZ is declared in stdio.h */
-
- while (chunksize > 0) {
- if (chunksize > BUFSIZ)
- size = BUFSIZ;
- else
- size = chunksize;
- if (full_write(dstfd, buffer, full_read(srcfd, buffer, size)) < size)
- return(FALSE);
- chunksize -= size;
- }
- return (TRUE);
+ off_t size, amount_written;
+ char buffer[BUFSIZ]; /* BUFSIZ is declared in stdio.h */
+
+ clearerr(src_file);
+ clearerr(dst_file);
+ while (chunksize > 0) {
+ if (chunksize > BUFSIZ) {
+ size = BUFSIZ;
+ } else {
+ size = chunksize;
+ }
+ amount_written = fwrite(buffer, 1, fread(buffer, 1, size, src_file), dst_file);
+ if (amount_written != size) {
+ error_msg("Couldnt write correct amount");
+ return(FALSE);
+ }
+ chunksize -= amount_written;
+ }
+ return (TRUE);
}
-
/* END CODE */
/*
Local Variables: