From 1da06804e1a405e5399a1a19ae791a40f77dfbab Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Mon, 12 Jun 2023 20:43:00 -0700 Subject: [libc++] Android temp dir is /data/local/tmp, enable Windows test [libc++] Android temp dir is /data/local/tmp, enable Windows test On Android, std::filesystem::temp_directory_path() should fall back to /data/local/tmp when no environment variable is set. There is no /tmp directory. Most apps can't access /data/local/tmp, but they do have a "cache dir" (Context#getCacheDir()) that is usable for temporary files. However, there is no obvious and reliable way for libc++ to query this directory in contexts where it is available. The global fallback /data/local/tmp is available for "adb shell", making it useful for test suites. On Windows, temp_directory_path falls back to the Windows directory (e.g. "C:\Windows"), so call GetWindowsDirectoryW to do the test. Reviewed By: ldionne, #libc, enh Differential Revision: https://reviews.llvm.org/D137131 --- libcxx/src/filesystem/operations.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'libcxx/src/filesystem/operations.cpp') diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp index fc14778..af31fe0 100644 --- a/libcxx/src/filesystem/operations.cpp +++ b/libcxx/src/filesystem/operations.cpp @@ -1550,8 +1550,13 @@ path __temp_directory_path(error_code* ec) { for (auto& ep : env_paths) if ((ret = getenv(ep))) break; - if (ret == nullptr) + if (ret == nullptr) { +#if defined(__ANDROID__) + ret = "/data/local/tmp"; +#else ret = "/tmp"; +#endif + } path p(ret); #endif -- cgit v1.1