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.binary io.timeouts system
5 strings kernel math namespaces sequences windows.errors
6 windows.kernel32 windows.shell32 windows.types windows.winsock
7 splitting continuations math.bitwise accessors init sets assocs ;
10 : win32-handles ( -- assoc )
11 \ win32-handles [ H{ } clone ] initialize-alien ;
13 TUPLE: win32-handle < identity-tuple handle disposed ;
15 M: win32-handle hashcode* handle>> hashcode* ;
17 : set-inherit ( handle ? -- )
18 [ handle>> HANDLE_FLAG_INHERIT ] dip
19 >BOOLEAN SetHandleInformation win32-error=0/f ;
21 : new-win32-handle ( handle class -- win32-handle )
24 dup win32-handles conjoin ;
26 : <win32-handle> ( handle -- win32-handle )
27 win32-handle new-win32-handle ;
29 ERROR: disposing-twice ;
31 : unregister-handle ( handle -- )
32 win32-handles delete-at*
33 [ t >>disposed drop ] [ disposing-twice ] if ;
35 M: win32-handle dispose* ( handle -- )
36 [ unregister-handle ] [ handle>> CloseHandle win32-error=0/f ] bi ;
38 TUPLE: win32-file < win32-handle ptr ;
40 : <win32-file> ( handle -- win32-file )
41 win32-file new-win32-handle ;
44 dup disposed>> [ drop ] [
45 [ cancel-operation ] [ call-next-method ] bi
48 HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
49 HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )
50 HOOK: add-completion io-backend ( port -- )
52 : opened-file ( handle -- win32-file )
57 : share-mode ( -- fixnum )
64 : default-security-attributes ( -- obj )
65 "SECURITY_ATTRIBUTES" <c-object>
66 "SECURITY_ATTRIBUTES" heap-size
67 over set-SECURITY_ATTRIBUTES-nLength ;