From: Sara Golemon Date: Wed, 8 Sep 2004 18:45:05 +0000 (+0000) Subject: MFH (r.163) Handle maxlen when stream can't be mmaped X-Git-Tag: php-5.0.2RC1~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c1c1b21686cde1a408a0fe44a937c8518ac9f4eb;p=php MFH (r.163) Handle maxlen when stream can't be mmaped --- diff --git a/main/streams/streams.c b/main/streams/streams.c index 6390600e4a..a0757d3811 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1211,6 +1211,17 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen } } + if (maxlen > 0) { + ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent); + while ((len < maxlen) & !php_stream_eof(src)) { + ret = php_stream_read(src, ptr, maxlen - len); + len += ret; + ptr += ret; + } + *ptr = '\0'; + return len; + } + /* avoid many reallocs by allocating a good sized chunk to begin with, if * we can. Note that the stream may be filtered, in which case the stat * result may be inaccurate, as the filter may inflate or deflate the