From 7f8ee64d284b01a3c5da6b89b66c7d85593fae99 Mon Sep 17 00:00:00 2001 From: "U-SLAVA-DFB8FF805\\Slava" Date: Tue, 6 May 2008 04:26:46 -0500 Subject: [PATCH] Implement on Windows --- extra/io/windows/nt/files/files.factor | 4 ++++ .../windows/nt/launcher/launcher-tests.factor | 17 ++++++++++++++++- extra/io/windows/nt/launcher/launcher.factor | 8 +++++++- extra/io/windows/nt/launcher/test/append.factor | 2 ++ extra/io/windows/windows.factor | 8 +++----- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100755 extra/io/windows/nt/launcher/test/append.factor diff --git a/extra/io/windows/nt/files/files.factor b/extra/io/windows/nt/files/files.factor index c9f17147d3..8839410d91 100755 --- a/extra/io/windows/nt/files/files.factor +++ b/extra/io/windows/nt/files/files.factor @@ -52,6 +52,10 @@ M: winnt CreateFile-flags ( DWORD -- DWORD ) M: winnt FileArgs-overlapped ( port -- overlapped ) make-overlapped ; +M: winnt open-append + [ dup file-info size>> ] [ drop 0 ] recover + >r (open-append) r> ; + : update-file-ptr ( n port -- ) port-handle dup win32-file-ptr [ diff --git a/extra/io/windows/nt/launcher/launcher-tests.factor b/extra/io/windows/nt/launcher/launcher-tests.factor index f4901fa90f..c5c0e6dec2 100755 --- a/extra/io/windows/nt/launcher/launcher-tests.factor +++ b/extra/io/windows/nt/launcher/launcher-tests.factor @@ -1,7 +1,7 @@ IN: io.windows.launcher.nt.tests USING: io.launcher tools.test calendar accessors namespaces kernel system arrays io io.files io.encodings.ascii -sequences parser assocs hashtables math ; +sequences parser assocs hashtables math continuations ; [ ] [ @@ -140,3 +140,18 @@ sequences parser assocs hashtables math ; [ ] [ "dir.txt" temp-file delete-file ] unit-test ] times + +[ "append-test" temp-file delete-file ] ignore-errors + +[ "Hello appender\r\nHello appender\r\n" ] [ + 2 [ + "resource:extra/io/windows/nt/launcher/test" [ + + vm "-script" "append.factor" 3array >>command + "append-test" temp-file >>stdout + try-process + ] with-directory + ] times + + "append-test" temp-file ascii file-contents +] unit-test diff --git a/extra/io/windows/nt/launcher/launcher.factor b/extra/io/windows/nt/launcher/launcher.factor index 5a00c27aaf..39edd931b1 100755 --- a/extra/io/windows/nt/launcher/launcher.factor +++ b/extra/io/windows/nt/launcher/launcher.factor @@ -51,6 +51,12 @@ IN: io.windows.nt.launcher f ! template file CreateFile dup invalid-handle? dup close-always ; +: redirect-append ( default path access-mode create-mode -- handle ) + >r >r path>> r> r> + drop OPEN_ALWAYS + redirect-file + dup 0 FILE_END set-file-pointer ; + : set-inherit ( handle ? -- ) >r HANDLE_FLAG_INHERIT r> >BOOLEAN SetHandleInformation win32-error=0/f ; @@ -66,7 +72,7 @@ IN: io.windows.nt.launcher { [ pick not ] [ redirect-default ] } { [ pick +closed+ eq? ] [ redirect-closed ] } { [ pick string? ] [ redirect-file ] } - { [ pick appender? ] [ redirect-file ] } + { [ pick appender? ] [ redirect-append ] } { [ pick win32-file? ] [ redirect-handle ] } [ redirect-stream ] } cond ; diff --git a/extra/io/windows/nt/launcher/test/append.factor b/extra/io/windows/nt/launcher/test/append.factor new file mode 100755 index 0000000000..4c1de0c5f9 --- /dev/null +++ b/extra/io/windows/nt/launcher/test/append.factor @@ -0,0 +1,2 @@ +USE: io +"Hello appender" print diff --git a/extra/io/windows/windows.factor b/extra/io/windows/windows.factor index acc3e28543..85c448bdbd 100755 --- a/extra/io/windows/windows.factor +++ b/extra/io/windows/windows.factor @@ -86,15 +86,13 @@ M: alien close-handle ( handle -- ) f CreateFileW dup win32-error=0/f GetLastError ERROR_ALREADY_EXISTS = not ; -: set-file-pointer ( handle length -- ) - dupd d>w/w FILE_BEGIN SetFilePointer +: set-file-pointer ( handle length method -- ) + >r dupd d>w/w r> SetFilePointer INVALID_SET_FILE_POINTER = [ CloseHandle "SetFilePointer failed" throw ] when drop ; -: open-append ( path -- handle length ) - [ dup file-info size>> ] [ drop 0 ] recover - >r (open-append) r> 2dup set-file-pointer ; +HOOK: open-append os ( path -- handle length ) TUPLE: FileArgs hFile lpBuffer nNumberOfBytesToRead