diff --git a/src/fs/io/FileReader.cxx b/src/fs/io/FileReader.cxx index 442ebed5d..28dbc2c8c 100644 --- a/src/fs/io/FileReader.cxx +++ b/src/fs/io/FileReader.cxx @@ -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() { diff --git a/src/fs/io/FileReader.hxx b/src/fs/io/FileReader.hxx index ee931592b..3a04ea8df 100644 --- a/src/fs/io/FileReader.hxx +++ b/src/fs/io/FileReader.hxx @@ -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;