summaryrefslogtreecommitdiff
path: root/main/memory_streams.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2002-04-02 16:46:33 +0000
committerWez Furlong <wez@php.net>2002-04-02 16:46:33 +0000
commita0f165a5cb615d49834d5e68ab7ab543e45d493e (patch)
tree9c5b85ae3ba3620161b6341d3829432cde3f6299 /main/memory_streams.c
parentabc5a2cacb6e16145934e0881954566b20f46d99 (diff)
downloadphp-git-a0f165a5cb615d49834d5e68ab7ab543e45d493e.tar.gz
main/streams.c
Diffstat (limited to 'main/memory_streams.c')
-rw-r--r--main/memory_streams.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/main/memory_streams.c b/main/memory_streams.c
index fdd074903f..eae29e4acf 100644
--- a/main/memory_streams.c
+++ b/main/memory_streams.c
@@ -120,7 +120,7 @@ static int php_stream_memory_close(php_stream *stream, int close_handle TSRMLS_D
ms = stream->abstract;
assert(ms != NULL);
- if (ms->data) {
+ if (ms->data && close_handle && ms->mode != TEMP_STREAM_READONLY) {
efree(ms->data);
}
efree(ms);
@@ -262,13 +262,19 @@ PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length ST
{ php_stream *stream;
php_stream_memory_data *ms;
- if ((stream = php_stream_memory_create_rel(TEMP_STREAM_DEFAULT)) != NULL) {
- if (length) {
- assert(buf != NULL);
- php_stream_write(stream, buf, length);
- }
+ if ((stream = php_stream_memory_create_rel(mode)) != NULL) {
ms = stream->abstract;
- ms->mode = mode;
+
+ if (mode == TEMP_STREAM_READONLY) {
+ /* use the buffer directly */
+ ms->data = buf;
+ ms->fsize = length;
+ } else {
+ if (length) {
+ assert(buf != NULL);
+ php_stream_write(stream, buf, length);
+ }
+ }
}
return stream;
}