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/data.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/data.cc') 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 #include @@ -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); } } -- cgit v1.2.3