/src/php-src/main/streams/mmap.c
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright © The PHP Group and Contributors. | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to the Modified BSD License that is | |
6 | | | bundled with this package in the file LICENSE, and is available | |
7 | | | through the World Wide Web at <https://www.php.net/license/>. | |
8 | | | | |
9 | | | SPDX-License-Identifier: BSD-3-Clause | |
10 | | +----------------------------------------------------------------------+ |
11 | | | Author: Wez Furlong <wez@thebrainroom.com> | |
12 | | +----------------------------------------------------------------------+ |
13 | | */ |
14 | | |
15 | | /* Memory Mapping interface for streams */ |
16 | | #include "php.h" |
17 | | #include "php_streams_int.h" |
18 | | |
19 | | 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) |
20 | 0 | { |
21 | 0 | php_stream_mmap_range range; |
22 | |
|
23 | 0 | range.offset = offset; |
24 | 0 | range.length = length; |
25 | 0 | range.mode = mode; |
26 | 0 | range.mapped = NULL; |
27 | |
|
28 | 0 | if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) { |
29 | 0 | if (mapped_len) { |
30 | 0 | *mapped_len = range.length; |
31 | 0 | } |
32 | 0 | return range.mapped; |
33 | 0 | } |
34 | 0 | return NULL; |
35 | 0 | } |
36 | | |
37 | | PHPAPI int _php_stream_mmap_unmap(php_stream *stream) |
38 | 0 | { |
39 | 0 | return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK; |
40 | 0 | } |
41 | | |
42 | | PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden) |
43 | 0 | { |
44 | 0 | int ret = 1; |
45 | |
|
46 | 0 | if (php_stream_seek(stream, readden, SEEK_CUR) != 0) { |
47 | 0 | ret = 0; |
48 | 0 | } |
49 | 0 | if (php_stream_mmap_unmap(stream) == 0) { |
50 | 0 | ret = 0; |
51 | 0 | } |
52 | |
|
53 | 0 | return ret; |
54 | 0 | } |