summaryrefslogtreecommitdiff
path: root/ext/ftp
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2004-03-18 17:12:07 +0000
committerIlia Alshanetsky <iliaa@php.net>2004-03-18 17:12:07 +0000
commitb176ee99d396ef598b74712cd9e87403bb0f2a23 (patch)
treeb26a2fd89bd59000402ac0c65a1a6b02e68e00e9 /ext/ftp
parent7767bacaf84905825ca6f73616de2084a7787b52 (diff)
downloadphp-git-b176ee99d396ef598b74712cd9e87403bb0f2a23.tar.gz
Fixed bug #27633 (Incorrect EOL translation by ftp_get() in ASCII mode).
Diffstat (limited to 'ext/ftp')
-rw-r--r--ext/ftp/ftp.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index fd3cd461ec..69a164c8b1 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -790,7 +790,6 @@ int
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 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type,
}
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)) {