diff --git a/src/io/FileReader.cxx b/src/io/FileReader.cxx index 66fd93621..b7d8f597e 100644 --- a/src/io/FileReader.cxx +++ b/src/io/FileReader.cxx @@ -61,14 +61,6 @@ FileReader::Skip(off_t offset) throw MakeLastError("Failed to seek"); } -void -FileReader::Close() noexcept -{ - assert(IsDefined()); - - CloseHandle(handle); -} - #else FileReader::FileReader(Path _path) @@ -123,12 +115,4 @@ FileReader::Skip(off_t offset) throw MakeErrno("Failed to seek"); } -void -FileReader::Close() noexcept -{ - assert(IsDefined()); - - fd.Close(); -} - #endif diff --git a/src/io/FileReader.hxx b/src/io/FileReader.hxx index 7c37f93bf..671101bc5 100644 --- a/src/io/FileReader.hxx +++ b/src/io/FileReader.hxx @@ -1,8 +1,7 @@ // SPDX-License-Identifier: BSD-2-Clause // author: Max Kellermann -#ifndef FILE_READER_HXX -#define FILE_READER_HXX +#pragma once #include "Reader.hxx" #include "fs/AllocatedPath.hxx" @@ -39,8 +38,8 @@ public: handle(std::exchange(other.handle, INVALID_HANDLE_VALUE)) {} ~FileReader() noexcept { - if (IsDefined()) - Close(); + if (handle != INVALID_HANDLE_VALUE) + CloseHandle(handle); } #else FileReader(FileReader &&other) noexcept @@ -65,8 +64,6 @@ public: } #endif - void Close() noexcept; - FileInfo GetFileInfo() const; [[gnu::pure]] @@ -105,5 +102,3 @@ public: /* virtual methods from class Reader */ std::size_t Read(void *data, std::size_t size) override; }; - -#endif