From d20431e11290320f04d62e26b9a7cbcefaf5480c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 27 Apr 2016 19:05:23 +0200 Subject: Add temp_directory(), temp_path() --- butl/path | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'butl/path') diff --git a/butl/path b/butl/path index 07b05ca..df76f99 100644 --- a/butl/path +++ b/butl/path @@ -159,6 +159,20 @@ namespace butl static void current (string_type const&); + // Return the temporary directory. Throw std::system_error to report the + // underlying OS errors. + // + static string_type + temp_directory (); + + // Return a temporary name. The name is constructed by starting with the + // prefix followed by the process id following by a unique counter value + // inside the process. Throw std::system_error to report the underlying OS + // errors. + // + static string_type + temp_name (string_type const& prefix); + // Make the path real (by calling realpath(3)). Throw invalid_basic_path // if the path is invalid (e.g., some components do not exist) and // std::system_error to report other underlying OS errors. @@ -302,6 +316,24 @@ namespace butl static void current (basic_path const&); + // Return the temporary directory. Throw std::system_error to report the + // underlying OS errors. + // + static dir_type + temp_directory () {return dir_type (traits::temp_directory ());} + + // Return a temporary path. The path is constructed by starting with the + // temporary directory and then appending a path component consisting of + // the prefix followed by the process id following by a unique counter + // value inside the process. Throw std::system_error to report the + // underlying OS errors. + // + static basic_path + temp_path (const string_type& prefix) + { + return temp_directory () / basic_path (traits::temp_name (prefix)); + } + public: bool empty () const -- cgit v1.1