Back to index

php5  5.3.10
Defines | Functions | Variables
php_memory_streams.h File Reference
#include "php_streams.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PHP_STREAM_MAX_MEM   2 * 1024 * 1024
#define TEMP_STREAM_DEFAULT   0
#define TEMP_STREAM_READONLY   1
#define TEMP_STREAM_TAKE_BUFFER   2
#define php_stream_memory_create(mode)   _php_stream_memory_create((mode) STREAMS_CC TSRMLS_CC)
#define php_stream_memory_create_rel(mode)   _php_stream_memory_create((mode) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_memory_open(mode, buf, length)   _php_stream_memory_open((mode), (buf), (length) STREAMS_CC TSRMLS_CC)
#define php_stream_memory_get_buffer(stream, length)   _php_stream_memory_get_buffer((stream), (length) STREAMS_CC TSRMLS_CC)
#define php_stream_temp_new()   php_stream_temp_create(TEMP_STREAM_DEFAULT, PHP_STREAM_MAX_MEM)
#define php_stream_temp_create(mode, max_memory_usage)   _php_stream_temp_create((mode), (max_memory_usage) STREAMS_CC TSRMLS_CC)
#define php_stream_temp_create_rel(mode, max_memory_usage)   _php_stream_temp_create((mode), (max_memory_usage) STREAMS_REL_CC TSRMLS_CC)
#define php_stream_temp_open(mode, max_memory_usage, buf, length)   _php_stream_temp_open((mode), (max_memory_usage), (buf), (length) STREAMS_CC TSRMLS_CC)
#define PHP_STREAM_IS_MEMORY   &php_stream_memory_ops
#define PHP_STREAM_IS_TEMP   &php_stream_temp_ops

Functions

PHPAPI php_stream * _php_stream_memory_create (int mode STREAMS_DC TSRMLS_DC)
PHPAPI php_stream * _php_stream_memory_open (int mode, char *buf, size_t length STREAMS_DC TSRMLS_DC)
PHPAPI char * _php_stream_memory_get_buffer (php_stream *stream, size_t *length STREAMS_DC TSRMLS_DC)
PHPAPI php_stream * _php_stream_temp_create (int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC)
PHPAPI php_stream * _php_stream_temp_open (int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC)

Variables

PHPAPI php_stream_ops php_stream_memory_ops
PHPAPI php_stream_ops php_stream_temp_ops
PHPAPI php_stream_ops php_stream_rfc2397_ops
PHPAPI php_stream_wrapper php_stream_rfc2397_wrapper

Define Documentation

Definition at line 56 of file php_memory_streams.h.

Definition at line 57 of file php_memory_streams.h.

#define PHP_STREAM_MAX_MEM   2 * 1024 * 1024

Definition at line 26 of file php_memory_streams.h.

Definition at line 32 of file php_memory_streams.h.

Definition at line 33 of file php_memory_streams.h.

Definition at line 35 of file php_memory_streams.h.

#define php_stream_memory_open (   mode,
  buf,
  length 
)    _php_stream_memory_open((mode), (buf), (length) STREAMS_CC TSRMLS_CC)

Definition at line 34 of file php_memory_streams.h.

#define php_stream_temp_create (   mode,
  max_memory_usage 
)    _php_stream_temp_create((mode), (max_memory_usage) STREAMS_CC TSRMLS_CC)

Definition at line 38 of file php_memory_streams.h.

#define php_stream_temp_create_rel (   mode,
  max_memory_usage 
)    _php_stream_temp_create((mode), (max_memory_usage) STREAMS_REL_CC TSRMLS_CC)

Definition at line 39 of file php_memory_streams.h.

Definition at line 37 of file php_memory_streams.h.

#define php_stream_temp_open (   mode,
  max_memory_usage,
  buf,
  length 
)    _php_stream_temp_open((mode), (max_memory_usage), (buf), (length) STREAMS_CC TSRMLS_CC)

Definition at line 40 of file php_memory_streams.h.

#define TEMP_STREAM_DEFAULT   0

Definition at line 28 of file php_memory_streams.h.

#define TEMP_STREAM_READONLY   1

Definition at line 29 of file php_memory_streams.h.

#define TEMP_STREAM_TAKE_BUFFER   2

Definition at line 30 of file php_memory_streams.h.


Function Documentation

PHPAPI php_stream* _php_stream_memory_create ( int mode STREAMS_DC  TSRMLS_DC)

Definition at line 293 of file memory.c.

{
       php_stream_memory_data *self;
       php_stream *stream;

       self = emalloc(sizeof(*self));
       self->data = NULL;
       self->fpos = 0;
       self->fsize = 0;
       self->smax = ~0u;
       self->mode = mode;
       self->owner_ptr = NULL;
       
       stream = php_stream_alloc_rel(&php_stream_memory_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b");
       stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
       return stream;
}
PHPAPI char* _php_stream_memory_get_buffer ( php_stream *  stream,
size_t *length STREAMS_DC  TSRMLS_DC 
)

Definition at line 339 of file memory.c.

{
       php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;

       assert(ms != NULL);
       assert(length != 0);

       *length = ms->fsize;
       return ms->data;
}
PHPAPI php_stream* _php_stream_memory_open ( int  mode,
char *  buf,
size_t length STREAMS_DC  TSRMLS_DC 
)

Definition at line 314 of file memory.c.

{
       php_stream *stream;
       php_stream_memory_data *ms;

       if ((stream = php_stream_memory_create_rel(mode)) != NULL) {
              ms = (php_stream_memory_data*)stream->abstract;
              
              if (mode == TEMP_STREAM_READONLY || mode == TEMP_STREAM_TAKE_BUFFER) {
                     /* use the buffer directly */
                     ms->data = buf;
                     ms->fsize = length;
              } else {
                     if (length) {
                            assert(buf != NULL);
                            php_stream_write(stream, buf, length);
                     }
              }
       }
       return stream;
}
PHPAPI php_stream* _php_stream_temp_create ( int  mode,
size_t max_memory_usage STREAMS_DC  TSRMLS_DC 
)

Definition at line 554 of file memory.c.

{
       php_stream_temp_data *self;
       php_stream *stream;

       self = ecalloc(1, sizeof(*self));
       self->smax = max_memory_usage;
       self->mode = mode;
       self->meta = NULL;
       stream = php_stream_alloc_rel(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b");
       stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
       self->innerstream = php_stream_memory_create_rel(mode);
       php_stream_auto_cleanup(self->innerstream); /* do not warn if innerstream is GC'ed before stream */
       ((php_stream_memory_data*)self->innerstream->abstract)->owner_ptr = &self->innerstream;

       return stream;
}
PHPAPI php_stream* _php_stream_temp_open ( int  mode,
size_t  max_memory_usage,
char *  buf,
size_t length STREAMS_DC  TSRMLS_DC 
)

Definition at line 575 of file memory.c.

{
       php_stream *stream;
       php_stream_temp_data *ts;
       off_t newoffs;

       if ((stream = php_stream_temp_create_rel(mode, max_memory_usage)) != NULL) {
              if (length) {
                     assert(buf != NULL);
                     php_stream_temp_write(stream, buf, length TSRMLS_CC);
                     php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs TSRMLS_CC);
              }
              ts = (php_stream_temp_data*)stream->abstract;
              assert(ts != NULL);
              ts->mode = mode;
       }
       return stream;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 281 of file memory.c.

Definition at line 595 of file memory.c.

PHPAPI php_stream_wrapper php_stream_rfc2397_wrapper

Definition at line 749 of file memory.c.

Definition at line 541 of file memory.c.