2003-02-27 17:43:38 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2019-01-30 09:03:12 +00:00
|
|
|
| Copyright (c) The PHP Group |
|
2003-02-27 17:43:38 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2003-02-27 17:43:38 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2021-05-06 10:16:35 +00:00
|
|
|
| https://www.php.net/license/3_01.txt |
|
2003-02-27 17:43:38 +00:00
|
|
|
| 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"
|
|
|
|
|
2015-03-04 03:28:14 +00:00
|
|
|
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-02-27 17:43:38 +00:00
|
|
|
{
|
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;
|
2003-02-27 17:43:38 +00:00
|
|
|
|
|
|
|
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)
|
2003-02-27 17:43:38 +00:00
|
|
|
{
|
2018-08-19 04:32:00 +00:00
|
|
|
return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK;
|
2003-02-27 17:43:38 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden)
|
2009-05-17 14:58:10 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|