+ if (flags & rb_ftp_ascii)
+ {
+ const char *bufend;
+
+ /* ASCII transfer. Put out lines delimited by CRLF. */
+ bufend = buf+ bufsize;
+ while (buf < bufend)
+ {
+ /* If CR, put out any pending CR, then set CR-pending flag. */
+ if (*buf == '\r')
+ {
+ if (cr_pending)
+ {
+ fwrite ("\r", 1, 1, out);
+ *written += 1;
+ }
+ cr_pending = 1;
+ buf++;
+ continue;
+ }
+
+ if (cr_pending)
+ {
+ if (*buf == '\n')
+ {
+ /* Found FTP EOL (CRLF). Put out local EOL. */
+ fwrite (EOL_STRING, 1, EOL_STRING_LEN, out);
+ *written += EOL_STRING_LEN;
+ }
+ else
+ {
+ /* Normal character. Put out pending CR and it. */
+ fwrite ("\r", 1, 1, out);
+ fwrite (buf, 1, 1, out);
+ *written += 2;
+ }
+ buf++;
+ cr_pending = 0;
+ }
+ else
+ {
+ /* Normal character. Put it out. */
+ fwrite (buf, 1, 1, out);
+ *written += 1;
+ buf++;
+ }
+ }
+ }
+ else
+ {
+ /* Image transfer. Put out buffer. */
+ fwrite (buf, 1, bufsize, out);
+ *written += bufsize;
+ }
+
+ /* Immediately flush the downloaded data. This should not hinder
+ performance: fast downloads will arrive in large 16K chunks
+ (which stdio would write out immediately anyway), and slow
+ downloads wouldn't be limited by disk speed. */
+
+ /* 2005-04-20 SMS.
+ Perhaps it shouldn't hinder performance, but it sure does, at least
+ on VMS (more than 2X). Rather than speculate on what it should or
+ shouldn't do, it might make more sense to test it. Even better, it
+ might be nice to explain what possible benefit it could offer, as
+ it appears to be a clear invitation to poor performance with no
+ actual justification. (Also, why 16K? Anyone test other values?)
+ */
+#ifndef __VMS
+ fflush (out);
+#endif /* ndef __VMS */
+ return !ferror (out);
+}
+
+/* Read the contents of file descriptor FD until it the connection
+ terminates or a read error occurs. The data is read in portions of
+ up to 16K and written to OUT as it arrives. If opt.verbose is set,
+ the progress is shown.
+
+ TOREAD is the amount of data expected to arrive, normally only used
+ by the progress gauge.
+
+ STARTPOS is the position from which the download starts, used by
+ the progress gauge. If QTYREAD is non-NULL, the value it points to
+ is incremented by the amount of data read from the network. If
+ QTYWRITTEN is non-NULL, the value it points to is incremented by
+ the amount of data written to disk. The time it took to download
+ the data is stored to ELAPSED.
+
+ The function exits and returns the amount of data read. In case of
+ error while reading data, -1 is returned. In case of error while
+ writing data, -2 is returned. */