[BusyBox-cvs] busybox/networking ftpgetput.c,1.1,1.2
Glenn McGrath
bug1 at busybox.net
Fri Dec 13 04:14:39 UTC 2002
Update of /var/cvs/busybox/networking
In directory winder:/tmp/cvs-serv19615/networking
Modified Files:
ftpgetput.c
Log Message:
Fix possible bug if file length not known
Index: ftpgetput.c
===================================================================
RCS file: /var/cvs/busybox/networking/ftpgetput.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ftpgetput.c 13 Dec 2002 02:43:50 -0000 1.1
+++ ftpgetput.c 13 Dec 2002 04:14:36 -0000 1.2
@@ -56,14 +56,20 @@
static char verbose_flag;
static char do_continue = 0;
-/* If chunksize == 0 read till end of file */
-static int copyfd_chunk(int fd1, int fd2, off_t chunksize)
+static int copyfd_chunk(int fd1, int fd2, const off_t chunksize)
{
size_t nread;
size_t nwritten;
size_t size;
+ size_t remaining;
char buffer[BUFSIZ];
+ if (chunksize) {
+ remaining = chunksize;
+ } else {
+ remaining = -1;
+ }
+
do {
if ((chunksize > BUFSIZ) || (chunksize == 0)) {
size = BUFSIZ;
@@ -73,7 +79,7 @@
nread = safe_read(fd1, buffer, size);
- if (nread < 0) {
+ if (nread <= 0) {
if (chunksize) {
perror_msg_and_die("read error");
} else {
@@ -88,10 +94,9 @@
}
if (chunksize) {
- chunksize -= nwritten;
+ remaining -= nwritten;
}
-
- } while (chunksize);
+ } while (remaining != 0);
return 0;
}
More information about the busybox-cvs
mailing list