aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-11-04 01:20:46 +0000
committerRob Landley <rob@landley.net>2005-11-04 01:20:46 +0000
commit21ccbb6c0e80ca8374b7868a4d9dbc61a87f6297 (patch)
treeeddd5c1d7a21517c213d24bbee5b0b2c23eb1ece /libbb
parentc2ce2c5b4b014e4c0e664c70680ab6b5d54ed9b8 (diff)
downloadbusybox-w32-21ccbb6c0e80ca8374b7868a4d9dbc61a87f6297.tar.gz
busybox-w32-21ccbb6c0e80ca8374b7868a4d9dbc61a87f6297.tar.bz2
busybox-w32-21ccbb6c0e80ca8374b7868a4d9dbc61a87f6297.zip
When cp ran out of space it didn't return a nonzero error code. Fixes bug 493.
Diffstat (limited to 'libbb')
-rw-r--r--libbb/copyfd.c84
1 files changed, 27 insertions, 57 deletions
diff --git a/libbb/copyfd.c b/libbb/copyfd.c
index 27d65a419..591548379 100644
--- a/libbb/copyfd.c
+++ b/libbb/copyfd.c
@@ -4,19 +4,7 @@
4 * 4 *
5 * Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> 5 * Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 8 */
21 9
22#include <errno.h> 10#include <errno.h>
@@ -34,59 +22,41 @@
34#endif 22#endif
35 23
36 24
37static size_t bb_full_fd_action(int src_fd, int dst_fd, const size_t size2) 25static ssize_t bb_full_fd_action(int src_fd, int dst_fd, size_t size)
38{ 26{
39 int status; 27 int status = -1;
40 size_t xread, wrote, total, size = size2; 28 size_t total = 0;
41 29 RESERVE_CONFIG_BUFFER(buffer,BUFSIZ);
42 if (src_fd < 0) {
43 return -1;
44 }
45 30
46 if (size == 0) { 31 if (src_fd < 0) goto out;
47 /* If size is 0 copy until EOF */
48 size = ULONG_MAX;
49 }
50 32
33 while (!size || total < size)
51 { 34 {
52 RESERVE_CONFIG_BUFFER(buffer,BUFSIZ); 35 ssize_t wrote, xread = (size && size < BUFSIZ) ? size : BUFSIZ;
53 total = 0; 36 xread = bb_full_read(src_fd, buffer, xread);
54 wrote = 0; 37 if (xread > 0) {
55 status = -1; 38 /* A -1 dst_fd means we need to fake it... */
56 while (total < size) 39 wrote = (dst_fd < 0) ? xread : bb_full_write(dst_fd, buffer, xread);
57 { 40 if (wrote < xread) {
58 xread = BUFSIZ; 41 bb_perror_msg(bb_msg_write_error);
59 if (size < (total + BUFSIZ))
60 xread = size - total;
61 xread = bb_full_read(src_fd, buffer, xread);
62 if (xread > 0) {
63 if (dst_fd < 0) {
64 /* A -1 dst_fd means we need to fake it... */
65 wrote = xread;
66 } else {
67 wrote = bb_full_write(dst_fd, buffer, xread);
68 }
69 if (wrote < xread) {
70 bb_perror_msg(bb_msg_write_error);
71 break;
72 }
73 total += wrote;
74 } else if (xread < 0) {
75 bb_perror_msg(bb_msg_read_error);
76 break;
77 } else if (xread == 0) {
78 /* All done. */
79 status = 0;
80 break; 42 break;
81 } 43 }
44 total += wrote;
45 size -= wrote;
46 } else if (xread < 0) {
47 bb_perror_msg(bb_msg_read_error);
48 break;
49 } else if (xread == 0) {
50 /* All done. */
51 status = 0;
52 break;
82 } 53 }
83 RELEASE_CONFIG_BUFFER(buffer);
84 } 54 }
55
56out:
57 RELEASE_CONFIG_BUFFER(buffer);
85 58
86 if (status == 0 || total) 59 return status ? status : total;
87 return total;
88 /* Some sortof error occured */
89 return -1;
90} 60}
91 61
92 62