factor/basis/io/mmap/mmap.factor

27 lines
837 B
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 destructors io.files io.files.info
io.backend kernel quotations system alien alien.accessors
accessors system vocabs.loader combinators alien.c-types ;
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
HOOK: (mapped-file) os ( path length -- address handle )
: <mapped-file> ( path -- mmap )
[ normalize-path ] [ file-info size>> ] bi [ (mapped-file) ] keep
2008-05-14 01:44:27 -04:00
f mapped-file boa ;
HOOK: close-mapped-file io-backend ( mmap -- )
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 quot -- )
[ <mapped-file> ] dip with-disposal ; inline
2008-07-02 22:52:28 -04:00
{
{ [ os unix? ] [ "io.mmap.unix" require ] }
{ [ os winnt? ] [ "io.mmap.windows" require ] }
2008-07-02 22:52:28 -04:00
} cond