factor/extra/io/windows/nt/files/files.factor

62 lines
1.7 KiB
Factor
Raw Normal View History

USING: continuations destructors io.buffers io.files io.backend
2008-05-13 19:24:46 -04:00
io.timeouts io.ports io.windows io.windows.nt.backend
2008-04-02 21:09:56 -04:00
kernel libc math threads windows windows.kernel32 system
2008-04-21 20:20:18 -04:00
alien.c-types alien.arrays alien.strings sequences combinators
combinators.lib sequences.lib ascii splitting alien strings
assocs namespaces io.files.private accessors ;
2007-09-20 18:09:08 -04:00
IN: io.windows.nt.files
2008-04-02 21:09:56 -04:00
M: winnt cwd
MAX_UNICODE_PATH dup "ushort" <c-array>
[ GetCurrentDirectory win32-error=0/f ] keep
2008-04-20 06:15:46 -04:00
utf16n alien>string ;
2008-04-02 21:09:56 -04:00
M: winnt cd
SetCurrentDirectory win32-error=0/f ;
: unicode-prefix ( -- seq )
"\\\\?\\" ; inline
2008-04-02 21:09:56 -04:00
M: winnt root-directory? ( path -- ? )
2008-03-27 17:22:24 -04:00
{
{ [ dup empty? ] [ f ] }
{ [ dup [ path-separator? ] all? ] [ t ] }
{ [ dup right-trim-separators
{ [ dup length 2 = ] [ dup second CHAR: : = ] } && nip ] [
t
] }
2008-04-11 13:56:11 -04:00
[ f ]
2008-03-27 17:22:24 -04:00
} cond nip ;
2008-03-25 20:52:07 -04:00
ERROR: not-absolute-path ;
2008-05-15 02:45:32 -04:00
: root-directory ( string -- string' )
{
[ dup length 2 >= ]
[ dup second CHAR: : = ]
[ dup first Letter? ]
2008-03-25 20:52:07 -04:00
} && [ 2 head ] [ not-absolute-path ] if ;
: prepend-prefix ( string -- string' )
dup unicode-prefix head? [
unicode-prefix prepend
] unless ;
2008-04-02 21:09:56 -04:00
M: winnt normalize-path ( string -- string' )
(normalize-path)
{ { CHAR: / CHAR: \\ } } substitute
prepend-prefix ;
2008-04-02 21:09:56 -04:00
M: winnt CreateFile-flags ( DWORD -- DWORD )
FILE_FLAG_OVERLAPPED bitor ;
2007-09-20 18:09:08 -04:00
2008-04-02 21:09:56 -04:00
M: winnt FileArgs-overlapped ( port -- overlapped )
2007-09-20 18:09:08 -04:00
make-overlapped ;
2008-05-06 05:26:46 -04:00
M: winnt open-append
[ dup file-info size>> ] [ drop 0 ] recover
>r (open-append) r> ;
2007-09-20 18:09:08 -04:00
: update-file-ptr ( n port -- )
2008-05-15 01:13:08 -04:00
handle>> dup ptr>> [ rot + >>ptr drop ] [ 2drop ] if* ;