mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-04 12:55:02 +02:00
refactor: Add AutoFile::size
This commit is contained in:
@@ -57,6 +57,20 @@ int64_t AutoFile::tell()
|
||||
return *m_position;
|
||||
}
|
||||
|
||||
int64_t AutoFile::size()
|
||||
{
|
||||
if (IsNull()) {
|
||||
throw std::ios_base::failure("AutoFile::size: file handle is nullptr");
|
||||
}
|
||||
// Temporarily save the current position
|
||||
int64_t current_pos = tell();
|
||||
seek(0, SEEK_END);
|
||||
int64_t file_size = tell();
|
||||
// Restore the original position
|
||||
seek(current_pos, SEEK_SET);
|
||||
return file_size;
|
||||
}
|
||||
|
||||
void AutoFile::read(std::span<std::byte> dst)
|
||||
{
|
||||
if (detail_fread(dst) != dst.size()) {
|
||||
|
||||
Reference in New Issue
Block a user