~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to main/streams/mmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  +----------------------------------------------------------------------+
 
3
  | PHP Version 5                                                        |
 
4
  +----------------------------------------------------------------------+
 
5
  | Copyright (c) 1997-2004 The PHP Group                                |
 
6
  +----------------------------------------------------------------------+
 
7
  | This source file is subject to version 3.0 of the PHP license,       |
 
8
  | that is bundled with this package in the file LICENSE, and is        |
 
9
  | available through the world-wide-web at the following url:           |
 
10
  | http://www.php.net/license/3_0.txt.                                  |
 
11
  | If you did not receive a copy of the PHP license and are unable to   |
 
12
  | obtain it through the world-wide-web, please send a note to          |
 
13
  | license@php.net so we can mail you a copy immediately.               |
 
14
  +----------------------------------------------------------------------+
 
15
  | Author: Wez Furlong <wez@thebrainroom.com>                           |
 
16
  +----------------------------------------------------------------------+
 
17
*/
 
18
 
 
19
/* $Id: mmap.c,v 1.5.2.2 2005/02/24 11:35:10 sniper Exp $ */
 
20
 
 
21
/* Memory Mapping interface for streams */
 
22
#include "php.h"
 
23
#include "php_streams_int.h"
 
24
 
 
25
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)
 
26
{
 
27
        php_stream_mmap_range range;
 
28
        
 
29
        range.offset = offset;
 
30
        range.length = length;
 
31
        range.mode = mode;
 
32
        range.mapped = NULL;
 
33
 
 
34
        /* For now, we impose an arbitrary 2MB limit to avoid
 
35
         * runaway swapping when large files are passed thru. */
 
36
        if (length > 2 * 1024 * 1024) {
 
37
                return NULL;
 
38
        }
 
39
        
 
40
        if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) {
 
41
                if (mapped_len) {
 
42
                        *mapped_len = range.length;
 
43
                }
 
44
                return range.mapped;
 
45
        }
 
46
        return NULL;
 
47
}
 
48
 
 
49
PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC)
 
50
{
 
51
        return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0;
 
52
}
 
53
 
 
54
/*
 
55
 * Local variables:
 
56
 * tab-width: 4
 
57
 * c-basic-offset: 4
 
58
 * End:
 
59
 * vim600: noet sw=4 ts=4 fdm=marker
 
60
 * vim<600: noet sw=4 ts=4
 
61
 */