From 05bfa3d1fe9e274ed195647c6f74cb272f00c23d 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. --- tools/dcpdumpsub.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/dcpdumpsub.cc b/tools/dcpdumpsub.cc index e0690ae5..fa7a170c 100644 --- a/tools/dcpdumpsub.cc +++ b/tools/dcpdumpsub.cc @@ -31,22 +31,26 @@ files in the program, then also delete it here. */ -#include "smpte_subtitle_asset.h" + #include "decrypted_kdm.h" #include "decrypted_kdm_key.h" #include "encrypted_kdm.h" +#include "file.h" +#include "smpte_subtitle_asset.h" #include "util.h" #include #include -#include #include +#include + -using std::string; -using std::cout; using std::cerr; +using std::cout; using std::map; +using std::string; using boost::optional; + static void help (string n) { @@ -129,15 +133,13 @@ main (int argc, char* argv[]) cout << sub.xml_as_string() << "\n"; if (extract_fonts) { - map fonts = sub.font_data (); - for (map::const_iterator i = fonts.begin(); i != fonts.end(); ++i) { - FILE* f = dcp::fopen_boost (i->first + ".ttf", "wb"); + for (auto const& i: sub.font_data()) { + dcp::File f(i.first + ".ttf", "wb"); if (!f) { - cerr << "Could not open font file " << i->first << ".ttf for writing"; + cerr << "Could not open font file " << i.first << ".ttf for writing"; exit (EXIT_FAILURE); } - fwrite (i->second.data(), 1, i->second.size(), f); - fclose (f); + f.write(i.second.data(), 1, i.second.size()); } } } -- cgit v1.2.3