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-20 20:04:21 +0200
commit05bfa3d1fe9e274ed195647c6f74cb272f00c23d (patch)
tree1372760463b288ff4e10ef7fb6e7414e202829f5 /src/data.cc
parent0338e7a7c19617f9ebb64ee02fbf3cceab8cf03f (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/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);
}
}