factor/basis/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
io.timeouts io.ports io.windows io.windows.files
io.windows.nt.backend windows windows.kernel32
kernel libc math threads system
2008-04-21 20:20:18 -04:00
alien.c-types alien.arrays alien.strings sequences combinators
2008-06-27 02:56:53 -04:00
combinators.short-circuit ascii splitting alien strings
2008-09-11 02:27:23 -04:00
assocs namespaces make io.files.private accessors tr ;
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
{
2008-09-18 18:45:15 -04:00
{ [ dup empty? ] [ drop f ] }
{ [ dup [ path-separator? ] all? ] [ drop t ] }
{ [ dup trim-right-separators { [ length 2 = ]
[ second CHAR: : = ] } 1&& ] [ drop t ] }
{ [ dup unicode-prefix head? ]
[ trim-right-separators length unicode-prefix length 2 + = ] }
[ drop f ]
} cond ;
2008-03-25 20:52:07 -04:00
ERROR: not-absolute-path ;
2008-05-15 02:45:32 -04:00
: root-directory ( string -- string' )
2008-06-27 02:56:53 -04:00
dup {
[ length 2 >= ]
[ second CHAR: : = ]
[ first Letter? ]
} 1&& [ 2 head ] [ not-absolute-path ] if ;
: prepend-prefix ( string -- string' )
dup unicode-prefix head? [
unicode-prefix prepend
] unless ;
TR: normalize-separators "/" "\\" ;
2008-04-02 21:09:56 -04:00
M: winnt normalize-path ( string -- string' )
(normalize-path)
normalize-separators
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> >>ptr ;