1 USING: accessors alien.c-types alien.strings classes.struct
2 combinators combinators.short-circuit continuations environment
3 io.backend io.backend.windows io.encodings.utf16n
4 io.files.private io.files.windows io.pathnames kernel math
5 sequences specialized-arrays
6 specialized-arrays.instances.alien.c-types.ushort system tr
7 windows windows.errors windows.kernel32 windows.shell32
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 ]