]> granicus.if.org Git - php/commitdiff
Handle maxlen when stream can't be mmaped
authorSara Golemon <pollita@php.net>
Wed, 8 Sep 2004 18:42:15 +0000 (18:42 +0000)
committerSara Golemon <pollita@php.net>
Wed, 8 Sep 2004 18:42:15 +0000 (18:42 +0000)
main/streams/streams.c

index a7c65dde57ce336f4c905c918c1b8f430d925994..fc5a0b82ee98541879d294436bd0cc8a98593801 100755 (executable)
@@ -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