func readLine()

in Sources/SystemMetrics/SystemMetrics.swift [219:254]


            func readLine() -> String? {
                guard let f = self.file else {
                    return nil
                }
                #if compiler(>=5.1)
                let buff: [CChar] = Array(unsafeUninitializedCapacity: 1024) { ptr, size in
                    guard fgets(ptr.baseAddress, Int32(ptr.count), f) != nil else {
                        if feof(f) != 0 {
                            size = 0
                            return
                        } else {
                            preconditionFailure("Error reading line")
                        }
                    }
                    size = strlen(ptr.baseAddress!)
                }
                if buff.isEmpty { return nil }
                return String(cString: buff)
                #else
                var buff = [CChar](repeating: 0, count: 1024)
                let hasNewLine = buff.withUnsafeMutableBufferPointer { ptr -> Bool in
                    guard fgets(ptr.baseAddress, Int32(ptr.count), f) != nil else {
                        if feof(f) != 0 {
                            return false
                        } else {
                            preconditionFailure("Error reading line")
                        }
                    }
                    return true
                }
                if !hasNewLine {
                    return nil
                }
                return String(cString: buff)
                #endif
            }