summaryrefslogtreecommitdiff
path: root/src/array_data.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-04-12 22:34:04 +0200
committerCarl Hetherington <cth@carlh.net>2022-04-12 22:34:04 +0200
commitc83f348adce3a18a9144ecfd73f4629cf060cc2a (patch)
tree5528c60440343b547c15f4a95aa6acd06453fafe /src/array_data.cc
parent04e215a7688239cb47fc86e8396756c685f338a1 (diff)
Add and use new File class.merged-to-main
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.cc11
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);
}
}