1 ! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: continuations destructors io.backend kernel quotations
4 sequences system alien alien.accessors accessors
5 sequences.private system vocabs.loader combinators ;
8 TUPLE: mapped-file address handle length disposed ;
10 M: mapped-file length dup check-disposed length>> ;
12 M: mapped-file nth-unsafe
13 dup check-disposed address>> swap alien-unsigned-1 ;
15 M: mapped-file set-nth-unsafe
16 dup check-disposed address>> swap set-alien-unsigned-1 ;
18 INSTANCE: mapped-file sequence
20 HOOK: (mapped-file) io-backend ( path length -- address handle )
22 : <mapped-file> ( path length -- mmap )
23 [ >r normalize-path r> (mapped-file) ] keep
26 HOOK: close-mapped-file io-backend ( mmap -- )
28 M: mapped-file dispose* ( mmap -- ) close-mapped-file ;
30 : with-mapped-file ( path length quot -- )
31 >r <mapped-file> r> with-disposal ; inline
34 { [ os unix? ] [ "io.unix.mmap" require ] }
35 { [ os winnt? ] [ "io.windows.mmap" require ] }