diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp --- a/libcxx/src/filesystem/operations.cpp +++ b/libcxx/src/filesystem/operations.cpp @@ -1550,8 +1550,13 @@ 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 --- 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 @@ -136,8 +136,16 @@ std::error_code ec = GetTestEC(); path ret = temp_directory_path(ec); TEST_CHECK(!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); + TEST_CHECK(win_dir_sz > 0 && win_dir_sz < MAX_PATH); + TEST_CHECK(win_dir[win_dir_sz-1] != L'\\'); + TEST_CHECK(ret == win_dir); +#elif defined(__ANDROID__) + TEST_CHECK(ret == "/data/local/tmp"); +#else TEST_CHECK(ret == "/tmp"); #endif TEST_CHECK(is_directory(ret));