contributed by Jeff Flinn
| 4745 | |
| 4746 | // contributed by Jeff Flinn |
| 4747 | BOOST_FILESYSTEM_DECL |
| 4748 | path temp_directory_path(system::error_code* ec) |
| 4749 | { |
| 4750 | if (ec) |
| 4751 | ec->clear(); |
| 4752 | |
| 4753 | #ifdef BOOST_FILESYSTEM_POSIX_API |
| 4754 | |
| 4755 | const char* val = nullptr; |
| 4756 | |
| 4757 | (val = std::getenv("TMPDIR")) || |
| 4758 | (val = std::getenv("TMP")) || |
| 4759 | (val = std::getenv("TEMP")) || |
| 4760 | (val = std::getenv("TEMPDIR")); |
| 4761 | |
| 4762 | #ifdef __ANDROID__ |
| 4763 | const char* default_tmp = "/data/local/tmp"; |
| 4764 | #else |
| 4765 | const char* default_tmp = "/tmp"; |
| 4766 | #endif |
| 4767 | path p((val != nullptr) ? val : default_tmp); |
| 4768 | |
| 4769 | if (BOOST_UNLIKELY(p.empty())) |
| 4770 | { |
| 4771 | fail_not_dir: |
| 4772 | error(ENOTDIR, p, ec, "boost::filesystem::temp_directory_path"); |
| 4773 | return p; |
| 4774 | } |
| 4775 | |
| 4776 | file_status status = detail::status_impl(p, ec); |
| 4777 | if (BOOST_UNLIKELY(ec && *ec)) |
| 4778 | return path(); |
| 4779 | if (BOOST_UNLIKELY(!is_directory(status))) |
| 4780 | goto fail_not_dir; |
| 4781 | |
| 4782 | return p; |
| 4783 | |
| 4784 | #else // Windows |
| 4785 | |
| 4786 | static const wchar_t* const env_list[] = { L"TMP", L"TEMP", L"LOCALAPPDATA", L"USERPROFILE" }; |
| 4787 | static const wchar_t temp_dir[] = L"Temp"; |
| 4788 | |
| 4789 | path p; |
| 4790 | for (unsigned int i = 0; i < sizeof(env_list) / sizeof(*env_list); ++i) |
| 4791 | { |
| 4792 | std::wstring env = wgetenv(env_list[i]); |
| 4793 | if (!env.empty()) |
| 4794 | { |
| 4795 | p = env; |
| 4796 | if (i >= 2) |
| 4797 | path_algorithms::append_v4(p, temp_dir, temp_dir + (sizeof(temp_dir) / sizeof(*temp_dir) - 1u)); |
| 4798 | error_code lcl_ec; |
| 4799 | if (exists(p, lcl_ec) && !lcl_ec && is_directory(p, lcl_ec) && !lcl_ec) |
| 4800 | break; |
| 4801 | p.clear(); |
| 4802 | } |
| 4803 | } |
| 4804 |