fix file mode for read only mmap in unix
parent
c44349c74e
commit
3f764fc872
|
@ -4,26 +4,23 @@ USING: alien io io.files kernel math math.bitwise system unix
|
||||||
io.backend.unix io.ports io.mmap destructors locals accessors ;
|
io.backend.unix io.ports io.mmap destructors locals accessors ;
|
||||||
IN: io.mmap.unix
|
IN: io.mmap.unix
|
||||||
|
|
||||||
: open-r/w ( path -- fd ) O_RDWR file-mode open-file ;
|
:: mmap-open ( path length prot flags open-mode -- alien fd )
|
||||||
|
|
||||||
:: mmap-open ( path length prot flags -- alien fd )
|
|
||||||
[
|
[
|
||||||
f length prot flags
|
f length prot flags
|
||||||
path open-r/w [ <fd> |dispose drop ] keep
|
path open-mode file-mode open-file [ <fd> |dispose drop ] keep
|
||||||
[ 0 mmap dup MAP_FAILED = [ (io-error) ] when ] keep
|
[ 0 mmap dup MAP_FAILED = [ (io-error) ] when ] keep
|
||||||
] with-destructors ;
|
] with-destructors ;
|
||||||
|
|
||||||
M: unix (mapped-file-r/w)
|
M: unix (mapped-file-r/w)
|
||||||
{ PROT_READ PROT_WRITE } flags
|
{ PROT_READ PROT_WRITE } flags
|
||||||
{ MAP_FILE MAP_SHARED } flags
|
{ MAP_FILE MAP_SHARED } flags
|
||||||
mmap-open ;
|
O_RDWR mmap-open ;
|
||||||
|
|
||||||
M: unix (mapped-file-reader)
|
M: unix (mapped-file-reader)
|
||||||
{ PROT_READ } flags
|
{ PROT_READ } flags
|
||||||
{ MAP_FILE MAP_SHARED } flags
|
{ MAP_FILE MAP_SHARED } flags
|
||||||
mmap-open ;
|
O_RDONLY mmap-open ;
|
||||||
|
|
||||||
M: unix close-mapped-file ( mmap -- )
|
M: unix close-mapped-file ( mmap -- )
|
||||||
[ [ address>> ] [ length>> ] bi munmap io-error ]
|
[ [ address>> ] [ length>> ] bi munmap io-error ]
|
||||||
[ handle>> close-file ]
|
[ handle>> close-file ] bi ;
|
||||||
bi ;
|
|
||||||
|
|
Loading…
Reference in New Issue