copy_file_chunk uses streams now.

This commit is contained in:
Glenn L McGrath
2001-04-11 16:23:35 +00:00
parent 5b20d02ea9
commit 4949faf4b2
14 changed files with 269 additions and 274 deletions

View File

@ -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: