Back to index

php5  5.3.10
mmap.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Wez Furlong <wez@thebrainroom.com>                           |
00016   +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: mmap.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 /* Memory Mapping interface for streams */
00022 #include "php.h"
00023 #include "php_streams_int.h"
00024 
00025 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)
00026 {
00027        php_stream_mmap_range range;
00028        
00029        range.offset = offset;
00030        range.length = length;
00031        range.mode = mode;
00032        range.mapped = NULL;
00033 
00034        /* For now, we impose an arbitrary limit to avoid
00035         * runaway swapping when large files are passed thru. */
00036        if (length > 4 * 1024 * 1024) {
00037               return NULL;
00038        }
00039        
00040        if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) {
00041               if (mapped_len) {
00042                      *mapped_len = range.length;
00043               }
00044               return range.mapped;
00045        }
00046        return NULL;
00047 }
00048 
00049 PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC)
00050 {
00051        return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0;
00052 }
00053 
00054 PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC)
00055 {
00056        int ret = 1;
00057 
00058        if (php_stream_seek(stream, readden, SEEK_CUR) != 0) {
00059               ret = 0;
00060        }
00061        if (php_stream_mmap_unmap(stream) == 0) {
00062               ret = 0;
00063        }
00064 
00065        return ret;
00066 }
00067 
00068 /*
00069  * Local variables:
00070  * tab-width: 4
00071  * c-basic-offset: 4
00072  * End:
00073  * vim600: noet sw=4 ts=4 fdm=marker
00074  * vim<600: noet sw=4 ts=4
00075  */