/* Define if readlink is available in <unistd.h>. */
#undef HAVE_READLINK
+/* Define to 1 if you have the `secure_getenv' function. */
+#undef HAVE_SECURE_GETENV
+
/* Define to 1 if you have the `setenv' function. */
#undef HAVE_SETENV
#define HAVE__WFOPEN 1
_ACEOF
+fi
+done
+
+ for ac_func in secure_getenv
+do :
+ ac_fn_c_check_func "$LINENO" "secure_getenv" "ac_cv_func_secure_getenv"
+if test "x$ac_cv_func_secure_getenv" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_SECURE_GETENV 1
+_ACEOF
+
fi
done
AC_CHECK_FUNCS(__cxa_thread_atexit_impl __cxa_thread_atexit)
AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)
AC_CHECK_FUNCS(_wfopen)
+ AC_CHECK_FUNCS(secure_getenv)
# C11 functions for C++17 library
AC_CHECK_FUNCS(timespec_get)
return result;
}
-fs::path fs::temp_directory_path()
+fs::path
+fs::temp_directory_path()
{
error_code ec;
path tmp = temp_directory_path(ec);
return tmp;
}
-fs::path fs::temp_directory_path(error_code& ec)
+fs::path
+fs::temp_directory_path(error_code& ec)
{
- path p;
-#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
- unsigned len = 1024;
- std::wstring buf;
- do
- {
- buf.resize(len);
- len = GetTempPathW(buf.size(), buf.data());
- } while (len > buf.size());
-
- if (len == 0)
- {
- ec.assign((int)GetLastError(), std::system_category());
- return p;
- }
- buf.resize(len);
- p = std::move(buf);
-#else
- const char* tmpdir = nullptr;
- const char* env[] = { "TMPDIR", "TMP", "TEMP", "TEMPDIR", nullptr };
- for (auto e = env; tmpdir == nullptr && *e != nullptr; ++e)
- tmpdir = ::getenv(*e);
- p = tmpdir ? tmpdir : "/tmp";
-#endif
+ path p = fs::get_temp_directory_from_env();
auto st = status(p, ec);
if (ec)
p.clear();
#endif // _GLIBCXX_HAVE_SYS_STAT_H
+ // Find OS-specific name of temporary directory from the environment,
+ // Caller must check that the path is an accessible directory.
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+ inline wstring
+ get_temp_directory_from_env()
+ {
+ unsigned len = 1024;
+ std::wstring buf;
+ do
+ {
+ buf.resize(len);
+ len = GetTempPathW(buf.size(), buf.data());
+ } while (len > buf.size());
+
+ if (len == 0)
+ {
+ ec.assign((int)GetLastError(), std::system_category());
+ return p;
+ }
+ buf.resize(len);
+ return buf;
+ }
+#else
+ inline const char*
+ get_temp_directory_from_env() noexcept
+ {
+ for (auto env : { "TMPDIR", "TMP", "TEMP", "TEMPDIR" })
+ {
+#if _GLIBCXX_HAVE_SECURE_GETENV
+ auto tmpdir = ::secure_getenv(env);
+#else
+ auto tmpdir = ::getenv(env);
+#endif
+ if (tmpdir)
+ return tmpdir;
+ }
+ return "/tmp";
+ }
+#endif
+
_GLIBCXX_END_NAMESPACE_FILESYSTEM
_GLIBCXX_END_NAMESPACE_VERSION
#endif
}
-fs::path fs::temp_directory_path()
+fs::path
+fs::temp_directory_path()
{
error_code ec;
path tmp = temp_directory_path(ec);
return tmp;
}
-fs::path fs::temp_directory_path(error_code& ec)
+fs::path
+fs::temp_directory_path(error_code& ec)
{
- path p;
-#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
- unsigned len = 1024;
- std::wstring buf;
- do
- {
- buf.resize(len);
- len = GetTempPathW(buf.size(), buf.data());
- } while (len > buf.size());
-
- if (len == 0)
- {
- ec.assign((int)GetLastError(), std::system_category());
- return p;
- }
- buf.resize(len);
- p = std::move(buf);
-#else
- const char* tmpdir = nullptr;
- const char* env[] = { "TMPDIR", "TMP", "TEMP", "TEMPDIR", nullptr };
- for (auto e = env; tmpdir == nullptr && *e != nullptr; ++e)
- tmpdir = ::getenv(*e);
- p = tmpdir ? tmpdir : "/tmp";
+ path p = fs::get_temp_directory_from_env();
auto st = status(p, ec);
if (ec)
p.clear();
p.clear();
ec = std::make_error_code(std::errc::not_a_directory);
}
-#endif
return p;
}
-
#include <filesystem>
#include <stdlib.h>
+#include <stdio.h>
#include <testsuite_hooks.h>
#include <testsuite_fs.h>
clean_env();
if (!fs::exists("/tmp"))
+ {
+ puts("/tmp doesn't exist, not testing it for temp_directory_path");
return; // just give up
+ }
std::error_code ec = make_error_code(std::errc::invalid_argument);
fs::path p1 = fs::temp_directory_path(ec);
clean_env();
if (!set_env("TMP", __gnu_test::nonexistent_path().string()))
+ {
+ puts("Cannot set environment variables, not testing temp_directory_path");
return; // just give up
+ }
std::error_code ec;
fs::path p = fs::temp_directory_path(ec);
#include <experimental/filesystem>
#include <stdlib.h>
+#include <stdio.h>
#include <testsuite_hooks.h>
#include <testsuite_fs.h>
clean_env();
if (!fs::exists("/tmp"))
+ {
+ puts("/tmp doesn't exist, not testing it for temp_directory_path");
return; // just give up
+ }
std::error_code ec = make_error_code(std::errc::invalid_argument);
fs::path p1 = fs::temp_directory_path(ec);
{
clean_env();
- if (set_env("TMPDIR", __gnu_test::nonexistent_path().string()))
+ if (!set_env("TMP", __gnu_test::nonexistent_path().string()))
+ {
+ puts("Cannot set environment variables, not testing temp_directory_path");
return; // just give up
+ }
std::error_code ec;
fs::path p = fs::temp_directory_path(ec);