Skip to content

Commit 93671ff

Browse files
committed
[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
1 parent 81db3c3 commit 93671ff

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
using namespace fs;
2727

2828
void PutEnv(std::string var, fs::path value) {
29-
assert(::setenv(var.c_str(), value.string().c_str(), /* overwrite */ 1) == 0);
29+
assert(utils::setenv(var.c_str(), value.string().c_str(), /* overwrite */ 1) == 0);
3030
}
3131

3232
void UnsetEnv(std::string var) {
33-
assert(::unsetenv(var.c_str()) == 0);
33+
assert(utils::unsetenv(var.c_str()) == 0);
3434
}
3535

3636
TEST_SUITE(filesystem_temp_directory_path_test_suite)

libcxx/test/support/filesystem_test_helper.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,24 @@ namespace utils {
4545
inline int link(const char *oldname, const char* newname) {
4646
return !CreateHardLinkA(newname, oldname, NULL);
4747
}
48+
inline int setenv(const char *var, const char *val, int overwrite) {
49+
(void)overwrite;
50+
return ::_putenv((std::string(var) + "=" + std::string(val)).c_str());
51+
}
52+
inline int unsetenv(const char *var) {
53+
return ::_putenv((std::string(var) + "=").c_str());
54+
}
4855
#else
4956
using ::mkdir;
5057
using ::ftruncate;
5158
inline int symlink(const char* oldname, const char* newname, bool is_dir) { (void)is_dir; return ::symlink(oldname, newname); }
5259
using ::link;
60+
inline int setenv(const char *var, const char *val, int overwrite) {
61+
return ::setenv(var, val, overwrite);
62+
}
63+
inline int unsetenv(const char *var) {
64+
return ::unsetenv(var);
65+
}
5366
#endif
5467

5568
inline std::string getcwd() {

0 commit comments

Comments
 (0)