[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
This commit is contained in:
Martin Storsjö 2020-10-18 23:19:29 +03:00
parent 81db3c31aa
commit 93671fffb5
2 changed files with 15 additions and 2 deletions

View File

@ -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)

View File

@ -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() {