factor/extra/io/windows/windows.factor

51 lines
1.5 KiB
Factor
Raw Normal View History

! Copyright (C) 2004, 2008 Mackenzie Straight, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2007-11-11 16:09:24 -05:00
USING: alien alien.c-types arrays destructors io io.backend
2008-05-13 19:24:46 -04:00
io.buffers io.files io.ports io.sockets io.binary
io.sockets windows.errors strings
2008-02-29 18:44:53 -05:00
kernel math namespaces sequences windows windows.kernel32
windows.shell32 windows.types windows.winsock splitting
2008-04-11 22:36:37 -04:00
continuations math.bitfields system accessors ;
2007-09-20 18:09:08 -04:00
IN: io.windows
2008-05-15 02:44:23 -04:00
TUPLE: win32-handle handle disposed ;
2007-09-20 18:09:08 -04:00
2008-05-15 02:44:23 -04:00
: new-win32-handle ( handle class -- win32-handle )
new swap >>handle ;
2007-09-20 18:09:08 -04:00
2008-05-15 02:44:23 -04:00
: <win32-handle> ( handle -- win32-handle )
win32-handle new-win32-handle ;
M: win32-handle dispose* ( handle -- )
handle>> CloseHandle drop ;
TUPLE: win32-file < win32-handle ptr ;
2008-05-15 02:44:23 -04:00
: <win32-file> ( handle -- win32-file )
win32-file new-win32-handle ;
HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
2007-09-20 18:09:08 -04:00
HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )
HOOK: add-completion io-backend ( port -- )
: opened-file ( handle -- win32-file )
dup invalid-handle?
<win32-file> |dispose
dup add-completion ;
2007-09-20 18:09:08 -04:00
: share-mode ( -- fixnum )
2008-02-02 14:29:09 -05:00
{
FILE_SHARE_READ
FILE_SHARE_WRITE
FILE_SHARE_DELETE
} flags ; foldable
2007-09-20 18:09:08 -04:00
2008-01-25 00:49:03 -05:00
: default-security-attributes ( -- obj )
"SECURITY_ATTRIBUTES" <c-object>
2008-04-04 13:02:25 -04:00
"SECURITY_ATTRIBUTES" heap-size
over set-SECURITY_ATTRIBUTES-nLength ;
2008-01-25 00:49:03 -05:00
: security-attributes-inherit ( -- obj )
default-security-attributes
TRUE over set-SECURITY_ATTRIBUTES-bInheritHandle ; foldable