in Sources/TSCBasic/FileSystem.swift [402:430]
func readFileContents(_ path: AbsolutePath) throws -> ByteString {
// Open the file.
let fp = fopen(path.pathString, "rb")
if fp == nil {
throw FileSystemError(errno: errno, path)
}
defer { fclose(fp) }
// Read the data one block at a time.
let data = BufferedOutputByteStream()
var tmpBuffer = [UInt8](repeating: 0, count: 1 << 12)
while true {
let n = fread(&tmpBuffer, 1, tmpBuffer.count, fp)
if n < 0 {
if errno == EINTR { continue }
throw FileSystemError(.ioError(code: errno), path)
}
if n == 0 {
let errno = ferror(fp)
if errno != 0 {
throw FileSystemError(.ioError(code: errno), path)
}
break
}
data <<< tmpBuffer[0..<n]
}
return data.bytes
}