From 93671fffb5ef37060da54199cb9e009188f63a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sun, 18 Oct 2020 23:19:29 +0300 Subject: [PATCH] [libcxx] [test] Use _putenv instead of setenv/unsetenv on windows Move the functions to the helper header and keep the arch specific logic there. Differential Revision: https://reviews.llvm.org/D89681 --- .../temp_directory_path.pass.cpp | 4 ++-- libcxx/test/support/filesystem_test_helper.h | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) 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 d9d25c8df138..a0b30e17128d 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 @@ -26,11 +26,11 @@ using namespace fs; void PutEnv(std::string var, fs::path value) { - assert(::setenv(var.c_str(), value.string().c_str(), /* overwrite */ 1) == 0); + assert(utils::setenv(var.c_str(), value.string().c_str(), /* overwrite */ 1) == 0); } void UnsetEnv(std::string var) { - assert(::unsetenv(var.c_str()) == 0); + assert(utils::unsetenv(var.c_str()) == 0); } TEST_SUITE(filesystem_temp_directory_path_test_suite) diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h index 37f0d6bcd367..704e2b26a0b4 100644 --- a/libcxx/test/support/filesystem_test_helper.h +++ b/libcxx/test/support/filesystem_test_helper.h @@ -45,11 +45,24 @@ namespace utils { inline int link(const char *oldname, const char* newname) { return !CreateHardLinkA(newname, oldname, NULL); } + inline int setenv(const char *var, const char *val, int overwrite) { + (void)overwrite; + return ::_putenv((std::string(var) + "=" + std::string(val)).c_str()); + } + inline int unsetenv(const char *var) { + return ::_putenv((std::string(var) + "=").c_str()); + } #else using ::mkdir; using ::ftruncate; inline int symlink(const char* oldname, const char* newname, bool is_dir) { (void)is_dir; return ::symlink(oldname, newname); } using ::link; + inline int setenv(const char *var, const char *val, int overwrite) { + return ::setenv(var, val, overwrite); + } + inline int unsetenv(const char *var) { + return ::unsetenv(var); + } #endif inline std::string getcwd() {