factor/basis/io/mmap/unix/unix.factor

27 lines
847 B
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2007 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2008-09-05 20:29:14 -04:00
USING: alien io io.files kernel math math.bitwise system unix
io.backend.unix io.ports io.mmap destructors locals accessors ;
IN: io.mmap.unix
2007-09-20 18:09:08 -04:00
:: mmap-open ( path length prot flags open-mode -- alien fd )
2008-05-14 00:51:04 -04:00
[
2008-05-14 01:44:27 -04:00
f length prot flags
path open-mode file-mode open-file [ <fd> |dispose drop ] keep
2008-05-14 00:51:04 -04:00
[ 0 mmap dup MAP_FAILED = [ (io-error) ] when ] keep
] with-destructors ;
2007-09-20 18:09:08 -04:00
2009-04-25 20:22:00 -04:00
M: unix (mapped-file-r/w)
2008-05-14 01:44:27 -04:00
{ PROT_READ PROT_WRITE } flags
{ MAP_FILE MAP_SHARED } flags
O_RDWR mmap-open ;
2007-09-20 18:09:08 -04:00
2009-04-25 20:22:00 -04:00
M: unix (mapped-file-reader)
{ PROT_READ } flags
{ MAP_FILE MAP_SHARED } flags
O_RDONLY mmap-open ;
2009-04-25 20:22:00 -04:00
2008-04-02 21:33:36 -04:00
M: unix close-mapped-file ( mmap -- )
2008-05-14 00:51:04 -04:00
[ [ address>> ] [ length>> ] bi munmap io-error ]
[ handle>> close-file ] bi ;