Back to index

php5  5.3.10
Functions
mmap.c File Reference
#include "php.h"
#include "php_streams_int.h"

Go to the source code of this file.

Functions

PHPAPI char * _php_stream_mmap_range (php_stream *stream, size_t offset, size_t length, php_stream_mmap_operation_t mode, size_t *mapped_len TSRMLS_DC)
PHPAPI int _php_stream_mmap_unmap (php_stream *stream TSRMLS_DC)
PHPAPI int _php_stream_mmap_unmap_ex (php_stream *stream, off_t readden TSRMLS_DC)

Function Documentation

PHPAPI char* _php_stream_mmap_range ( php_stream *  stream,
size_t  offset,
size_t  length,
php_stream_mmap_operation_t  mode,
size_t *mapped_len  TSRMLS_DC 
)

Definition at line 25 of file mmap.c.

{
       php_stream_mmap_range range;
       
       range.offset = offset;
       range.length = length;
       range.mode = mode;
       range.mapped = NULL;

       /* For now, we impose an arbitrary limit to avoid
        * runaway swapping when large files are passed thru. */
       if (length > 4 * 1024 * 1024) {
              return NULL;
       }
       
       if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) {
              if (mapped_len) {
                     *mapped_len = range.length;
              }
              return range.mapped;
       }
       return NULL;
}
PHPAPI int _php_stream_mmap_unmap ( php_stream *stream  TSRMLS_DC)
PHPAPI int _php_stream_mmap_unmap_ex ( php_stream *  stream,
off_t readden  TSRMLS_DC 
)

Definition at line 54 of file mmap.c.

{
       int ret = 1;

       if (php_stream_seek(stream, readden, SEEK_CUR) != 0) {
              ret = 0;
       }
       if (php_stream_mmap_unmap(stream) == 0) {
              ret = 0;
       }

       return ret;
}