aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-12-13 08:20:44 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-12-13 08:20:44 +0000
commit25fe94fd32f39a76294456a7bc7b8dd0595afb0d (patch)
tree5f41636eb6f772de78a17e90189da6aeee3f32a7 /networking
parenta67dffe186eefb6cf75c08422dbfa0e4a752c692 (diff)
downloadbusybox-w32-25fe94fd32f39a76294456a7bc7b8dd0595afb0d.tar.gz
busybox-w32-25fe94fd32f39a76294456a7bc7b8dd0595afb0d.tar.bz2
busybox-w32-25fe94fd32f39a76294456a7bc7b8dd0595afb0d.zip
Merge copyfd and copy_file_chunk
Diffstat (limited to 'networking')
-rw-r--r--networking/ftpgetput.c53
1 files changed, 6 insertions, 47 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index 909f3b117..a23c64af1 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -56,51 +56,6 @@ typedef struct ftp_host_info_s {
56static char verbose_flag; 56static char verbose_flag;
57static char do_continue = 0; 57static char do_continue = 0;
58 58
59static int copyfd_chunk(int fd1, int fd2, const off_t chunksize)
60{
61 size_t nread;
62 size_t nwritten;
63 size_t size;
64 size_t remaining;
65 char buffer[BUFSIZ];
66
67 if (chunksize) {
68 remaining = chunksize;
69 } else {
70 remaining = -1;
71 }
72
73 do {
74 if ((chunksize > BUFSIZ) || (chunksize == 0)) {
75 size = BUFSIZ;
76 } else {
77 size = chunksize;
78 }
79
80 nread = safe_read(fd1, buffer, size);
81
82 if (nread <= 0) {
83 if (chunksize) {
84 perror_msg_and_die("read error");
85 } else {
86 return(0);
87 }
88 }
89
90 nwritten = full_write(fd2, buffer, nread);
91
92 if (nwritten != nread) {
93 error_msg_and_die("Unable to write all data");
94 }
95
96 if (chunksize) {
97 remaining -= nwritten;
98 }
99 } while (remaining != 0);
100
101 return 0;
102}
103
104static ftp_host_info_t *ftp_init(void) 59static ftp_host_info_t *ftp_init(void)
105{ 60{
106 ftp_host_info_t *host; 61 ftp_host_info_t *host;
@@ -252,7 +207,9 @@ static int ftp_recieve(FILE *control_stream, const char *host, const char *local
252 } 207 }
253 208
254 /* Copy the file */ 209 /* Copy the file */
255 copyfd_chunk(fd_data, fd_local, filesize); 210 if (copyfd(fd_data, fd_local, filesize) == -1) {
211 exit(EXIT_FAILURE);
212 }
256 213
257 /* close it all down */ 214 /* close it all down */
258 close(fd_data); 215 close(fd_data);
@@ -311,7 +268,9 @@ static int ftp_send(FILE *control_stream, const char *host, const char *server_p
311 } 268 }
312 269
313 /* transfer the file */ 270 /* transfer the file */
314 copyfd_chunk(fd_local, fd_data, 0); 271 if (copyfd(fd_local, fd_data, 0) == -1) {
272 exit(EXIT_FAILURE);
273 }
315 274
316 /* close it all down */ 275 /* close it all down */
317 close(fd_data); 276 close(fd_data);