factor/extra/io/mmap/mmap.factor

38 lines
1.1 KiB
Factor
Raw Normal View History

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.
USING: continuations io.backend kernel quotations sequences
2008-02-01 00:00:08 -05:00
system alien alien.accessors sequences.private ;
2007-09-20 18:09:08 -04:00
IN: io.mmap
TUPLE: mapped-file length address handle closed? ;
2007-09-20 18:09:08 -04:00
: check-closed ( mapped-file -- mapped-file )
dup mapped-file-closed? [
"Mapped file is closed" throw
] when ; inline
M: mapped-file length check-closed mapped-file-length ;
2007-09-20 18:09:08 -04:00
M: mapped-file nth-unsafe
check-closed mapped-file-address swap alien-unsigned-1 ;
2007-09-20 18:09:08 -04:00
M: mapped-file set-nth-unsafe
check-closed mapped-file-address swap set-alien-unsigned-1 ;
2007-09-20 18:09:08 -04:00
INSTANCE: mapped-file sequence
HOOK: (mapped-file) io-backend ( path length -- mmap )
: <mapped-file> ( path length -- mmap )
>r normalize-path r> (mapped-file) ;
HOOK: close-mapped-file io-backend ( mmap -- )
M: mapped-file dispose ( mmap -- )
check-closed
t over set-mapped-file-closed?
close-mapped-file ;
2007-09-20 18:09:08 -04:00
: with-mapped-file ( path length quot -- )
>r <mapped-file> r> with-disposal ; inline