2008-02-01 00:00:08 -05:00
|
|
|
! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-05-15 00:23:12 -04:00
|
|
|
USING: continuations destructors io.backend kernel quotations
|
|
|
|
sequences system alien alien.accessors accessors
|
|
|
|
sequences.private ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: io.mmap
|
|
|
|
|
2008-05-15 00:23:12 -04:00
|
|
|
TUPLE: mapped-file address handle length disposed ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-05-15 00:23:12 -04:00
|
|
|
M: mapped-file length dup check-disposed length>> ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: mapped-file nth-unsafe
|
2008-05-15 00:23:12 -04:00
|
|
|
dup check-disposed address>> swap alien-unsigned-1 ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: mapped-file set-nth-unsafe
|
2008-05-15 00:23:12 -04:00
|
|
|
dup check-disposed address>> swap set-alien-unsigned-1 ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
INSTANCE: mapped-file sequence
|
|
|
|
|
2008-05-14 01:44:27 -04:00
|
|
|
HOOK: (mapped-file) io-backend ( path length -- address handle )
|
2008-04-25 02:10:40 -04:00
|
|
|
|
|
|
|
: <mapped-file> ( path length -- mmap )
|
2008-05-14 01:44:27 -04:00
|
|
|
[ >r normalize-path r> (mapped-file) ] keep
|
|
|
|
f mapped-file boa ;
|
2007-11-17 01:49:06 -05:00
|
|
|
|
2008-01-31 01:52:06 -05:00
|
|
|
HOOK: close-mapped-file io-backend ( mmap -- )
|
2007-11-17 01:49:06 -05:00
|
|
|
|
2008-05-15 00:23:12 -04:00
|
|
|
M: mapped-file dispose* ( mmap -- ) close-mapped-file ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: with-mapped-file ( path length quot -- )
|
2008-01-31 01:52:06 -05:00
|
|
|
>r <mapped-file> r> with-disposal ; inline
|