fs/io/FileReader: add method Skip()

This commit is contained in:
Max Kellermann 2016-02-19 18:18:25 +01:00
parent 8e0e4d7c04
commit 98bd4dfe04
2 changed files with 22 additions and 0 deletions

View File

@ -65,6 +65,16 @@ FileReader::Seek(off_t offset)
throw MakeLastError("Failed to seek");
}
void
FileReader::Skip(off_t offset)
{
assert(IsDefined());
auto result = SetFilePointer(handle, offset, nullptr, FILE_CURRENT);
if (result == INVALID_SET_FILE_POINTER)
throw MakeLastError("Failed to seek");
}
void
FileReader::Close()
{
@ -120,6 +130,17 @@ FileReader::Seek(off_t offset)
throw MakeErrno("Failed to seek");
}
void
FileReader::Skip(off_t offset)
{
assert(IsDefined());
auto result = fd.Skip(offset);
const bool success = result >= 0;
if (!success)
throw MakeErrno("Failed to seek");
}
void
FileReader::Close()
{

View File

@ -92,6 +92,7 @@ public:
FileInfo GetFileInfo() const;
void Seek(off_t offset);
void Skip(off_t offset);
/* virtual methods from class Reader */
size_t Read(void *data, size_t size) override;