Index: boost/filesystem/v3/operations.hpp =================================================================== --- boost/filesystem/v3/operations.hpp (revision 65864) +++ boost/filesystem/v3/operations.hpp (working copy) @@ -188,6 +188,8 @@ BOOST_FILESYSTEM_DECL path system_complete(const path& p, system::error_code* ec=0); BOOST_FILESYSTEM_DECL + path temp_dir_path(system::error_code* ec=0); + BOOST_FILESYSTEM_DECL path unique_path(const path& p, system::error_code* ec=0); } // namespace detail @@ -443,6 +445,12 @@ path system_complete(const path& p, system::error_code& ec) {return detail::system_complete(p, &ec);} inline + path temp_dir_path() {return detail::temp_dir_path();} + + inline + path temp_dir_path(system::error_code& ec) + {return detail::temp_dir_path(&ec);} + inline path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%") { return detail::unique_path(p); } inline @@ -982,6 +990,7 @@ using filesystem3::symlink_file; using filesystem3::symlink_status; using filesystem3::system_complete; + using filesystem3::temp_dir_path; using filesystem3::type_unknown; using filesystem3::unique_path; # ifndef BOOST_FILESYSTEM_NO_DEPRECATED Index: libs/filesystem/v3/test/operations_test.cpp =================================================================== --- libs/filesystem/v3/test/operations_test.cpp (revision 65864) +++ libs/filesystem/v3/test/operations_test.cpp (working copy) @@ -1269,6 +1269,41 @@ BOOST_TEST(!fs::equivalent(ng, file_ph)); } + // temp_dir_path_tests ---------------------------------------------------------// + + void temp_dir_path_tests() + { + std::cout << "temp_dir_path_tests..." << std::endl; + + BOOST_TEST(!fs::temp_dir_path().empty()); + BOOST_TEST(exists(fs::temp_dir_path())); + + fs::path ph = fs::temp_dir_path()/"temp_dir_path_test.txt"; + + { + if(exists(ph)) remove(ph); + + std::ofstream f(ph.BOOST_FILESYSTEM_C_STR); + + f << "passed"; + } + + BOOST_TEST(exists(ph)); + + { + std::ifstream f(ph.BOOST_FILESYSTEM_C_STR); + std::string s; + + f >> s; + + BOOST_TEST(s == "passed"); + } + + remove(ph); + + BOOST_TEST(!exists(ph)); + } + // _tests --------------------------------------------------------------------------// void _tests() @@ -1393,7 +1428,9 @@ if (create_symlink_ok) // only if symlinks supported remove_symlink_tests(); write_time_tests(dir); - + + temp_dir_path_tests(); + std::cout << "testing complete" << std::endl; // post-test cleanup Index: libs/filesystem/v3/doc/reference.html =================================================================== --- libs/filesystem/v3/doc/reference.html (revision 65864) +++ libs/filesystem/v3/doc/reference.html (working copy) @@ -114,6 +114,7 @@      status_known
     symlink_status
     system_complete
+     temp_dir_path
     unique_path File streams
@@ -437,6 +438,9 @@ path system_complete(const path& p); path system_complete(const path& p, system::error_code& ec); + path temp_dir_path(); + path temp_dir_path(system::error_code& ec); + path unique_path(const path& model="%%%%-%%%%-%%%%-%%%%"); path unique_path(const path& model, system::error_code& ec); @@ -2442,6 +2446,19 @@

See complete() note for usage suggestions. -- end note]

+
path temp_dir_path();
+path temp_dir_path(system::error_code& ec);
+
+

Returns: The temporary directory path as returned by the POSIX getenv("TMPDIR") environment variable, + or the Windows GetTempPath API function. is_directory() is true for the returned path. +

+

Throws: As specified in + Error reporting.

+

[Note: The temp_dir_path() name was chosen to emphasize that the return is a + path, not just a single directory name.

+

For POSIX systems the definition of the first existing environment variable from the list: TMPDIR, TMP, TEMP, TEMPDIR is used. +   -- end note]

+
path unique_path(const path& model="%%%%-%%%%-%%%%-%%%%");
 path unique_path(const path& model, system::error_code& ec);
Index: libs/filesystem/v3/src/operations.cpp =================================================================== --- libs/filesystem/v3/src/operations.cpp (revision 65864) +++ libs/filesystem/v3/src/operations.cpp (working copy) @@ -49,6 +49,7 @@ #include #include #include // for malloc, free +#include #ifdef BOOST_FILEYSTEM_INCLUDE_IOSTREAM # include @@ -1445,6 +1446,51 @@ } BOOST_FILESYSTEM_DECL + path temp_dir_path(system::error_code* ec) + { +# ifdef BOOST_POSIX_API + const char* val = 0; + + (val = std::getenv("TMPDIR" )) || + (val = std::getenv("TMP" )) || + (val = std::getenv("TEMP" )) || + (val = std::getenv("TEMPDIR")); + + if (error(val==0, + ec, "boost::filesystem::temp_dir_path")) + return path(); + + path p(val); + + if (error((ec && !is_directory(p, *ec)) || + (!ec && !is_directory(p)), + ec, "boost::filesystem::temp_dir_path")) + return path(); + + return p; + +# else // Windows + + std::vector buf(GetTempPathW(0, NULL)); + + if (error(buf.empty() || GetTempPathW(buf.size(), &buf[0])==0, + ec, "boost::filesystem::temp_dir_path")) + return path(); + + buf.pop_back(); + + path p(buf.begin(), buf.end()); + + if (error((ec && !is_directory(p, *ec)) || + (!ec && !is_directory(p)), + ec, "boost::filesystem::temp_dir_path")) + return path(); + + return p; +# endif + } + + BOOST_FILESYSTEM_DECL path system_complete(const path& p, system::error_code* ec) { # ifdef BOOST_POSIX_API