cvs: php-src /main/streams memory.c
| From: | Marcus Boerger | Date: | Sat, 27 Jan 2007 15:17:23 +0000 |
| Subject: | cvs: php-src /main/streams memory.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-42889@lists.php.net to get a copy of this message | ||
helly Sat Jan 27 15:17:23 2007 UTC
Modified files:
/php-src/main/streams memory.c
Log:
- Add option support for temp/memory stream (adds ftruncate support)
http://cvs.php.net/viewvc.cgi/php-src/main/streams/memory.c?r1=1.31&r2=1.32&diff_format=u
Index: php-src/main/streams/memory.c
diff -u php-src/main/streams/memory.c:1.31 php-src/main/streams/memory.c:1.32
--- php-src/main/streams/memory.c:1.31 Sun Jan 14 19:13:34 2007
+++ php-src/main/streams/memory.c Sat Jan 27 15:17:23 2007
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: memory.c,v 1.31 2007/01/14 19:13:34 helly Exp $ */
+/* $Id: memory.c,v 1.32 2007/01/27 15:17:23 helly Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -241,6 +241,37 @@
}
/* }}} */
+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_memory_seek,
php_stream_memory_cast,
php_stream_memory_stat,
- NULL /* set_option */
+ php_stream_memory_set_option
};
@@ -493,6 +524,9 @@
}
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;
}
}