[libcxx-commits] [PATCH] D89681: [libcxx] [test] Use _putenv instead of setenv on windows

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 19 05:53:52 PDT 2020


mstorsjo updated this revision to Diff 299026.
mstorsjo added a comment.

Moved to the helper header, so this then goes on top of D89530 <https://reviews.llvm.org/D89530>.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89681/new/

https://reviews.llvm.org/D89681

Files:
  libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
  libcxx/test/support/filesystem_test_helper.h


Index: libcxx/test/support/filesystem_test_helper.h
===================================================================
--- libcxx/test/support/filesystem_test_helper.h
+++ libcxx/test/support/filesystem_test_helper.h
@@ -55,6 +55,13 @@
     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
     inline int mkdir(const char* path, int mode) { return ::mkdir(path, mode); }
     inline int ftruncate(int fd, off_t length) { return ::ftruncate(fd, length); }
@@ -71,6 +78,12 @@
         assert(ret && "getcwd failed");
         return std::string(ret);
     }
+    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 bool exists(std::string const& path) {
Index: libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp
+++ 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89681.299026.patch
Type: text/x-patch
Size: 2056 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201019/fcf85ddf/attachment.bin>


More information about the libcxx-commits mailing list