@@ -49,10 +49,10 @@ extension NSError {
49
49
50
50
open class FileHandle : NSObject {
51
51
#if os(Windows)
52
- private var _handle : HANDLE
52
+ internal private( set ) var handle : HANDLE
53
53
54
- internal var handle : HANDLE {
55
- return _handle
54
+ public var _handle : HANDLE {
55
+ return self . handle
56
56
}
57
57
58
58
@available ( Windows, unavailable, message: " Cannot perform non-owning handle to fd conversion " )
@@ -61,11 +61,11 @@ open class FileHandle : NSObject {
61
61
}
62
62
63
63
private func _checkFileHandle( ) {
64
- precondition ( _handle != INVALID_HANDLE_VALUE, " Invalid file handle " )
64
+ precondition ( self . handle != INVALID_HANDLE_VALUE, " Invalid file handle " )
65
65
}
66
66
67
67
internal var _isPlatformHandleValid : Bool {
68
- return _handle != INVALID_HANDLE_VALUE
68
+ return self . handle != INVALID_HANDLE_VALUE
69
69
}
70
70
#else
71
71
private var _fd : Int32
@@ -228,15 +228,15 @@ open class FileHandle : NSObject {
228
228
return NSData . NSDataReadResult ( bytes: nil , length: 0 , deallocator: nil )
229
229
}
230
230
231
- if GetFileType ( _handle ) == FILE_TYPE_DISK {
231
+ if GetFileType ( self . handle ) == FILE_TYPE_DISK {
232
232
var fiFileInfo : BY_HANDLE_FILE_INFORMATION = BY_HANDLE_FILE_INFORMATION ( )
233
- if !GetFileInformationByHandle( _handle , & fiFileInfo) {
233
+ if !GetFileInformationByHandle( self . handle , & fiFileInfo) {
234
234
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
235
235
}
236
236
237
237
if options. contains ( . alwaysMapped) {
238
238
let hMapping : HANDLE =
239
- CreateFileMappingA ( _handle , nil , DWORD ( PAGE_READONLY) , 0 , 0 , nil )
239
+ CreateFileMappingA ( self . handle , nil , DWORD ( PAGE_READONLY) , 0 , 0 , nil )
240
240
if hMapping == HANDLE ( bitPattern: 0 ) {
241
241
fatalError ( " CreateFileMappingA failed " )
242
242
}
@@ -272,7 +272,7 @@ open class FileHandle : NSObject {
272
272
}
273
273
274
274
var BytesRead : DWORD = 0
275
- if !ReadFile( _handle , buffer. advanced ( by: total) , BytesToRead, & BytesRead, nil ) {
275
+ if !ReadFile( self . handle , buffer. advanced ( by: total) , BytesToRead, & BytesRead, nil ) {
276
276
let err = GetLastError ( )
277
277
if err == ERROR_BROKEN_PIPE {
278
278
break
@@ -370,7 +370,7 @@ open class FileHandle : NSObject {
370
370
#if os(Windows)
371
371
var BytesRead : DWORD = 0
372
372
let BytesToRead : DWORD = DWORD ( length)
373
- if !ReadFile( _handle , buffer, BytesToRead, & BytesRead, nil ) {
373
+ if !ReadFile( self . handle , buffer, BytesToRead, & BytesRead, nil ) {
374
374
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
375
375
}
376
376
return Int ( BytesRead)
@@ -413,7 +413,7 @@ open class FileHandle : NSObject {
413
413
414
414
#if os(Windows)
415
415
internal init ( handle: HANDLE , closeOnDealloc closeopt: Bool ) {
416
- _handle = handle
416
+ self . handle = handle
417
417
_closeOnDealloc = closeopt
418
418
}
419
419
@@ -424,10 +424,10 @@ open class FileHandle : NSObject {
424
424
fatalError ( " DuplicateHandle() failed: \( GetLastError ( ) ) " )
425
425
}
426
426
_close ( fd)
427
- _handle = handle!
427
+ self . handle = handle!
428
428
_closeOnDealloc = true
429
429
} else {
430
- _handle = HANDLE ( bitPattern: _get_osfhandle ( fd) ) !
430
+ self . handle = HANDLE ( bitPattern: _get_osfhandle ( fd) ) !
431
431
_closeOnDealloc = false
432
432
}
433
433
}
@@ -443,7 +443,7 @@ open class FileHandle : NSObject {
443
443
} ) , fd > 0 else { return nil }
444
444
445
445
self . init ( fileDescriptor: fd, closeOnDealloc: true )
446
- if _handle == INVALID_HANDLE_VALUE { return nil }
446
+ if self . handle == INVALID_HANDLE_VALUE { return nil }
447
447
}
448
448
#else
449
449
public init ( fileDescriptor fd: Int32 , closeOnDealloc closeopt: Bool ) {
@@ -525,7 +525,7 @@ open class FileHandle : NSObject {
525
525
526
526
#if os(Windows)
527
527
var liPointer : LARGE_INTEGER = LARGE_INTEGER ( QuadPart: 0 )
528
- guard SetFilePointerEx ( _handle , LARGE_INTEGER ( QuadPart: 0 ) , & liPointer, DWORD ( FILE_CURRENT) ) else {
528
+ guard SetFilePointerEx ( self . handle , LARGE_INTEGER ( QuadPart: 0 ) , & liPointer, DWORD ( FILE_CURRENT) ) else {
529
529
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
530
530
}
531
531
return UInt64 ( liPointer. QuadPart)
@@ -545,7 +545,7 @@ open class FileHandle : NSObject {
545
545
546
546
#if os(Windows)
547
547
var liPointer : LARGE_INTEGER = LARGE_INTEGER ( QuadPart: 0 )
548
- guard SetFilePointerEx ( _handle , LARGE_INTEGER ( QuadPart: 0 ) , & liPointer, DWORD ( FILE_END) ) else {
548
+ guard SetFilePointerEx ( self . handle , LARGE_INTEGER ( QuadPart: 0 ) , & liPointer, DWORD ( FILE_END) ) else {
549
549
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
550
550
}
551
551
return UInt64 ( liPointer. QuadPart)
@@ -563,7 +563,7 @@ open class FileHandle : NSObject {
563
563
guard _isPlatformHandleValid else { throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . fileReadUnknown. rawValue) }
564
564
565
565
#if os(Windows)
566
- guard SetFilePointerEx ( _handle , LARGE_INTEGER ( QuadPart: LONGLONG ( offset) ) , nil , DWORD ( FILE_BEGIN) ) else {
566
+ guard SetFilePointerEx ( self . handle , LARGE_INTEGER ( QuadPart: LONGLONG ( offset) ) , nil , DWORD ( FILE_BEGIN) ) else {
567
567
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
568
568
}
569
569
#else
@@ -578,10 +578,10 @@ open class FileHandle : NSObject {
578
578
guard _isPlatformHandleValid else { throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . fileWriteUnknown. rawValue) }
579
579
580
580
#if os(Windows)
581
- guard SetFilePointerEx ( _handle , LARGE_INTEGER ( QuadPart: LONGLONG ( offset) ) , nil , DWORD ( FILE_BEGIN) ) else {
581
+ guard SetFilePointerEx ( self . handle , LARGE_INTEGER ( QuadPart: LONGLONG ( offset) ) , nil , DWORD ( FILE_BEGIN) ) else {
582
582
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
583
583
}
584
- guard SetEndOfFile ( _handle ) else {
584
+ guard SetEndOfFile ( self . handle ) else {
585
585
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
586
586
}
587
587
#else
@@ -595,7 +595,7 @@ open class FileHandle : NSObject {
595
595
guard self != FileHandle . _nulldeviceFileHandle else { return }
596
596
597
597
#if os(Windows)
598
- guard FlushFileBuffers ( _handle ) else {
598
+ guard FlushFileBuffers ( self . handle ) else {
599
599
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
600
600
}
601
601
#else
@@ -638,10 +638,10 @@ open class FileHandle : NSObject {
638
638
privateAsyncVariablesLock. unlock ( )
639
639
640
640
#if os(Windows)
641
- guard CloseHandle ( _handle ) else {
641
+ guard CloseHandle ( self . handle ) else {
642
642
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
643
643
}
644
- _handle = INVALID_HANDLE_VALUE
644
+ self . handle = INVALID_HANDLE_VALUE
645
645
#else
646
646
guard _close ( _fd) >= 0 else {
647
647
throw _NSErrorWithErrno ( errno, reading: true )
0 commit comments