@@ -27,35 +27,33 @@ extension FileManager {
27
27
internal func _mountedVolumeURLs( includingResourceValuesForKeys propertyKeys: [ URLResourceKey ] ? , options: VolumeEnumerationOptions = [ ] ) -> [ URL ] ? {
28
28
var urls : [ URL ] = [ ]
29
29
30
- var wszVolumeName : UnsafeMutableBufferPointer < WCHAR > = UnsafeMutableBufferPointer< WCHAR> . allocate( capacity: Int ( MAX_PATH) )
31
- defer { wszVolumeName. deallocate ( ) }
30
+ var wszVolumeName : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH) )
32
31
33
- var hVolumes : HANDLE = FindFirstVolumeW ( wszVolumeName. baseAddress , DWORD ( wszVolumeName. count) )
32
+ var hVolumes : HANDLE = FindFirstVolumeW ( & wszVolumeName, DWORD ( wszVolumeName. count) )
34
33
guard hVolumes != INVALID_HANDLE_VALUE else { return nil }
35
34
defer { FindVolumeClose ( hVolumes) }
36
35
37
36
repeat {
38
37
var dwCChReturnLength : DWORD = 0
39
- GetVolumePathNamesForVolumeNameW ( wszVolumeName. baseAddress , nil , 0 , & dwCChReturnLength)
38
+ GetVolumePathNamesForVolumeNameW ( & wszVolumeName, nil , 0 , & dwCChReturnLength)
40
39
41
- var wszPathNames : UnsafeMutableBufferPointer < WCHAR > = UnsafeMutableBufferPointer< WCHAR> . allocate( capacity: Int ( dwCChReturnLength + 1 ) )
42
- defer { wszPathNames. deallocate ( ) }
43
-
44
- if !GetVolumePathNamesForVolumeNameW( wszVolumeName. baseAddress, wszPathNames. baseAddress, DWORD ( wszPathNames. count) , & dwCChReturnLength) {
40
+ var wszPathNames : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( dwCChReturnLength + 1 ) )
41
+ if !GetVolumePathNamesForVolumeNameW( & wszVolumeName, & wszPathNames, DWORD ( wszPathNames. count) , & dwCChReturnLength) {
45
42
// TODO(compnerd) handle error
46
43
continue
47
44
}
48
45
49
46
var pPath : DWORD = 0
50
47
repeat {
51
- let path : String = String ( decodingCString: wszPathNames. baseAddress! + Int( pPath) , as: UTF16 . self)
48
+ let path : String = String ( decodingCString: & wszPathNames[ Int ( pPath) ] , as: UTF16 . self)
52
49
if path. length == 0 {
53
50
break
54
51
}
55
52
urls. append ( URL ( fileURLWithPath: path, isDirectory: true ) )
56
53
pPath += DWORD ( path. length + 1 )
57
54
} while pPath < dwCChReturnLength
58
- } while FindNextVolumeW ( hVolumes, wszVolumeName. baseAddress, DWORD ( wszVolumeName. count) )
55
+ } while FindNextVolumeW ( hVolumes, & wszVolumeName, DWORD ( wszVolumeName. count) )
56
+
59
57
return urls
60
58
}
61
59
internal func _urls( for directory: SearchPathDirectory , in domainMask: SearchPathDomainMask ) -> [ URL ] {
@@ -245,17 +243,16 @@ extension FileManager {
245
243
246
244
try path. withCString ( encodedAs: UTF16 . self) {
247
245
let dwLength : DWORD = GetFullPathNameW ( $0, 0 , nil , nil )
248
- let szVolumePath : UnsafeMutableBufferPointer < WCHAR > = UnsafeMutableBufferPointer< WCHAR> . allocate( capacity: Int ( dwLength + 1 ) )
249
- defer { szVolumePath. deallocate ( ) }
246
+ var szVolumePath : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( dwLength + 1 ) )
250
247
251
- guard GetVolumePathNameW ( $0, szVolumePath. baseAddress , dwLength) else {
248
+ guard GetVolumePathNameW ( $0, & szVolumePath, dwLength) else {
252
249
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
253
250
}
254
251
255
252
var liTotal : ULARGE_INTEGER = ULARGE_INTEGER ( )
256
253
var liFree : ULARGE_INTEGER = ULARGE_INTEGER ( )
257
254
258
- guard GetDiskFreeSpaceExW ( szVolumePath. baseAddress , nil , & liTotal, & liFree) else {
255
+ guard GetDiskFreeSpaceExW ( & szVolumePath, nil , & liTotal, & liFree) else {
259
256
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
260
257
}
261
258
@@ -297,11 +294,10 @@ extension FileManager {
297
294
}
298
295
299
296
let dwLength : DWORD = GetFinalPathNameByHandleW ( hFile, nil , 0 , DWORD ( FILE_NAME_NORMALIZED) )
300
- let szPath : UnsafeMutableBufferPointer < WCHAR > = UnsafeMutableBufferPointer< WCHAR> . allocate( capacity: Int ( dwLength + 1 ) )
301
- defer { szPath. deallocate ( ) }
297
+ var szPath : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( dwLength + 1 ) )
302
298
303
- GetFinalPathNameByHandleW ( hFile, szPath. baseAddress , dwLength, DWORD ( FILE_NAME_NORMALIZED) )
304
- return String ( decodingCString: szPath. baseAddress! , as: UTF16 . self)
299
+ GetFinalPathNameByHandleW ( hFile, & szPath, dwLength, DWORD ( FILE_NAME_NORMALIZED) )
300
+ return String ( decodingCString: & szPath, as: UTF16 . self)
305
301
}
306
302
307
303
internal func _copyRegularFile( atPath srcPath: String , toPath dstPath: String , variant: String = " Copy " ) throws {
@@ -469,11 +465,10 @@ extension FileManager {
469
465
470
466
internal func _currentDirectoryPath( ) -> String {
471
467
let dwLength : DWORD = GetCurrentDirectoryW ( 0 , nil )
472
- var szDirectory : UnsafeMutableBufferPointer < WCHAR > = UnsafeMutableBufferPointer . allocate ( capacity: Int ( dwLength + 1 ) )
473
- defer { szDirectory. deallocate ( ) }
468
+ var szDirectory : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( dwLength + 1 ) )
474
469
475
- GetCurrentDirectoryW ( dwLength, szDirectory. baseAddress )
476
- return String ( decodingCString: szDirectory. baseAddress! , as: UTF16 . self)
470
+ GetCurrentDirectoryW ( dwLength, & szDirectory)
471
+ return String ( decodingCString: & szDirectory, as: UTF16 . self)
477
472
}
478
473
479
474
@discardableResult
0 commit comments