]> granicus.if.org Git - php/commitdiff
Fixed bug #27633 (Double \r\r problem on ftp_get in ASCII mode on Win32).
authorIlia Alshanetsky <iliaa@php.net>
Thu, 17 Feb 2005 15:37:24 +0000 (15:37 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 17 Feb 2005 15:37:24 +0000 (15:37 +0000)
ext/ftp/ftp.c

index 345cbc5731ec705653a328a4ea3cacc455663e25..51cccab02b2060ababc41693310e6435f0454353 100644 (file)
@@ -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;
                        }