iliaa Thu Mar 18 12:12:09 2004 EDT Modified files: /php-src/ext/ftp ftp.c Log: Fixed bug #27633 (Incorrect EOL translation by ftp_get() in ASCII mode). http://cvs.php.net/diff.php/php-src/ext/ftp/ftp.c?r1=1.101&r2=1.102&ty=u Index: php-src/ext/ftp/ftp.c diff -u php-src/ext/ftp/ftp.c:1.101 php-src/ext/ftp/ftp.c:1.102 --- php-src/ext/ftp/ftp.c:1.101 Thu Mar 4 17:24:27 2004 +++ php-src/ext/ftp/ftp.c Thu Mar 18 12:12:07 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ftp.c,v 1.101 2004/03/04 22:24:27 pollita Exp $ */ +/* $Id: ftp.c,v 1.102 2004/03/18 17:12:07 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -790,7 +790,6 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, int resumepos TSRMLS_DC) { databuf_t *data = NULL; - char *ptr; int lastch; size_t rcvd; char arg[11]; @@ -840,22 +839,45 @@ } if (type == FTPTYPE_ASCII) { - for (ptr = data->buf; rcvd; rcvd--, ptr++) { - if (lastch == '\r' && *ptr != '\n') + char *s; + char *ptr = data->buf; + char *e = ptr + rcvd; + /* logic depends on the OS EOL + * Win32 -> \r\n + * Everything Else \n + */ +#ifdef PHP_WIN32 + while ((s = strpbrk(ptr, "\r\n"))) { + if (*s == '\n') { php_stream_putc(outstream, '\r'); - if (*ptr != '\r') - php_stream_putc(outstream, *ptr); - lastch = *ptr; + } else if (*s == '\r' && *(s + 1) == '\n') { + s++; + } + s++; + php_stream_write(outstream, ptr, (s - ptr)); + if (*(s - 1) == '\r') { + php_stream_putc(outstream, '\n'); + } + ptr = s; + } +#else + while ((s = memchr(ptr, '\r', (e - ptr)))) { + php_stream_write(outstream, ptr, (s - ptr)); + if (*(s + 1) == '\n') { + s++; + } + php_stream_putc(outstream, '\n'); + ptr = s + 1; + } +#endif + if (ptr < e) { + php_stream_write(outstream, ptr, (e - ptr)); } } else if (rcvd != php_stream_write(outstream, data->buf, rcvd)) { goto bail; } } - if (type == FTPTYPE_ASCII && lastch == '\r') { - php_stream_putc(outstream, '\r'); - } - ftp->data = data = data_close(ftp, data); if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php