diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-11-04 01:20:46 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-11-04 01:20:46 +0000 |
commit | 59783584ea92ebb97711b7218303eea1454d7780 (patch) | |
tree | eddd5c1d7a21517c213d24bbee5b0b2c23eb1ece /libbb | |
parent | aa7cf10d1c00cc8a36cf6791458e4c6e230ceb78 (diff) | |
download | busybox-w32-59783584ea92ebb97711b7218303eea1454d7780.tar.gz busybox-w32-59783584ea92ebb97711b7218303eea1454d7780.tar.bz2 busybox-w32-59783584ea92ebb97711b7218303eea1454d7780.zip |
When cp ran out of space it didn't return a nonzero error code. Fixes bug 493.
git-svn-id: svn://busybox.net/trunk/busybox@12146 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/copyfd.c | 84 |
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 | ||
37 | static size_t bb_full_fd_action(int src_fd, int dst_fd, const size_t size2) | 25 | static 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 | |||
56 | out: | ||
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 | ||