]> gitweb.factorcode.org Git - factor.git/blob - basis/io/windows/nt/files/files.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / io / windows / nt / files / files.factor
1 USING: continuations destructors io.buffers io.files io.backend
2 io.timeouts io.ports io.files.private io.windows
3 io.windows.files io.windows.nt.backend io.encodings.utf16n
4 windows windows.kernel32 kernel libc math threads system
5 environment alien.c-types alien.arrays alien.strings sequences
6 combinators combinators.short-circuit ascii splitting alien
7 strings assocs namespaces make accessors tr ;
8 IN: io.windows.nt.files
9
10 M: winnt cwd
11     MAX_UNICODE_PATH dup "ushort" <c-array>
12     [ GetCurrentDirectory win32-error=0/f ] keep
13     utf16n alien>string ;
14
15 M: winnt cd
16     SetCurrentDirectory win32-error=0/f ;
17
18 : unicode-prefix ( -- seq )
19     "\\\\?\\" ; inline
20
21 M: winnt root-directory? ( path -- ? )
22     {
23         { [ dup empty? ] [ drop f ] }
24         { [ dup [ path-separator? ] all? ] [ drop t ] }
25         { [ dup trim-right-separators { [ length 2 = ]
26           [ second CHAR: : = ] } 1&& ] [ drop t ] }
27         { [ dup unicode-prefix head? ]
28           [ trim-right-separators length unicode-prefix length 2 + = ] }
29         [ drop f ]
30     } cond ;
31
32 ERROR: not-absolute-path ;
33
34 M: winnt root-directory ( string -- string' )
35     unicode-prefix ?head drop
36     dup {
37         [ length 2 >= ]
38         [ second CHAR: : = ]
39         [ first Letter? ]
40     } 1&& [ 2 head "\\" append ] [ not-absolute-path ] if ;
41
42 : prepend-prefix ( string -- string' )
43     dup unicode-prefix head? [
44         unicode-prefix prepend
45     ] unless ;
46
47 TR: normalize-separators "/" "\\" ;
48
49 M: winnt normalize-path ( string -- string' )
50     (normalize-path)
51     normalize-separators
52     prepend-prefix ;
53
54 M: winnt CreateFile-flags ( DWORD -- DWORD )
55     FILE_FLAG_OVERLAPPED bitor ;
56
57 M: winnt FileArgs-overlapped ( port -- overlapped )
58     make-overlapped ;
59
60 M: winnt open-append
61     [ dup file-info size>> ] [ drop 0 ] recover
62     [ (open-append) ] dip >>ptr ;
63
64 M: winnt home "USERPROFILE" os-env ;