MCPcopy Create free account
hub / github.com/boostorg/filesystem / temp_directory_path

Function temp_directory_path

src/operations.cpp:4747–4828  ·  view source on GitHub ↗

contributed by Jeff Flinn

Source from the content-addressed store, hash-verified

4745
4746// contributed by Jeff Flinn
4747BOOST_FILESYSTEM_DECL
4748path 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

Callers 2

mainFunction · 0.50

Calls 9

errorFunction · 0.85
status_implFunction · 0.85
wgetenvFunction · 0.85
clearMethod · 0.80
getMethod · 0.80
pathFunction · 0.50
is_directoryFunction · 0.50
existsFunction · 0.50
emptyMethod · 0.45

Tested by 1