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.files.info
4 io.backend kernel quotations system alien alien.accessors
5 accessors vocabs.loader combinators alien.c-types
9 TUPLE: mapped-file address handle length disposed ;
11 HOOK: (mapped-file-reader) os ( path length -- address handle )
12 HOOK: (mapped-file-r/w) os ( path length -- address handle )
14 ERROR: bad-mmap-size path size ;
18 : prepare-mapped-file ( path -- path' n )
19 [ normalize-path ] [ file-info size>> ] bi
20 dup 0 <= [ bad-mmap-size ] when ;
24 : <mapped-file-reader> ( path -- mmap )
26 [ (mapped-file-reader) ] keep
29 : <mapped-file> ( path -- mmap )
31 [ (mapped-file-r/w) ] keep
34 HOOK: close-mapped-file io-backend ( mmap -- )
36 M: mapped-file dispose* ( mmap -- ) close-mapped-file ;
38 : with-mapped-file ( path quot -- )
39 [ <mapped-file> ] dip with-disposal ; inline
41 : with-mapped-file-reader ( path quot -- )
42 [ <mapped-file-reader> ] dip with-disposal ; inline
45 { [ os unix? ] [ "io.mmap.unix" require ] }
46 { [ os winnt? ] [ "io.mmap.windows" require ] }