Skip to content

Commit 0a6f5a3

Browse files
committed
remove changes that break compatibillity on 32bit platforms
1 parent 0a619c3 commit 0a6f5a3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Foundation/FileManager.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,17 @@ open class FileManager : NSObject {
503503
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(fileInfo.st_blksize))
504504
defer { buffer.deallocate() }
505505

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)
507508
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)
510511
if bytesRead == 0 {
511512
// Early EOF
512513
return
513514
}
514515
try _writeTo(fd: dstfd, fromBuffer: buffer, length: bytesRead, filename: dstPath)
515-
bytesRemaining -= bytesRead
516+
bytesRemaining -= Int64(bytesRead)
516517
}
517518
}
518519

@@ -693,10 +694,10 @@ open class FileManager : NSObject {
693694
/* 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.
694695
*/
695696
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)))
700701
}
701702

702703
@discardableResult
@@ -778,9 +779,9 @@ open class FileManager : NSObject {
778779
buffer2.deallocate()
779780
}
780781

781-
var bytesLeft = Int(size)
782+
var bytesLeft = size
782783
while bytesLeft > 0 {
783-
let bytesToRead = min(bufSize, bytesLeft)
784+
let bytesToRead = Int(min(Int64(bufSize), bytesLeft))
784785
guard read(fd1, buffer1, bytesToRead) == bytesToRead else {
785786
return false
786787
}
@@ -790,7 +791,7 @@ open class FileManager : NSObject {
790791
guard memcmp(buffer1, buffer2, bytesToRead) == 0 else {
791792
return false
792793
}
793-
bytesLeft -= bytesToRead
794+
bytesLeft -= Int64(bytesToRead)
794795
}
795796
return true
796797
}

0 commit comments

Comments
 (0)