diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-04-12 22:34:04 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-04-20 20:04:21 +0200 |
| commit | 05bfa3d1fe9e274ed195647c6f74cb272f00c23d (patch) | |
| tree | 1372760463b288ff4e10ef7fb6e7414e202829f5 /src/array_data.cc | |
| parent | 0338e7a7c19617f9ebb64ee02fbf3cceab8cf03f (diff) | |
Add and use new File class.master
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.
Diffstat (limited to 'src/array_data.cc')
| -rw-r--r-- | src/array_data.cc | 11 |
1 files changed, 5 insertions, 6 deletions
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 <cstdio> +#include "util.h" #include <cerrno> +#include <cstdio> 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_t>(_size)) { + if (f.read(_data.get(), 1, _size) != static_cast<size_t>(_size)) { throw FileError ("could not read from file", file, errno); } } |
