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

25 lines
752 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
: open-r/w ( path -- fd ) O_RDWR file-mode open-file ;
2007-09-20 18:09:08 -04:00
:: mmap-open ( path length prot flags -- alien fd )
2008-05-14 00:51:04 -04:00
[
2008-05-14 01:44:27 -04:00
f length prot flags
path open-r/w [ <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
2008-05-14 01:44:27 -04:00
M: unix (mapped-file)
{ PROT_READ PROT_WRITE } flags
{ MAP_FILE MAP_SHARED } flags
mmap-open ;
2007-09-20 18:09:08 -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 ;