1 USING: continuations destructors io.buffers io.files io.backend
2 io.timeouts io.ports io.pathnames io.files.private
3 io.backend.windows io.files.windows io.encodings.utf16n windows
4 windows.kernel32 kernel libc math threads system environment
5 alien.c-types alien.arrays alien.strings sequences combinators
6 combinators.short-circuit ascii splitting alien strings assocs
7 namespaces make accessors tr windows.time windows.shell32
8 windows.errors specialized-arrays classes.struct ;
9 SPECIALIZED-ARRAY: ushort
10 IN: io.files.windows.nt
13 MAX_UNICODE_PATH dup <ushort-array>
14 [ GetCurrentDirectory win32-error=0/f ] keep
18 SetCurrentDirectory win32-error=0/f ;
20 CONSTANT: unicode-prefix "\\\\?\\"
22 M: winnt root-directory? ( path -- ? )
24 { [ dup empty? ] [ drop f ] }
25 { [ dup [ path-separator? ] all? ] [ drop t ] }
26 { [ dup trim-tail-separators { [ length 2 = ]
27 [ second CHAR: : = ] } 1&& ] [ drop t ] }
28 { [ dup unicode-prefix head? ]
29 [ trim-tail-separators length unicode-prefix length 2 + = ] }
33 : prepend-prefix ( string -- string' )
34 dup unicode-prefix head? [
35 unicode-prefix prepend
38 TR: normalize-separators "/" "\\" ;
40 M: winnt normalize-path ( string -- string' )
45 M: winnt CreateFile-flags ( DWORD -- DWORD )
46 FILE_FLAG_OVERLAPPED bitor ;
50 : windows-file-size ( path -- size )
51 normalize-path 0 WIN32_FILE_ATTRIBUTE_DATA <struct>
52 [ GetFileAttributesEx win32-error=0/f ] keep
53 [ nFileSizeLow>> ] [ nFileSizeHigh>> ] bi >64bit ;
58 [ dup windows-file-size ] [ drop 0 ] recover
59 [ (open-append) ] dip >>ptr ;
63 [ "HOMEDRIVE" os-env "HOMEPATH" os-env append-path ]
64 [ "USERPROFILE" os-env ]