]> gitweb.factorcode.org Git - factor.git/blob - basis/io/mmap/mmap.factor
Merge branch 'master' into experimental (untested!)
[factor.git] / basis / io / mmap / mmap.factor
1 ! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: continuations destructors io.files io.backend kernel
4 quotations system alien alien.accessors accessors system
5 vocabs.loader combinators alien.c-types ;
6 IN: io.mmap
7
8 TUPLE: mapped-file address handle length disposed ;
9
10 HOOK: (mapped-file) io-backend ( path length -- address handle )
11
12 : <mapped-file> ( path -- mmap )
13     [ normalize-path ] [ file-info size>> ] bi [ (mapped-file) ] keep
14     f mapped-file boa ;
15
16 HOOK: close-mapped-file io-backend ( mmap -- )
17
18 M: mapped-file dispose* ( mmap -- ) close-mapped-file ;
19
20 : with-mapped-file ( path quot -- )
21     [ <mapped-file> ] dip with-disposal ; inline
22
23 {
24     { [ os unix? ] [ "io.unix.mmap" require ] }
25     { [ os winnt? ] [ "io.windows.mmap" require ] }
26 } cond