From c83f348adce3a18a9144ecfd73f4629cf060cc2a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 12 Apr 2022 22:34:04 +0200 Subject: Add and use new File class. It was always a bit troubling that fopen_boost wasn't exception safe, and this also fixes a leak where load_ratings_list would never close the ratings file. --- src/array_data.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/array_data.cc') diff --git a/src/array_data.cc b/src/array_data.cc index 2df53830..1234ba22 100644 --- a/src/array_data.cc +++ b/src/array_data.cc @@ -38,10 +38,11 @@ #include "array_data.h" -#include "util.h" +#include "file.h" #include "exceptions.h" -#include +#include "util.h" #include +#include using boost::shared_array; @@ -83,14 +84,12 @@ ArrayData::ArrayData (boost::filesystem::path file) _size = boost::filesystem::file_size (file); _data.reset (new uint8_t[_size]); - auto f = fopen_boost (file, "rb"); + File f(file, "rb"); if (!f) { throw FileError ("could not open file for reading", file, errno); } - auto const r = fread (_data.get(), 1, _size, f); - fclose (f); - if (r != static_cast(_size)) { + if (f.read(_data.get(), 1, _size) != static_cast(_size)) { throw FileError ("could not read from file", file, errno); } } -- cgit v1.2.3