]> gitweb.factorcode.org Git - factor.git/blob - basis/io/mmap/mmap.factor
01e7054ef1f3c670723aab54406a7079959c078d
[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.backend kernel quotations
4 sequences system alien alien.accessors accessors
5 sequences.private system vocabs.loader combinators ;
6 IN: io.mmap
7
8 TUPLE: mapped-file address handle length disposed ;
9
10 M: mapped-file length dup check-disposed length>> ;
11
12 M: mapped-file nth-unsafe
13     dup check-disposed address>> swap alien-unsigned-1 ;
14
15 M: mapped-file set-nth-unsafe
16     dup check-disposed address>> swap set-alien-unsigned-1 ;
17
18 INSTANCE: mapped-file sequence
19
20 HOOK: (mapped-file) io-backend ( path length -- address handle )
21
22 : <mapped-file> ( path length -- mmap )
23     [ >r normalize-path r> (mapped-file) ] keep
24     f mapped-file boa ;
25
26 HOOK: close-mapped-file io-backend ( mmap -- )
27
28 M: mapped-file dispose* ( mmap -- ) close-mapped-file ;
29
30 : with-mapped-file ( path length quot -- )
31     >r <mapped-file> r> with-disposal ; inline
32
33 {
34     { [ os unix? ] [ "io.unix.mmap" require ] }
35     { [ os winnt? ] [ "io.windows.mmap" require ] }
36 } cond