]> gitweb.factorcode.org Git - factor.git/blob - basis/io/backend/windows/windows.factor
Use flags{ instead of flags all over the place
[factor.git] / basis / io / backend / 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.binary io.timeouts system
5 strings kernel math namespaces sequences windows.errors
6 windows.kernel32 windows.shell32 windows.types splitting
7 continuations math.bitwise accessors init sets assocs
8 classes.struct classes literals ;
9 IN: io.backend.windows
10
11 TUPLE: win32-handle < disposable handle ;
12
13 : set-inherit ( handle ? -- )
14     [ handle>> HANDLE_FLAG_INHERIT ] dip
15     >BOOLEAN SetHandleInformation win32-error=0/f ;
16
17 : new-win32-handle ( handle class -- win32-handle )
18     new-disposable swap >>handle
19     dup f set-inherit ;
20
21 : <win32-handle> ( handle -- win32-handle )
22     win32-handle new-win32-handle ;
23
24 M: win32-handle dispose* ( handle -- )
25     handle>> CloseHandle win32-error=0/f ;
26
27 TUPLE: win32-file < win32-handle ptr ;
28
29 : <win32-file> ( handle -- win32-file )
30     win32-file new-win32-handle ;
31
32 M: win32-file dispose
33     dup disposed>> [ drop ] [
34         [ cancel-operation ] [ call-next-method ] bi
35     ] if ;
36
37 HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
38 HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )
39 HOOK: add-completion io-backend ( port -- )
40
41 : opened-file ( handle -- win32-file )
42     dup invalid-handle?
43     <win32-file> |dispose
44     dup add-completion ;
45
46 CONSTANT: share-mode
47     flags{
48         FILE_SHARE_READ
49         FILE_SHARE_WRITE
50         FILE_SHARE_DELETE
51     }
52
53 : default-security-attributes ( -- obj )
54     SECURITY_ATTRIBUTES <struct>
55     SECURITY_ATTRIBUTES heap-size >>nLength ;