diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-04-01 22:51:54 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-04-01 22:51:54 +0100 |
| commit | 854f2e5bbb7ffb9758b823af87034033033f3cb8 (patch) | |
| tree | 54e5fe000e5f961ca65e2c2aba81749d9601226d /src/lib/util.cc | |
| parent | 1eeba876ce09cedfa4c779bf3554372c01dc34c5 (diff) | |
| parent | 931fa4ef2dbfb7c9f726c4dd41eea79621b49906 (diff) | |
Merge master.
Diffstat (limited to 'src/lib/util.cc')
| -rw-r--r-- | src/lib/util.cc | 37 |
1 files changed, 36 insertions, 1 deletions
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 <cth@carlh.net> + Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net> 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; + } +} |
