diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-04-12 22:34:04 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-04-20 20:04:21 +0200 |
| commit | 05bfa3d1fe9e274ed195647c6f74cb272f00c23d (patch) | |
| tree | 1372760463b288ff4e10ef7fb6e7414e202829f5 /src/util.cc | |
| parent | 0338e7a7c19617f9ebb64ee02fbf3cceab8cf03f (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/util.cc')
| -rw-r--r-- | src/util.cc | 19 |
1 files changed, 3 insertions, 16 deletions
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<boost::filesystem::path> 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; |
