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/util.cc | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'src/util.cc') diff --git a/src/util.cc b/src/util.cc index ed3fb772..6ae69387 100644 --- a/src/util.cc +++ b/src/util.cc @@ -41,6 +41,7 @@ #include "compose.hpp" #include "dcp_assert.h" #include "exceptions.h" +#include "file.h" #include "language_tag.h" #include "openjpeg_image.h" #include "rating.h" @@ -228,19 +229,6 @@ dcp::base64_decode (string const & in, unsigned char* out, int out_length) } -FILE * -dcp::fopen_boost (boost::filesystem::path p, string t) -{ -#ifdef LIBDCP_WINDOWS - wstring w (t.begin(), t.end()); - /* c_str() here should give a UTF-16 string */ - return _wfopen (p.c_str(), w.c_str ()); -#else - return fopen (p.c_str(), t.c_str ()); -#endif -} - - optional dcp::relative_to_root (boost::filesystem::path root, boost::filesystem::path file) { @@ -284,15 +272,14 @@ dcp::file_to_string (boost::filesystem::path p, uintmax_t max_length) throw MiscError (String::compose("Unexpectedly long file (%1)", p.string())); } - auto f = fopen_boost (p, "r"); + File f(p, "r"); if (!f) { throw FileError ("could not open file", p, errno); } char* c = new char[len]; /* This may read less than `len' if we are on Windows and we have CRLF in the file */ - int const N = fread (c, 1, len, f); - fclose (f); + int const N = f.read(c, 1, len); string s (c, N); delete[] c; -- cgit v1.2.3