From 93918c7a7cc7ee88ebd8f34723e064fea1479388 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sat, 27 Jan 2007 15:17:23 +0000 Subject: [PATCH] - Add option support for temp/memory stream (adds ftruncate support) --- main/streams/memory.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/main/streams/memory.c b/main/streams/memory.c index fd191d687f..3dc504cf49 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -241,6 +241,37 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb TS } /* }}} */ +static int php_stream_memory_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) /* {{{ */ +{ + php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract; + size_t newsize; + + switch(option) { + case PHP_STREAM_OPTION_TRUNCATE_API: + switch (value) { + case PHP_STREAM_TRUNCATE_SUPPORTED: + return PHP_STREAM_OPTION_RETURN_OK; + + case PHP_STREAM_TRUNCATE_SET_SIZE: + newsize = *(size_t*)ptrparam; + if (newsize <= ms->fsize) { + if (newsize < ms->fpos) { + ms->fpos = newsize; + } else { + ms->data = erealloc(ms->data, newsize); + memset(ms->data+ms->fsize, 0, newsize - ms->fsize); + ms->fsize = newsize; + } + ms->fsize = newsize; + return PHP_STREAM_OPTION_RETURN_OK; + } + } + default: + return PHP_STREAM_OPTION_RETURN_NOTIMPL; + } +} +/* }}} */ + php_stream_ops php_stream_memory_ops = { php_stream_memory_write, php_stream_memory_read, php_stream_memory_close, php_stream_memory_flush, @@ -248,7 +279,7 @@ php_stream_ops php_stream_memory_ops = { php_stream_memory_seek, php_stream_memory_cast, php_stream_memory_stat, - NULL /* set_option */ + php_stream_memory_set_option }; @@ -493,6 +524,9 @@ static int php_stream_temp_set_option(php_stream *stream, int option, int value, } return PHP_STREAM_OPTION_RETURN_OK; default: + if (ts->innerstream) { + return php_stream_set_option(ts->innerstream, option, value, ptrparam); + } return PHP_STREAM_OPTION_RETURN_NOTIMPL; } } -- 2.50.1