         let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(fileInfo.st_blksize))
         defer { buffer.deallocate() }
 
-        var bytesRemaining = Int(fileInfo.st_size)
+        // Casted to Int64 because fileInfo.st_size is 64 bits long even on 32 bit platforms
+        var bytesRemaining = Int64(fileInfo.st_size)
         while bytesRemaining > 0 {
-            let bytesToRead = min(bytesRemaining, Int(fileInfo.st_blksize))
-            let bytesRead = try _readFrom(fd: srcfd, toBuffer: buffer, length: bytesToRead, filename: srcPath)
+            let bytesToRead = min(bytesRemaining, Int64(fileInfo.st_blksize))
+            let bytesRead = try _readFrom(fd: srcfd, toBuffer: buffer, length: Int(bytesToRead), filename: srcPath)
             if bytesRead == 0 {
                 // Early EOF
                 return
             }
             try _writeTo(fd: dstfd, fromBuffer: buffer, length: bytesRead, filename: dstPath)
-            bytesRemaining -= bytesRead
+            bytesRemaining -= Int64(bytesRead)
         }
     }
 

            buffer2.deallocate()
        }

        var bytesLeft = Int(size)
        while bytesLeft > 0 {
            let bytesToRead = min(bufSize, bytesLeft)
            guard read(fd1, buffer1, bytesToRead) == bytesToRead else {
                return false
            }

            guard memcmp(buffer1, buffer2, bytesToRead) == 0 else {
                return false
            }
            bytesLeft -= Int64(bytesToRead)
        }
        return true
    }
