From f2eb0acfcf3f484cd1650cfc3861f2519102a751 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 17 Feb 2005 15:37:24 +0000 Subject: [PATCH] Fixed bug #27633 (Double \r\r problem on ftp_get in ASCII mode on Win32). --- ext/ftp/ftp.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 345cbc5731..51cccab02b 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -846,16 +846,22 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, * Everything Else \n */ #ifdef PHP_WIN32 - while ((s = strpbrk(ptr, "\r\n"))) { - if (*s == '\n') { - php_stream_putc(outstream, '\r'); - } else if (*s == '\r' && *(s + 1) == '\n') { - s++; - } - s++; + while ((s = strpbrk(ptr, "\r\n")) && (s < e)) { php_stream_write(outstream, ptr, (s - ptr)); - if (*(s - 1) == '\r') { - php_stream_putc(outstream, '\n'); + php_stream_write(outstream, "\r\n", sizeof("\r\n")-1); + + if (*s == '\r') { + *s++; + } + /* for some reason some servers prefix a \r before a \n, + * resulting in a \r\r\n in the buffer when + * the remote file already has windoze style line endings. + */ + if (*s == '\r') { + *s++; + } + if (*s == '\n') { + *s++; } ptr = s; } -- 2.40.0