summaryrefslogtreecommitdiff
path: root/src/lib/scoped_temporary.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-04-16 22:20:54 +0200
committerCarl Hetherington <cth@carlh.net>2022-05-05 23:38:41 +0200
commit8a8c977c12fc65f1f50ea05099387e0fc8840e7d (patch)
tree2d2c8663652939d643779d1ab1c18a12813fcbd2 /src/lib/scoped_temporary.cc
parentefe153ab23b54cdbf28c653f2ccb0f25ca6bd015 (diff)
Use dcp::File in DCP-o-matic (#2231).
Diffstat (limited to 'src/lib/scoped_temporary.cc')
-rw-r--r--src/lib/scoped_temporary.cc34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/lib/scoped_temporary.cc b/src/lib/scoped_temporary.cc
index 223100ba5..0ead7b165 100644
--- a/src/lib/scoped_temporary.cc
+++ b/src/lib/scoped_temporary.cc
@@ -29,16 +29,18 @@
*/
ScopedTemporary::ScopedTemporary ()
{
- _file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path ();
+ _path = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
}
/** Close and delete the temporary file */
ScopedTemporary::~ScopedTemporary ()
{
- close ();
+ if (_file) {
+ _file->close();
+ }
boost::system::error_code ec;
- boost::filesystem::remove (_file, ec);
+ boost::filesystem::remove (_path, ec);
}
@@ -46,31 +48,23 @@ ScopedTemporary::~ScopedTemporary ()
char const *
ScopedTemporary::c_str () const
{
- return _file.string().c_str();
+ return _path.string().c_str();
}
/** Open the temporary file.
* @return File's FILE pointer.
*/
-FILE*
+dcp::File&
ScopedTemporary::open (char const * params)
{
- close ();
- _open = fopen_boost (_file, params);
- if (!_open) {
- throw FileError ("Could not open scoped temporary", _file);
+ if (_file) {
+ _file->close();
}
- return _open;
-}
-
-
-/** Close the file */
-void
-ScopedTemporary::close ()
-{
- if (_open) {
- fclose (_open);
- _open = nullptr;
+ _file = dcp::File(_path, params);
+ if (!*_file) {
+ throw FileError ("Could not open scoped temporary", _path);
}
+ return *_file;
}
+