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

27 lines
845 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.
USING: accessors destructors io.backend.unix io.mmap literals
2010-01-22 16:01:38 -05:00
io.mmap.private kernel locals math.bitwise system unix unix.ffi ;
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)
flags{ PROT_READ PROT_WRITE }
flags{ MAP_FILE MAP_SHARED }
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)
flags{ PROT_READ }
flags{ MAP_FILE MAP_SHARED }
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 ;