summaryrefslogtreecommitdiff
path: root/src/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/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/data.cc')
-rw-r--r--src/data.cc8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/data.cc b/src/data.cc
index 79f58f93..a26d4d1b 100644
--- a/src/data.cc
+++ b/src/data.cc
@@ -38,8 +38,8 @@
#include "data.h"
+#include "file.h"
#include "exceptions.h"
-#include "util.h"
#include <cstdio>
#include <cerrno>
@@ -50,13 +50,11 @@ using namespace dcp;
void
Data::write (boost::filesystem::path file) const
{
- auto f = fopen_boost (file, "wb");
+ File f(file, "wb");
if (!f) {
throw FileError ("could not write to file", file, errno);
}
- size_t const r = fwrite (data(), 1, size(), f);
- fclose (f);
- if (r != size_t(size())) {
+ if (f.write(data(), 1, size()) != size_t(size())) {
throw FileError ("could not write to file", file, errno);
}
}