From 889be6e29d9cce5c009e0f56eeedf17d81e8bd8a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 27 Aug 2016 12:20:59 +0200 Subject: [PATCH] fs/io/FileReader: add methods GetSize(), GetPosition() --- src/fs/io/FileReader.hxx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/fs/io/FileReader.hxx b/src/fs/io/FileReader.hxx index 8e5ee9a12..d13acfdb1 100644 --- a/src/fs/io/FileReader.hxx +++ b/src/fs/io/FileReader.hxx @@ -89,6 +89,32 @@ public: gcc_pure FileInfo GetFileInfo() const; + gcc_pure + uint64_t GetSize() const { +#ifdef WIN32 + LARGE_INTEGER size; + return GetFileSizeEx(handle, &size) + ? size.QuadPart + : 0; +#else + return fd.GetSize(); +#endif + } + + gcc_pure + uint64_t GetPosition() const { +#ifdef WIN32 + LARGE_INTEGER zero; + zero.QuadPart = 0; + LARGE_INTEGER position; + return SetFilePointerEx(handle, zero, &position, FILE_CURRENT) + ? position.QuadPart + : 0; +#else + return fd.Tell(); +#endif + } + void Rewind() { Seek(0); }