[libcxx-commits] [libcxx] 1da0680 - [libc++] Android temp dir is /data/local/tmp, enable Windows test
Ryan Prichard via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 12 20:43:57 PDT 2023
Author: Ryan Prichard
Date: 2023-06-12T20:43:00-07:00
New Revision: 1da06804e1a405e5399a1a19ae791a40f77dfbab
URL: https://github.com/llvm/llvm-project/commit/1da06804e1a405e5399a1a19ae791a40f77dfbab
DIFF: https://github.com/llvm/llvm-project/commit/1da06804e1a405e5399a1a19ae791a40f77dfbab.diff
LOG: [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
Added:
Modified:
libcxx/src/filesystem/operations.cpp
libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index fc14778f3f7a8..af31fe049b3e4 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
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
index 4bc4099b0d394..49a7f363210ce 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
@@ -133,8 +133,16 @@ static void basic_tests()
std::error_code ec = GetTestEC();
path ret = temp_directory_path(ec);
assert(!ec);
-#ifndef _WIN32
+#if defined(_WIN32)
// On Windows, the function falls back to the Windows folder.
+ wchar_t win_dir[MAX_PATH];
+ DWORD win_dir_sz = GetWindowsDirectoryW(win_dir, MAX_PATH);
+ assert(win_dir_sz > 0 && win_dir_sz < MAX_PATH);
+ assert(win_dir[win_dir_sz-1] != L'\\');
+ assert(ret == win_dir);
+#elif defined(__ANDROID__)
+ assert(ret == "/data/local/tmp");
+#else
assert(ret == "/tmp");
#endif
assert(is_directory(ret));
More information about the libcxx-commits
mailing list