cvs: php4 /ext/ftp php_ftp.c /ext/standard file.c /main php_streams.h streams.c

From: Date: Sat, 16 Mar 2002 02:48:35 +0000
Subject: cvs: php4 /ext/ftp php_ftp.c /ext/standard file.c /main php_streams.h streams.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10205@lists.php.net to get a copy of this message
wez Fri Mar 15 21:48:35 2002 EDT Modified files: /php4/ext/ftp php_ftp.c /php4/ext/standard file.c /php4/main php_streams.h streams.c Log: Allow php_stream_copy_to_stream to do nothing when used with code that calculates a max length of zero. (Thanks again Marcus). Index: php4/ext/ftp/php_ftp.c diff -u php4/ext/ftp/php_ftp.c:1.55 php4/ext/ftp/php_ftp.c:1.56 --- php4/ext/ftp/php_ftp.c:1.55 Fri Mar 15 21:32:59 2002 +++ php4/ext/ftp/php_ftp.c Fri Mar 15 21:48:35 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_ftp.c,v 1.55 2002/03/16 02:32:59 wez Exp $ */ +/* $Id: php_ftp.c,v 1.56 2002/03/16 02:48:35 wez Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -489,7 +489,7 @@ } php_stream_rewind(tmpstream); - if (php_stream_copy_to_stream(tmpstream, outstream, 0) == 0) { + if (php_stream_copy_to_stream(tmpstream, outstream, PHP_STREAM_COPY_ALL) == 0) { php_error(E_WARNING, "%s(): error writing %s", get_active_function_name(TSRMLS_C), local); RETVAL_FALSE; } Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.208 php4/ext/standard/file.c:1.209 --- php4/ext/standard/file.c:1.208 Fri Mar 15 21:32:59 2002 +++ php4/ext/standard/file.c Fri Mar 15 21:48:35 2002 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.208 2002/03/16 02:32:59 wez Exp $ */ +/* $Id: file.c,v 1.209 2002/03/16 02:48:35 wez Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1658,7 +1658,7 @@ NULL TSRMLS_CC); if (srcstream && deststream) - ret = php_stream_copy_to_stream(srcstream, deststream, 0) == 0 ? FAILURE : SUCCESS; + ret = php_stream_copy_to_stream(srcstream, deststream, PHP_STREAM_COPY_ALL) == 0 ? FAILURE : SUCCESS; if (srcstream) php_stream_close(srcstream); Index: php4/main/php_streams.h diff -u php4/main/php_streams.h:1.9 php4/main/php_streams.h:1.10 --- php4/main/php_streams.h:1.9 Fri Mar 15 20:58:13 2002 +++ php4/main/php_streams.h Fri Mar 15 21:48:35 2002 @@ -88,8 +88,9 @@ PHPAPI char *php_stream_gets(php_stream *stream, char *buf, size_t maxlen); PHPAPI int php_stream_puts(php_stream *stream, char *buf); -/* copy up to maxlen bytes from src to dest. If maxlen is 0, copy until eof(src). +/* copy up to maxlen bytes from src to dest. If maxlen is PHP_STREAM_COPY_ALL, copy until eof(src). * Uses mmap if the src is a plain file and at offset 0 */ +#define PHP_STREAM_COPY_ALL -1 PHPAPI size_t php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen); /* read all data from stream and put into a buffer. Caller must free buffer when done, * according to allocopts. Index: php4/main/streams.c diff -u php4/main/streams.c:1.13 php4/main/streams.c:1.14 --- php4/main/streams.c:1.13 Fri Mar 15 21:39:39 2002 +++ php4/main/streams.c Fri Mar 15 21:48:35 2002 @@ -302,6 +302,12 @@ int srcfd; #endif + if (maxlen == 0) + return 0; + + if (maxlen == PHP_STREAM_COPY_ALL) + maxlen = 0; + #if HAVE_MMAP /* try and optimize the case where we are copying from the start of a plain file. * We could probably make this work in more situations, but I don't trust the stdio @@ -315,11 +321,14 @@ if (fstat(srcfd, &sbuf) == 0) { void *srcfile; + + if (maxlen > sbuf.st_size || maxlen == 0) + maxlen = sbuf.st_size; - srcfile = mmap(NULL, sbuf.st_size, PROT_READ, MAP_SHARED, srcfd, 0); + srcfile = mmap(NULL, maxlen, PROT_READ, MAP_SHARED, srcfd, 0); if (srcfile != (void*)MAP_FAILED) { - haveread = php_stream_write(dest, srcfile, sbuf.st_size); - munmap(srcfile, sbuf.st_size); + haveread = php_stream_write(dest, srcfile, maxlen); + munmap(srcfile, maxlen); return haveread; } }

« previous php.cvs (#10205) next »