1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
24 static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
28 RESERVE_CONFIG_BUFFER(buffer,BUFSIZ);
30 if (src_fd < 0) goto out;
31 while (!size || total < size) {
34 rd = safe_read(src_fd, buffer,
35 (!size || size - total > BUFSIZ) ? BUFSIZ : size - total);
38 /* A -1 dst_fd means we need to fake it... */
39 wr = (dst_fd < 0) ? rd : full_write(dst_fd, buffer, rd);
41 bb_perror_msg(bb_msg_write_error);
45 if (total == size) status = 0;
47 bb_perror_msg(bb_msg_read_error);
57 RELEASE_CONFIG_BUFFER(buffer);
59 return status ? status : total;
63 off_t bb_copyfd_size(int fd1, int fd2, off_t size)
66 return bb_full_fd_action(fd1, fd2, size);
71 off_t bb_copyfd_eof(int fd1, int fd2)
73 return bb_full_fd_action(fd1, fd2, 0);