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/encrypted_kdm.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/encrypted_kdm.cc') diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc index 986f82e4..5e5f9fe4 100644 --- a/src/encrypted_kdm.cc +++ b/src/encrypted_kdm.cc @@ -37,11 +37,12 @@ */ -#include "encrypted_kdm.h" -#include "util.h" #include "certificate_chain.h" -#include "exceptions.h" #include "compose.hpp" +#include "encrypted_kdm.h" +#include "exceptions.h" +#include "file.h" +#include "util.h" #include #include #include @@ -730,14 +731,12 @@ EncryptedKDM::~EncryptedKDM () void EncryptedKDM::as_xml (boost::filesystem::path path) const { - auto f = fopen_boost (path, "w"); + File f(path, "w"); if (!f) { throw FileError ("Could not open KDM file for writing", path, errno); } auto const x = as_xml (); - size_t const written = fwrite (x.c_str(), 1, x.length(), f); - fclose (f); - if (written != x.length()) { + if (f.write(x.c_str(), 1, x.length()) != x.length()) { throw FileError ("Could not write to KDM file", path, errno); } } -- cgit v1.2.3