diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-11-21 22:24:57 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-11-21 22:24:57 +0000 |
commit | 7ffe1338647d2b890df3ae46e526410b21a90d18 (patch) | |
tree | e949e5879a7083bac9e2da249363f9c613d0a409 | |
parent | 1a2d75fd7273e8de936e5fd91462bdff381f9b62 (diff) | |
download | busybox-w32-7ffe1338647d2b890df3ae46e526410b21a90d18.tar.gz busybox-w32-7ffe1338647d2b890df3ae46e526410b21a90d18.tar.bz2 busybox-w32-7ffe1338647d2b890df3ae46e526410b21a90d18.zip |
As we no longer use function pointers for read in common archiving code
archive_xread can be replaced with bb_full_read, and archive_copy_file
with bb_copyfd*
bb_copyfd is split into two functions bb_copyfd_size and bb_copyfd_eof,
they share a common backend.
-rw-r--r-- | archival/ar.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/Makefile.in | 3 | ||||
-rw-r--r-- | archival/libunarchive/archive_copy_file.c | 44 | ||||
-rw-r--r-- | archival/libunarchive/archive_xread.c | 33 | ||||
-rw-r--r-- | archival/libunarchive/archive_xread_all.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/archive_xread_all_eof.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/data_extract_all.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/data_extract_to_stdout.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/seek_by_char.c | 16 | ||||
-rw-r--r-- | archival/tar.c | 17 | ||||
-rw-r--r-- | coreutils/cat.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | include/unarchive.h | 2 | ||||
-rw-r--r-- | libbb/copy_file.c | 2 | ||||
-rw-r--r-- | libbb/copyfd.c | 61 | ||||
-rw-r--r-- | libbb/print_file.c | 2 | ||||
-rw-r--r-- | networking/ftpgetput.c | 4 |
18 files changed, 55 insertions, 148 deletions
diff --git a/archival/ar.c b/archival/ar.c index 57ec92719..32ecd5736 100644 --- a/archival/ar.c +++ b/archival/ar.c | |||
@@ -59,7 +59,7 @@ static void data_extract_regular_file(archive_handle_t *archive_handle) | |||
59 | 59 | ||
60 | file_header = archive_handle->file_header; | 60 | file_header = archive_handle->file_header; |
61 | dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT); | 61 | dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT); |
62 | archive_copy_file(archive_handle, dst_fd); | 62 | bb_copyfd_eof(archive_handle->src_fd, dst_fd, file_header->size); |
63 | close(dst_fd); | 63 | close(dst_fd); |
64 | 64 | ||
65 | chmod(file_header->name, file_header->mode); | 65 | chmod(file_header->name, file_header->mode); |
diff --git a/archival/libunarchive/Makefile.in b/archival/libunarchive/Makefile.in index c9dec09ad..09b0571ed 100644 --- a/archival/libunarchive/Makefile.in +++ b/archival/libunarchive/Makefile.in | |||
@@ -37,15 +37,12 @@ LIBUNARCHIVE-y:= \ | |||
37 | header_list.o \ | 37 | header_list.o \ |
38 | header_verbose_list.o \ | 38 | header_verbose_list.o \ |
39 | \ | 39 | \ |
40 | archive_xread.o \ | ||
41 | archive_xread_all.o \ | 40 | archive_xread_all.o \ |
42 | archive_xread_all_eof.o \ | 41 | archive_xread_all_eof.o \ |
43 | \ | 42 | \ |
44 | seek_by_char.o \ | 43 | seek_by_char.o \ |
45 | seek_by_jump.o \ | 44 | seek_by_jump.o \ |
46 | \ | 45 | \ |
47 | archive_copy_file.o \ | ||
48 | \ | ||
49 | data_align.o \ | 46 | data_align.o \ |
50 | find_list_entry.o \ | 47 | find_list_entry.o \ |
51 | open_transformer.o \ | 48 | open_transformer.o \ |
diff --git a/archival/libunarchive/archive_copy_file.c b/archival/libunarchive/archive_copy_file.c deleted file mode 100644 index 675bc6ffe..000000000 --- a/archival/libunarchive/archive_copy_file.c +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License as published by | ||
4 | * the Free Software Foundation; either version 2 of the License, or | ||
5 | * (at your option) any later version. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
15 | */ | ||
16 | |||
17 | #include <unistd.h> | ||
18 | |||
19 | #include "libbb.h" | ||
20 | #include "unarchive.h" | ||
21 | |||
22 | extern void archive_copy_file(const archive_handle_t *archive_handle, const int dst_fd) | ||
23 | { | ||
24 | char buffer[512]; | ||
25 | off_t chunksize = archive_handle->file_header->size; | ||
26 | |||
27 | while (chunksize != 0) { | ||
28 | size_t size; | ||
29 | if (chunksize > 512) { | ||
30 | size = 512; | ||
31 | } else { | ||
32 | size = chunksize; | ||
33 | } | ||
34 | // archive_xread_all(archive_handle, buffer, size); | ||
35 | size = archive_xread(archive_handle, buffer, size); | ||
36 | |||
37 | if (write(dst_fd, buffer, size) != size) { | ||
38 | bb_error_msg_and_die ("Short write"); | ||
39 | } | ||
40 | chunksize -= size; | ||
41 | } | ||
42 | |||
43 | return; | ||
44 | } | ||
diff --git a/archival/libunarchive/archive_xread.c b/archival/libunarchive/archive_xread.c deleted file mode 100644 index 59b4d77a8..000000000 --- a/archival/libunarchive/archive_xread.c +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License as published by | ||
4 | * the Free Software Foundation; either version 2 of the License, or | ||
5 | * (at your option) any later version. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU Library General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | #include <stdlib.h> | ||
19 | #include <string.h> | ||
20 | #include "unarchive.h" | ||
21 | #include "libbb.h" | ||
22 | |||
23 | extern ssize_t archive_xread(const archive_handle_t *archive_handle, unsigned char *buf, const size_t count) | ||
24 | { | ||
25 | ssize_t size; | ||
26 | |||
27 | size = bb_full_read(archive_handle->src_fd, buf, count); | ||
28 | if (size < 0) { | ||
29 | bb_perror_msg_and_die("Read error"); | ||
30 | } | ||
31 | |||
32 | return(size); | ||
33 | } | ||
diff --git a/archival/libunarchive/archive_xread_all.c b/archival/libunarchive/archive_xread_all.c index cfe046b27..ba9ade2d5 100644 --- a/archival/libunarchive/archive_xread_all.c +++ b/archival/libunarchive/archive_xread_all.c | |||
@@ -24,7 +24,7 @@ extern void archive_xread_all(const archive_handle_t *archive_handle, void *buf, | |||
24 | { | 24 | { |
25 | ssize_t size; | 25 | ssize_t size; |
26 | 26 | ||
27 | size = archive_xread(archive_handle, buf, count); | 27 | size = bb_full_read(archive_handle->src_fd, buf, count); |
28 | if (size != count) { | 28 | if (size != count) { |
29 | bb_error_msg_and_die("Short read"); | 29 | bb_error_msg_and_die("Short read"); |
30 | } | 30 | } |
diff --git a/archival/libunarchive/archive_xread_all_eof.c b/archival/libunarchive/archive_xread_all_eof.c index 23719cd7b..8084e3524 100644 --- a/archival/libunarchive/archive_xread_all_eof.c +++ b/archival/libunarchive/archive_xread_all_eof.c | |||
@@ -24,7 +24,7 @@ extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned | |||
24 | { | 24 | { |
25 | ssize_t size; | 25 | ssize_t size; |
26 | 26 | ||
27 | size = archive_xread(archive_handle, buf, count); | 27 | size = bb_full_read(archive_handle->src_fd, buf, count); |
28 | if ((size != 0) && (size != count)) { | 28 | if ((size != 0) && (size != count)) { |
29 | bb_perror_msg_and_die("Short read, read %d of %d", size, count); | 29 | bb_perror_msg_and_die("Short read, read %d of %d", size, count); |
30 | } | 30 | } |
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c index 4dccb815d..bf3be5b35 100644 --- a/archival/libunarchive/data_extract_all.c +++ b/archival/libunarchive/data_extract_all.c | |||
@@ -79,7 +79,7 @@ extern void data_extract_all(archive_handle_t *archive_handle) | |||
79 | case S_IFREG: { | 79 | case S_IFREG: { |
80 | /* Regular file */ | 80 | /* Regular file */ |
81 | dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL); | 81 | dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL); |
82 | archive_copy_file(archive_handle, dst_fd); | 82 | bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size); |
83 | close(dst_fd); | 83 | close(dst_fd); |
84 | break; | 84 | break; |
85 | } | 85 | } |
diff --git a/archival/libunarchive/data_extract_to_stdout.c b/archival/libunarchive/data_extract_to_stdout.c index 8be2fa2e9..ce5d4b8d0 100644 --- a/archival/libunarchive/data_extract_to_stdout.c +++ b/archival/libunarchive/data_extract_to_stdout.c | |||
@@ -18,5 +18,5 @@ | |||
18 | 18 | ||
19 | extern void data_extract_to_stdout(archive_handle_t *archive_handle) | 19 | extern void data_extract_to_stdout(archive_handle_t *archive_handle) |
20 | { | 20 | { |
21 | archive_copy_file(archive_handle, fileno(stdout)); | 21 | bb_copyfd_eof(archive_handle->src_fd, fileno(stdout)); |
22 | } | 22 | } |
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index d55189f42..603535a4c 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -57,7 +57,7 @@ extern char get_header_tar(archive_handle_t *archive_handle) | |||
57 | /* Align header */ | 57 | /* Align header */ |
58 | data_align(archive_handle, 512); | 58 | data_align(archive_handle, 512); |
59 | 59 | ||
60 | if (archive_xread(archive_handle, tar.raw, 512) != 512) { | 60 | if (bb_full_read(archive_handle->src_fd, tar.raw, 512) != 512) { |
61 | /* Assume end of file */ | 61 | /* Assume end of file */ |
62 | return(EXIT_FAILURE); | 62 | return(EXIT_FAILURE); |
63 | } | 63 | } |
diff --git a/archival/libunarchive/seek_by_char.c b/archival/libunarchive/seek_by_char.c index 77da4ef2e..c0315616e 100644 --- a/archival/libunarchive/seek_by_char.c +++ b/archival/libunarchive/seek_by_char.c | |||
@@ -26,19 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size) | 27 | extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size) |
28 | { | 28 | { |
29 | unsigned int remaining = jump_size; | 29 | if (jump_size) { |
30 | unsigned int read_amount; | 30 | bb_full_fd_action(archive_handle->src_fd, -1, jump_size, NULL); |
31 | RESERVE_CONFIG_BUFFER(buf, BUFSIZ); | ||
32 | |||
33 | while (remaining > 0) { | ||
34 | if (remaining > BUFSIZ) { | ||
35 | read_amount = BUFSIZ; | ||
36 | } else { | ||
37 | read_amount = remaining; | ||
38 | } | ||
39 | read_amount = archive_xread(archive_handle, buf, read_amount); | ||
40 | remaining -= read_amount; | ||
41 | } | 31 | } |
42 | |||
43 | RELEASE_CONFIG_BUFFER(buf); | ||
44 | } | 32 | } |
diff --git a/archival/tar.c b/archival/tar.c index b3fa447f2..cf9bc04d3 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -414,8 +414,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, | |||
414 | if ((tbInfo->hlInfo == NULL) | 414 | if ((tbInfo->hlInfo == NULL) |
415 | && (S_ISREG(statbuf->st_mode))) { | 415 | && (S_ISREG(statbuf->st_mode))) { |
416 | int inputFileFd; | 416 | int inputFileFd; |
417 | char buffer[BUFSIZ]; | 417 | ssize_t readSize = 0; |
418 | ssize_t size = 0, readSize = 0; | ||
419 | 418 | ||
420 | /* open the file we want to archive, and make sure all is well */ | 419 | /* open the file we want to archive, and make sure all is well */ |
421 | if ((inputFileFd = open(fileName, O_RDONLY)) < 0) { | 420 | if ((inputFileFd = open(fileName, O_RDONLY)) < 0) { |
@@ -424,18 +423,8 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, | |||
424 | } | 423 | } |
425 | 424 | ||
426 | /* write the file to the archive */ | 425 | /* write the file to the archive */ |
427 | while ((size = bb_full_read(inputFileFd, buffer, sizeof(buffer))) > 0) { | 426 | readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd); |
428 | if (bb_full_write(tbInfo->tarFd, buffer, size) != size) { | 427 | |
429 | /* Output file seems to have a problem */ | ||
430 | bb_error_msg(bb_msg_io_error, fileName); | ||
431 | return (FALSE); | ||
432 | } | ||
433 | readSize += size; | ||
434 | } | ||
435 | if (size == -1) { | ||
436 | bb_error_msg(bb_msg_io_error, fileName); | ||
437 | return (FALSE); | ||
438 | } | ||
439 | /* Pad the file up to the tar block size */ | 428 | /* Pad the file up to the tar block size */ |
440 | for (; (readSize % TAR_BLOCK_SIZE) != 0; readSize++) { | 429 | for (; (readSize % TAR_BLOCK_SIZE) != 0; readSize++) { |
441 | write(tbInfo->tarFd, "\0", 1); | 430 | write(tbInfo->tarFd, "\0", 1); |
diff --git a/coreutils/cat.c b/coreutils/cat.c index 865275767..62af6c5d5 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -54,7 +54,7 @@ extern int cat_main(int argc, char **argv) | |||
54 | 54 | ||
55 | do { | 55 | do { |
56 | if ((f = bb_wfopen_input(*argv)) != NULL) { | 56 | if ((f = bb_wfopen_input(*argv)) != NULL) { |
57 | int r = bb_copyfd(fileno(f), STDOUT_FILENO, 0); | 57 | int r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); |
58 | bb_fclose_nonstdin(f); | 58 | bb_fclose_nonstdin(f); |
59 | if (r >= 0) { | 59 | if (r >= 0) { |
60 | continue; | 60 | continue; |
diff --git a/include/libbb.h b/include/libbb.h index 22a77e610..5ff49114b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -136,7 +136,8 @@ extern long *find_pid_by_name( const char* pidName); | |||
136 | extern char *find_real_root_device_name(const char* name); | 136 | extern char *find_real_root_device_name(const char* name); |
137 | extern char *bb_get_line_from_file(FILE *file); | 137 | extern char *bb_get_line_from_file(FILE *file); |
138 | extern char *bb_get_chomped_line_from_file(FILE *file); | 138 | extern char *bb_get_chomped_line_from_file(FILE *file); |
139 | extern int bb_copyfd(int fd1, int fd2, const off_t chunksize); | 139 | extern int bb_copyfd_size(int fd1, int fd2, const off_t size); |
140 | extern int bb_copyfd_eof(int fd1, int fd2); | ||
140 | extern void bb_xprint_and_close_file(FILE *file); | 141 | extern void bb_xprint_and_close_file(FILE *file); |
141 | extern int bb_xprint_file_by_name(const char *filename); | 142 | extern int bb_xprint_file_by_name(const char *filename); |
142 | extern char bb_process_escape_sequence(const char **ptr); | 143 | extern char bb_process_escape_sequence(const char **ptr); |
@@ -480,6 +481,6 @@ extern void xregcomp(regex_t *preg, const char *regex, int cflags); | |||
480 | #define HASH_SHA1 1 | 481 | #define HASH_SHA1 1 |
481 | #define HASH_MD5 2 | 482 | #define HASH_MD5 2 |
482 | extern int hash_fd(int fd, const size_t size, const uint8_t hash_algo, uint8_t *hashval); | 483 | extern int hash_fd(int fd, const size_t size, const uint8_t hash_algo, uint8_t *hashval); |
483 | 484 | extern size_t bb_full_fd_action(int src_fd, int dst_fd, const size_t size, ssize_t (*action)(int fd, const void *, size_t)); | |
484 | 485 | ||
485 | #endif /* __LIBCONFIG_H__ */ | 486 | #endif /* __LIBCONFIG_H__ */ |
diff --git a/include/unarchive.h b/include/unarchive.h index 79ee99e37..bbf11b557 100644 --- a/include/unarchive.h +++ b/include/unarchive.h | |||
@@ -90,12 +90,10 @@ extern char get_header_tar_gz(archive_handle_t *archive_handle); | |||
90 | extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount); | 90 | extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount); |
91 | extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int amount); | 91 | extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int amount); |
92 | 92 | ||
93 | extern ssize_t archive_xread(const archive_handle_t *archive_handle, unsigned char *buf, const size_t count); | ||
94 | extern void archive_xread_all(const archive_handle_t *archive_handle, void *buf, const size_t count); | 93 | extern void archive_xread_all(const archive_handle_t *archive_handle, void *buf, const size_t count); |
95 | extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count); | 94 | extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count); |
96 | 95 | ||
97 | extern void data_align(archive_handle_t *archive_handle, const unsigned short boundary); | 96 | extern void data_align(archive_handle_t *archive_handle, const unsigned short boundary); |
98 | extern void archive_copy_file(const archive_handle_t *archive_handle, const int dst_fd); | ||
99 | extern const llist_t *find_list_entry(const llist_t *list, const char *filename); | 97 | extern const llist_t *find_list_entry(const llist_t *list, const char *filename); |
100 | 98 | ||
101 | extern int uncompressStream(int src_fd, int dst_fd); | 99 | extern int uncompressStream(int src_fd, int dst_fd); |
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 5808ca48c..c9d239f9a 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -181,7 +181,7 @@ int copy_file(const char *source, const char *dest, int flags) | |||
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | if (bb_copyfd(fileno(sfp), fileno(dfp), 0) == -1) | 184 | if (bb_copyfd_eof(fileno(sfp), fileno(dfp)) == -1) |
185 | status = -1; | 185 | status = -1; |
186 | 186 | ||
187 | if (fclose(dfp) < 0) { | 187 | if (fclose(dfp) < 0) { |
diff --git a/libbb/copyfd.c b/libbb/copyfd.c index 05bed6b73..0787c812f 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c | |||
@@ -29,44 +29,55 @@ | |||
29 | #define BUFSIZ 4096 | 29 | #define BUFSIZ 4096 |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | /* If chunksize is 0 copy until EOF */ | 32 | /* If size is 0 copy until EOF */ |
33 | extern int bb_copyfd(int fd1, int fd2, const off_t chunksize) | 33 | extern size_t bb_full_fd_action(int src_fd, int dst_fd, const size_t size, ssize_t (*action)(int fd, const void *, size_t)) |
34 | { | 34 | { |
35 | ssize_t nread; | 35 | size_t read_total = 0; |
36 | size_t size; | ||
37 | off_t remaining; | ||
38 | RESERVE_CONFIG_BUFFER(buffer,BUFSIZ); | 36 | RESERVE_CONFIG_BUFFER(buffer,BUFSIZ); |
39 | 37 | ||
40 | remaining = size = BUFSIZ; | 38 | while ((size == 0) || (read_total < size)) { |
41 | if (chunksize) { | 39 | size_t read_try; |
42 | remaining = chunksize; | 40 | ssize_t read_actual; |
43 | } | ||
44 | 41 | ||
45 | do { | 42 | if ((size == 0) || (size - read_total > BUFSIZ)) { |
46 | if (size > remaining) { | 43 | read_try = BUFSIZ; |
47 | size = remaining; | 44 | } else { |
45 | read_try = size - read_total; | ||
48 | } | 46 | } |
49 | 47 | ||
50 | if ((nread = safe_read(fd1, buffer, size)) > 0) { | 48 | read_actual = safe_read(src_fd, buffer, read_try); |
51 | if (bb_full_write(fd2, buffer, nread) < 0) { | 49 | if (read_actual > 0) { |
50 | if (action && (action(dst_fd, buffer, (size_t) read_actual) != read_actual)) { | ||
52 | bb_perror_msg(bb_msg_write_error); /* match Read error below */ | 51 | bb_perror_msg(bb_msg_write_error); /* match Read error below */ |
53 | break; | 52 | break; |
54 | } | 53 | } |
55 | if (chunksize && ((remaining -= nread) == 0)) { | 54 | } |
56 | return 0; | 55 | else if (read_actual == 0) { |
57 | } | 56 | if (size) { |
58 | } else if (!nread) { | ||
59 | if (chunksize) { | ||
60 | bb_error_msg("Unable to read all data"); | 57 | bb_error_msg("Unable to read all data"); |
61 | break; | ||
62 | } | 58 | } |
63 | return 0; | 59 | break; |
64 | } else { /* nread < 0 */ | 60 | } else { |
65 | bb_perror_msg("Read error"); /* match bb_msg_write_error above */ | 61 | /* read_actual < 0 */ |
62 | bb_perror_msg("Read error"); | ||
66 | break; | 63 | break; |
67 | } | 64 | } |
68 | 65 | ||
69 | } while (1); | 66 | read_total += read_actual; |
67 | } | ||
68 | |||
69 | RELEASE_CONFIG_BUFFER(buffer); | ||
70 | 70 | ||
71 | return -1; | 71 | return(read_total); |
72 | } | ||
73 | |||
74 | |||
75 | extern int bb_copyfd_size(int fd1, int fd2, const off_t size) | ||
76 | { | ||
77 | return(bb_full_fd_action(fd1, fd2, size, bb_full_write)); | ||
78 | } | ||
79 | |||
80 | extern int bb_copyfd_eof(int fd1, int fd2) | ||
81 | { | ||
82 | return(bb_full_fd_action(fd1, fd2, 0, bb_full_write)); | ||
72 | } | 83 | } |
diff --git a/libbb/print_file.c b/libbb/print_file.c index 6d3667b60..161b398fa 100644 --- a/libbb/print_file.c +++ b/libbb/print_file.c | |||
@@ -28,7 +28,7 @@ extern void bb_xprint_and_close_file(FILE *file) | |||
28 | bb_xfflush_stdout(); | 28 | bb_xfflush_stdout(); |
29 | /* Note: Do not use STDOUT_FILENO here, as this is a lib routine | 29 | /* Note: Do not use STDOUT_FILENO here, as this is a lib routine |
30 | * and the calling code may have reassigned stdout. */ | 30 | * and the calling code may have reassigned stdout. */ |
31 | if (bb_copyfd(fileno(file), fileno(stdout), 0) == -1) { | 31 | if (bb_copyfd_eof(fileno(file), fileno(stdout)) == -1) { |
32 | /* bb_copyfd outputs any needed messages, so just die. */ | 32 | /* bb_copyfd outputs any needed messages, so just die. */ |
33 | exit(bb_default_error_retval); | 33 | exit(bb_default_error_retval); |
34 | } | 34 | } |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 56223dccb..2fd50e4c4 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -210,7 +210,7 @@ static int ftp_recieve(ftp_host_info_t *server, FILE *control_stream, | |||
210 | } | 210 | } |
211 | 211 | ||
212 | /* Copy the file */ | 212 | /* Copy the file */ |
213 | if (bb_copyfd(fd_data, fd_local, filesize) == -1) { | 213 | if (bb_copyfd_size(fd_data, fd_local, filesize) == -1) { |
214 | exit(EXIT_FAILURE); | 214 | exit(EXIT_FAILURE); |
215 | } | 215 | } |
216 | 216 | ||
@@ -272,7 +272,7 @@ static int ftp_send(ftp_host_info_t *server, FILE *control_stream, | |||
272 | } | 272 | } |
273 | 273 | ||
274 | /* transfer the file */ | 274 | /* transfer the file */ |
275 | if (bb_copyfd(fd_local, fd_data, 0) == -1) { | 275 | if (bb_copyfd_eof(fd_local, fd_data) == -1) { |
276 | exit(EXIT_FAILURE); | 276 | exit(EXIT_FAILURE); |
277 | } | 277 | } |
278 | 278 | ||