diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-03-25 15:24:13 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-03-25 15:24:13 +0000 |
| commit | 0a62857e4412d294712cfdf227fa38ae9ef371fe (patch) | |
| tree | a5e32cdc0fc69acf6b36ef84fb6a3f525f03ac14 /src/lib | |
| parent | 68215e4e2dc313b74da7bde187917add138d3c9f (diff) | |
Add support for downloading Doremi server certificates.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/util.cc | 35 | ||||
| -rw-r--r-- | src/lib/util.h | 18 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc index 85c52b039..7a19790eb 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1030,3 +1030,38 @@ divide_with_round (int64_t a, int64_t b) return a / b; } } + +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; + } +} diff --git a/src/lib/util.h b/src/lib/util.h index c05680859..0bbab8305 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -176,6 +176,24 @@ private: char* _old; }; +class ScopedTemporary +{ +public: + ScopedTemporary (); + ~ScopedTemporary (); + + boost::filesystem::path file () const { + return _file; + } + + char const * c_str () const; + FILE* open (char const *); + void close (); + +private: + boost::filesystem::path _file; + FILE* _open; +}; #endif |
