diff options
author | Glenn L McGrath | 2002-09-25 02:47:48 +0000 |
---|---|---|
committer | Glenn L McGrath | 2002-09-25 02:47:48 +0000 |
commit | 7ca04f328e22fcbee4659d73f9a72dfdf1dd6a23 (patch) | |
tree | f38c7ef4317eea28c6abdb0adbbb286fe041711e /archival/libunarchive/copy_file_chunk_fd.c | |
parent | ecfa290cfd4953598e6d91989bd66ac16e135f84 (diff) | |
download | busybox-7ca04f328e22fcbee4659d73f9a72dfdf1dd6a23.zip busybox-7ca04f328e22fcbee4659d73f9a72dfdf1dd6a23.tar.gz |
New common unarchive code.
Diffstat (limited to 'archival/libunarchive/copy_file_chunk_fd.c')
-rw-r--r-- | archival/libunarchive/copy_file_chunk_fd.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/archival/libunarchive/copy_file_chunk_fd.c b/archival/libunarchive/copy_file_chunk_fd.c new file mode 100644 index 0000000..fb513e6 --- /dev/null +++ b/archival/libunarchive/copy_file_chunk_fd.c @@ -0,0 +1,33 @@ +#include <unistd.h> +#include <sys/types.h> +#include "libbb.h" + +/* Copy CHUNKSIZE bytes (or untill EOF if chunksize == -1) + * from SRC_FILE to DST_FILE. */ +extern int copy_file_chunk_fd(int src_fd, int dst_fd, off_t chunksize) +{ + size_t nread, size; + char buffer[BUFSIZ]; + + while (chunksize != 0) { + if (chunksize > BUFSIZ) { + size = BUFSIZ; + } else { + size = chunksize; + } + nread = xread(src_fd, buffer, size); + if (nread == 0) { + return 1; + } + + if (write (dst_fd, buffer, nread) != nread) { + error_msg_and_die ("Short write"); + } + + if (chunksize != -1) { + chunksize -= nread; + } + } + + return 0; +} |