php-src/main/streams/mmap.c

57 lines
1.9 KiB
C
Raw Normal View History

/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <wez@thebrainroom.com> |
+----------------------------------------------------------------------+
*/
/* Memory Mapping interface for streams */
#include "php.h"
#include "php_streams_int.h"
PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_access_t mode, size_t *mapped_len)
{
2003-07-14 19:38:13 +00:00
php_stream_mmap_range range;
2015-01-03 09:22:58 +00:00
2003-07-14 19:38:13 +00:00
range.offset = offset;
range.length = length;
range.mode = mode;
range.mapped = 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;
}
2014-12-13 22:06:14 +00:00
PHPAPI int _php_stream_mmap_unmap(php_stream *stream)
{
return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK;
}
2014-12-13 22:06:14 +00:00
PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden)
{
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;
}