]> gitweb.factorcode.org Git - factor.git/blob - basis/windows/windows.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / windows / windows.factor
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 ;
6 IN: windows
7
8 : lo-word ( wparam -- lo ) <short> *short ; inline
9 : hi-word ( wparam -- hi ) -16 shift lo-word ; inline
10 : MAX_UNICODE_PATH 32768 ; inline
11
12 ! You must LocalFree the return value!
13 FUNCTION: void* error_message ( DWORD id ) ;
14
15 : (win32-error-string) ( n -- string )
16     error_message
17     dup utf16n alien>string
18     swap LocalFree drop ;
19
20 : win32-error-string ( -- str )
21     GetLastError (win32-error-string) ;
22
23 : (win32-error) ( n -- )
24     dup zero? [
25         drop
26     ] [
27         win32-error-string throw
28     ] if ;
29
30 : win32-error ( -- )
31     GetLastError (win32-error) ;
32
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 ;
37
38 : invalid-handle? ( handle -- )
39     INVALID_HANDLE_VALUE = [
40         win32-error-string throw
41     ] when ;
42
43 : expected-io-errors ( -- seq )
44     ERROR_SUCCESS
45     ERROR_IO_INCOMPLETE
46     ERROR_IO_PENDING
47     WAIT_TIMEOUT 4array ; foldable
48
49 : expected-io-error? ( error-code -- ? )
50     expected-io-errors member? ;
51
52 : expected-io-error ( error-code -- )
53     dup expected-io-error? [
54         drop
55     ] [
56         (win32-error-string) throw
57     ] if ;
58
59 : io-error ( return-value -- )
60     { 0 f } member? [ GetLastError expected-io-error ] when ;