diff options
author | Max Kellermann <max@duempel.org> | 2015-03-03 14:29:36 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-03-03 14:29:36 +0100 |
commit | dd5daa0767c806b4027482f589ff1e9676b413e4 (patch) | |
tree | 70e873297cd2963e20887d81ec96f5730faf267a /src/fs/io/FileReader.cxx | |
parent | ef5090c3976ca14784c7b98f3d110e1213c158ba (diff) | |
download | mpd-dd5daa0767c806b4027482f589ff1e9676b413e4.tar.gz mpd-dd5daa0767c806b4027482f589ff1e9676b413e4.tar.xz mpd-dd5daa0767c806b4027482f589ff1e9676b413e4.zip |
fs/io/FileReader: add method Seek()
Diffstat (limited to 'src/fs/io/FileReader.cxx')
-rw-r--r-- | src/fs/io/FileReader.cxx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/fs/io/FileReader.cxx b/src/fs/io/FileReader.cxx index a19f472e8..e4198b71a 100644 --- a/src/fs/io/FileReader.cxx +++ b/src/fs/io/FileReader.cxx @@ -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() { |