mirror of
https://github.com/apple/swift-system
synced 2026-11-26 04:57:54 +00:00
FileHelpers: Add FileDescriptor.fileSize
Signed-off-by: Si Beaumont <beaumont@apple.com>
This commit is contained in:
1 parent
a77a331dc7
commit
23ac190631
1 file changed
+14
@@ -122,4 +122,18 @@ extension FileDescriptor {
|
||||
return .success(buffer.count)
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the current size of the file.
|
||||
///
|
||||
/// - Returns: The current size of the file, in bytes.
|
||||
@_alwaysEmitIntoClient
|
||||
@discardableResult
|
||||
public func fileSize(
|
||||
retryOnInterrupt: Bool = true
|
||||
) throws -> Int64 {
|
||||
let current = try seek(offset: 0, from: .current)
|
||||
let size = try seek(offset: 0, from: .end)
|
||||
try seek(offset: current, from: .start)
|
||||
return size
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user