Windows code updates

release
Slava Pestov 2007-11-21 01:26:15 -05:00
parent e7cc5ea6d4
commit 52c3db354b
3 changed files with 9 additions and 33 deletions

View File

@ -1,16 +0,0 @@
USING: io.files kernel tools.test ;
IN: temporary
[ "c:\\foo\\" ] [ "c:\\foo\\bar" parent-directory ] unit-test
[ "c:\\" ] [ "c:\\foo\\" parent-directory ] unit-test
[ "c:\\" ] [ "c:\\foo" parent-directory ] unit-test
! { "c:" "c:\\" "c:/" } [ directory ] each -- all do the same thing
[ "c:\\" ] [ "c:\\" parent-directory ] unit-test
[ "Z:\\" ] [ "Z:\\" parent-directory ] unit-test
[ "c:" ] [ "c:" parent-directory ] unit-test
[ "Z:" ] [ "Z:" parent-directory ] unit-test
[ t ] [ "c:\\" root-directory? ] unit-test
[ t ] [ "Z:\\" root-directory? ] unit-test
[ f ] [ "c:\\foo" root-directory? ] unit-test
[ f ] [ "." root-directory? ] unit-test
[ f ] [ ".." root-directory? ] unit-test

1
extra/windows/errors/errors.factor Normal file → Executable file
View File

@ -3,6 +3,7 @@ IN: windows.errors
: ERROR_SUCCESS 0 ; inline
: ERROR_HANDLE_EOF 38 ; inline
: ERROR_BROKEN_PIPE 109 ; inline
: ERROR_IO_INCOMPLETE 996 ; inline
: ERROR_IO_PENDING 997 ; inline

25
extra/windows/windows.factor Normal file → Executable file
View File

@ -39,30 +39,21 @@ FUNCTION: void* error_message ( DWORD id ) ;
win32-error-string throw
] when ;
: (expected-io-error?) ( error-code -- ? )
: expected-io-errors
ERROR_SUCCESS
ERROR_IO_INCOMPLETE
ERROR_IO_PENDING
WAIT_TIMEOUT 4array member? ;
WAIT_TIMEOUT 4array ; foldable
: expected-io-error? ( error-code -- )
dup (expected-io-error?) [
: expected-io-error? ( error-code -- ? )
expected-io-errors member? ;
: expected-io-error ( error-code -- )
dup expected-io-error? [
drop
] [
(win32-error-string) throw
] if ;
: io-error ( return-value -- )
{ 0 f } member? [ GetLastError expected-io-error? ] when ;
: overlapped-error? ( port n -- ? )
zero? [
GetLastError
{
{ [ dup (expected-io-error?) ] [ 2drop t ] }
{ [ dup ERROR_HANDLE_EOF = ] [ drop t swap set-port-eof? f ] }
{ [ t ] [ (win32-error-string) throw ] }
} cond
] [
drop t
] if ;
{ 0 f } member? [ GetLastError expected-io-error ] when ;