]> gitweb.factorcode.org Git - factor.git/blob - basis/io/windows/windows.factor
Fix permission bits
[factor.git] / basis / io / windows / windows.factor
1 ! Copyright (C) 2004, 2008 Mackenzie Straight, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types arrays destructors io io.backend
4 io.buffers io.files io.ports io.sockets io.binary
5 io.sockets io.timeouts windows.errors strings
6 kernel math namespaces sequences windows windows.kernel32
7 windows.shell32 windows.types windows.winsock splitting
8 continuations math.bitwise system accessors ;
9 IN: io.windows
10
11 : set-inherit ( handle ? -- )
12     >r HANDLE_FLAG_INHERIT r> >BOOLEAN SetHandleInformation win32-error=0/f ;
13
14 TUPLE: win32-handle handle disposed ;
15
16 : new-win32-handle ( handle class -- win32-handle )
17     new swap [ >>handle ] [ f set-inherit ] bi ;
18
19 : <win32-handle> ( handle -- win32-handle )
20     win32-handle new-win32-handle ;
21
22 M: win32-handle dispose* ( handle -- )
23     handle>> CloseHandle drop ;
24
25 TUPLE: win32-file < win32-handle ptr ;
26
27 : <win32-file> ( handle -- win32-file )
28     win32-file new-win32-handle ;
29
30 M: win32-file dispose
31     dup disposed>> [ drop ] [
32         [ cancel-operation ] [ call-next-method ] bi
33     ] if ;
34
35 HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
36 HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )
37 HOOK: add-completion io-backend ( port -- )
38
39 : opened-file ( handle -- win32-file )
40     dup invalid-handle?
41     <win32-file> |dispose
42     dup add-completion ;
43
44 : share-mode ( -- fixnum )
45     {
46         FILE_SHARE_READ
47         FILE_SHARE_WRITE
48         FILE_SHARE_DELETE
49     } flags ; foldable
50
51 : default-security-attributes ( -- obj )
52     "SECURITY_ATTRIBUTES" <c-object>
53     "SECURITY_ATTRIBUTES" heap-size
54     over set-SECURITY_ATTRIBUTES-nLength ;