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

28 lines
838 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.
2014-04-04 11:03:46 -04:00
USING: accessors destructors io.backend.unix io.mmap
io.mmap.private kernel libc literals locals 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
[ 0 mmap dup MAP_FAILED = [ throw-errno ] when ] keep
2008-05-14 00:51:04 -04:00
] 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 ;