]> granicus.if.org Git - php/commitdiff
- Add option support for temp/memory stream (adds ftruncate support)
authorMarcus Boerger <helly@php.net>
Sat, 27 Jan 2007 15:17:23 +0000 (15:17 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 27 Jan 2007 15:17:23 +0000 (15:17 +0000)
main/streams/memory.c

index fd191d687f05a30efc3a468b00670a28cc738c9e..3dc504cf49f122655862c4ddfeff1fdcb415473c 100644 (file)
@@ -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;
        }
 }