2007-09-20 18:09:08 -04:00
|
|
|
! Copyright (C) 2007 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: alien io io.files kernel math system unix io.unix.backend
|
2008-04-24 20:46:52 -04:00
|
|
|
io.mmap io.backend ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: io.unix.mmap
|
|
|
|
|
|
|
|
: open-r/w ( path -- fd ) O_RDWR file-mode open dup io-error ;
|
|
|
|
|
|
|
|
: mmap-open ( length prot flags path -- alien fd )
|
|
|
|
>r f -roll r> open-r/w [ 0 mmap ] keep
|
|
|
|
over MAP_FAILED = [ close (io-error) ] when ;
|
|
|
|
|
2008-04-02 21:33:36 -04:00
|
|
|
M: unix <mapped-file> ( path length -- obj )
|
2008-04-24 20:46:52 -04:00
|
|
|
swap normalize-path >r
|
2007-09-20 18:09:08 -04:00
|
|
|
dup PROT_READ PROT_WRITE bitor MAP_FILE MAP_SHARED bitor
|
2008-04-13 16:06:27 -04:00
|
|
|
r> mmap-open f mapped-file boa ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-04-02 21:33:36 -04:00
|
|
|
M: unix close-mapped-file ( mmap -- )
|
2007-09-20 18:09:08 -04:00
|
|
|
[ mapped-file-address ] keep
|
|
|
|
[ mapped-file-length munmap ] keep
|
|
|
|
mapped-file-handle close
|
|
|
|
io-error ;
|