summaryrefslogtreecommitdiff
path: root/main/streams.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2002-03-16 02:48:35 +0000
committerWez Furlong <wez@php.net>2002-03-16 02:48:35 +0000
commit636829345ea4ce06766b55b43adfd2b47628fada (patch)
treeb492c19733f5331e0b56f2c0fb6793af26716514 /main/streams.c
parent94b6c6e87fe11ba9e4e0b28dc9eb42f775a32820 (diff)
downloadphp-git-636829345ea4ce06766b55b43adfd2b47628fada.tar.gz
Allow php_stream_copy_to_stream to do nothing when used with code
that calculates a max length of zero. (Thanks again Marcus).
Diffstat (limited to 'main/streams.c')
-rwxr-xr-xmain/streams.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/main/streams.c b/main/streams.c
index 5157fe9ce7..ccafe65b8c 100755
--- a/main/streams.c
+++ b/main/streams.c
@@ -302,6 +302,12 @@ PHPAPI size_t php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_
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 @@ PHPAPI size_t php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_
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;
}
}