system/Open: new UniqueFileDescriptor constructing library

This commit is contained in:
Max Kellermann
2018-08-21 18:16:52 +02:00
parent ab7597b089
commit d092a88a93
4 changed files with 147 additions and 4 deletions

View File

@@ -21,6 +21,7 @@
#include "FileReader.hxx"
#include "fs/FileInfo.hxx"
#include "system/Error.hxx"
#include "system/Open.hxx"
#include <assert.h>
@@ -88,11 +89,8 @@ FileReader::Close() noexcept
#else
FileReader::FileReader(Path _path)
:path(_path)
:path(_path), fd(OpenReadOnly(path.c_str()))
{
fd.OpenReadOnly(path.c_str());
if (!fd.IsDefined())
throw FormatErrno("Failed to open %s", path.ToUTF8().c_str());
}
FileInfo