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 ;
8 : lo-word ( wparam -- lo ) <short> *short ; inline
9 : hi-word ( wparam -- hi ) -16 shift lo-word ; inline
10 : MAX_UNICODE_PATH 32768 ; inline
12 ! You must LocalFree the return value!
13 FUNCTION: void* error_message ( DWORD id ) ;
15 : (win32-error-string) ( n -- string )
17 dup utf16n alien>string
20 : win32-error-string ( -- str )
21 GetLastError (win32-error-string) ;
23 : (win32-error) ( n -- )
27 win32-error-string throw
31 GetLastError (win32-error) ;
33 : win32-error=0/f ( n -- ) { 0 f } member? [ win32-error ] when ;
34 : win32-error>0 ( n -- ) 0 > [ win32-error ] when ;
35 : win32-error<0 ( n -- ) 0 < [ win32-error ] when ;
36 : win32-error<>0 ( n -- ) zero? [ win32-error ] unless ;
38 : invalid-handle? ( handle -- )
39 INVALID_HANDLE_VALUE = [
40 win32-error-string throw
43 : expected-io-errors ( -- seq )
47 WAIT_TIMEOUT 4array ; foldable
49 : expected-io-error? ( error-code -- ? )
50 expected-io-errors member? ;
52 : expected-io-error ( error-code -- )
53 dup expected-io-error? [
56 (win32-error-string) throw
59 : io-error ( return-value -- )
60 { 0 f } member? [ GetLastError expected-io-error ] when ;