fs/io/FileReader: add method Seek()
This commit is contained in:
parent
ef5090c397
commit
dd5daa0767
@ -52,6 +52,19 @@ FileReader::Read(void *data, size_t size, Error &error)
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
bool
|
||||
FileReader::Seek(off_t offset, Error &error)
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
auto result = SetFilePointer(handle, offset, nullptr, FILE_BEGIN);
|
||||
const bool success = result != INVALID_SET_FILE_POINTER;
|
||||
if (!success)
|
||||
error.SetLastError("Failed to seek");
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void
|
||||
FileReader::Close()
|
||||
{
|
||||
@ -90,6 +103,19 @@ FileReader::Read(void *data, size_t size, Error &error)
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
bool
|
||||
FileReader::Seek(off_t offset, Error &error)
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
auto result = lseek(fd, offset, SEEK_SET);
|
||||
const bool success = result >= 0;
|
||||
if (!success)
|
||||
error.SetErrno("Failed to seek");
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void
|
||||
FileReader::Close()
|
||||
{
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
|
||||
void Close();
|
||||
|
||||
bool Seek(off_t offset, Error &error);
|
||||
|
||||
/* virtual methods from class Reader */
|
||||
size_t Read(void *data, size_t size, Error &error) override;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user