X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=40e9d9c2eed730795a8f8476533ae16290c403c0;hp=1339be73d1044cf58192454984dc5a3de2a9f2c7;hb=854f2e5bbb7ffb9758b823af87034033033f3cb8;hpb=1eeba876ce09cedfa4c779bf3554372c01dc34c5 diff --git a/src/lib/util.cc b/src/lib/util.cc index 1339be73d..40e9d9c2e 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington Copyright (C) 2000-2007 Paul Davis This program is free software; you can redistribute it and/or modify @@ -957,3 +957,38 @@ dependency_version_summary () return s.str (); } + +ScopedTemporary::ScopedTemporary () + : _open (0) +{ + _file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path (); +} + +ScopedTemporary::~ScopedTemporary () +{ + close (); + boost::system::error_code ec; + boost::filesystem::remove (_file, ec); +} + +char const * +ScopedTemporary::c_str () const +{ + return _file.string().c_str (); +} + +FILE* +ScopedTemporary::open (char const * params) +{ + _open = fopen (c_str(), params); + return _open; +} + +void +ScopedTemporary::close () +{ + if (_open) { + fclose (_open); + _open = 0; + } +}