copy_file_chunk uses streams now.
This commit is contained in:
@ -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:
|
||||
|
Reference in New Issue
Block a user