1 ! Copyright (C) 2005, 2006 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.syntax alien.c-types alien.strings arrays
4 combinators kernel math namespaces parser prettyprint sequences
5 windows.errors windows.types windows.kernel32 words
9 : lo-word ( wparam -- lo ) <short> *short ; inline
10 : hi-word ( wparam -- hi ) -16 shift lo-word ; inline
11 : MAX_UNICODE_PATH 32768 ; inline
13 ! You must LocalFree the return value!
14 FUNCTION: void* error_message ( DWORD id ) ;
16 : (win32-error-string) ( n -- string )
18 dup utf16n alien>string
21 : win32-error-string ( -- str )
22 GetLastError (win32-error-string) ;
24 : (win32-error) ( n -- )
28 win32-error-string throw
32 GetLastError (win32-error) ;
34 : win32-error=0/f ( n -- ) { 0 f } member? [ win32-error ] when ;
35 : win32-error>0 ( n -- ) 0 > [ win32-error ] when ;
36 : win32-error<0 ( n -- ) 0 < [ win32-error ] when ;
37 : win32-error<>0 ( n -- ) zero? [ win32-error ] unless ;
39 : invalid-handle? ( handle -- )
40 INVALID_HANDLE_VALUE = [
41 win32-error-string throw
44 : expected-io-errors ( -- seq )
48 WAIT_TIMEOUT 4array ; foldable
50 : expected-io-error? ( error-code -- ? )
51 expected-io-errors member? ;
53 : expected-io-error ( error-code -- )
54 dup expected-io-error? [
57 (win32-error-string) throw
60 : io-error ( return-value -- )
61 { 0 f } member? [ GetLastError expected-io-error ] when ;