diff options
Diffstat (limited to 'src/lib/film.cc')
| -rw-r--r-- | src/lib/film.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc index aa16fdad8..cc60ab303 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1685,3 +1685,37 @@ Film::closed_caption_tracks () const return tt; } + +shared_ptr<InfoFileHandle> +Film::info_file_handle (DCPTimePeriod period, bool read) const +{ + return shared_ptr<InfoFileHandle> (new InfoFileHandle(_info_file_mutex, info_file(period), read)); +} + +InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read) + : _lock (mutex) + , _file (file) +{ + if (read) { + _handle = fopen_boost (file, "rb"); + if (!_handle) { + throw OpenFileError (file, errno, OpenFileError::READ); + } + } else { + bool const exists = boost::filesystem::exists (file); + if (exists) { + _handle = fopen_boost (file, "r+b"); + } else { + _handle = fopen_boost (file, "wb"); + } + + if (!_handle) { + throw OpenFileError (file, errno, exists ? OpenFileError::READ_WRITE : OpenFileError::WRITE); + } + } +} + +InfoFileHandle::~InfoFileHandle () +{ + fclose (_handle); +} |
