@@ -503,16 +503,17 @@ open class FileManager : NSObject {
503
503
let buffer = UnsafeMutablePointer< UInt8> . allocate( capacity: Int ( fileInfo. st_blksize) )
504
504
defer { buffer. deallocate ( ) }
505
505
506
- var bytesRemaining = Int ( fileInfo. st_size)
506
+ // Casted to Int64 because fileInfo.st_size is 64 bits long even on 32 bit platforms
507
+ var bytesRemaining = Int64 ( fileInfo. st_size)
507
508
while bytesRemaining > 0 {
508
- let bytesToRead = min ( bytesRemaining, Int ( fileInfo. st_blksize) )
509
- let bytesRead = try _readFrom ( fd: srcfd, toBuffer: buffer, length: bytesToRead, filename: srcPath)
509
+ let bytesToRead = min ( bytesRemaining, Int64 ( fileInfo. st_blksize) )
510
+ let bytesRead = try _readFrom ( fd: srcfd, toBuffer: buffer, length: Int ( bytesToRead) , filename: srcPath)
510
511
if bytesRead == 0 {
511
512
// Early EOF
512
513
return
513
514
}
514
515
try _writeTo ( fd: dstfd, fromBuffer: buffer, length: bytesRead, filename: dstPath)
515
- bytesRemaining -= bytesRead
516
+ bytesRemaining -= Int64 ( bytesRead)
516
517
}
517
518
}
518
519
@@ -693,10 +694,10 @@ open class FileManager : NSObject {
693
694
/* Process working directory management. Despite the fact that these are instance methods on FileManager, these methods report and change (respectively) the working directory for the entire process. Developers are cautioned that doing so is fraught with peril.
694
695
*/
695
696
open var currentDirectoryPath : String {
696
- let len = Int ( PATH_MAX) + 1
697
- var buf = [ Int8] ( repeating: 0 , count: len )
698
- getcwd ( & buf, len )
699
- return string ( withFileSystemRepresentation: buf, length: len )
697
+ let length = Int ( PATH_MAX) + 1
698
+ var buf = [ Int8] ( repeating: 0 , count: length )
699
+ getcwd ( & buf, length )
700
+ return string ( withFileSystemRepresentation: buf, length: Int ( strlen ( buf ) ) )
700
701
}
701
702
702
703
@discardableResult
@@ -778,9 +779,9 @@ open class FileManager : NSObject {
778
779
buffer2. deallocate ( )
779
780
}
780
781
781
- var bytesLeft = Int ( size)
782
+ var bytesLeft = size
782
783
while bytesLeft > 0 {
783
- let bytesToRead = min ( bufSize, bytesLeft)
784
+ let bytesToRead = Int ( min ( Int64 ( bufSize) , bytesLeft) )
784
785
guard read ( fd1, buffer1, bytesToRead) == bytesToRead else {
785
786
return false
786
787
}
@@ -790,7 +791,7 @@ open class FileManager : NSObject {
790
791
guard memcmp ( buffer1, buffer2, bytesToRead) == 0 else {
791
792
return false
792
793
}
793
- bytesLeft -= bytesToRead
794
+ bytesLeft -= Int64 ( bytesToRead)
794
795
}
795
796
return true
796
797
}
0 commit comments