[compiler-rt] r180098 - Revert r180082 and add a test for SetEnv function
Alexey Samsonov
samsonov at google.com
Tue Apr 23 05:49:12 PDT 2013
Author: samsonov
Date: Tue Apr 23 07:49:12 2013
New Revision: 180098
URL: http://llvm.org/viewvc/llvm-project?rev=180098&view=rev
Log:
Revert r180082 and add a test for SetEnv function
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=180098&r1=180097&r2=180098&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Apr 23 07:49:12 2013
@@ -130,6 +130,7 @@ void DisableCoreDumper();
void DumpProcessMap();
bool FileExists(const char *filename);
const char *GetEnv(const char *name);
+bool SetEnv(const char *name, const char *value);
const char *GetPwd();
u32 GetUid();
void ReExec();
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=180098&r1=180097&r2=180098&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Tue Apr 23 07:49:12 2013
@@ -264,6 +264,20 @@ const char *GetEnv(const char *name) {
return 0; // Not found.
}
+// Does not compile for Go because dlsym() requires -ldl
+#ifndef SANITIZER_GO
+bool SetEnv(const char *name, const char *value) {
+ void *f = dlsym(RTLD_NEXT, "setenv");
+ if (f == 0)
+ return false;
+ typedef int(*setenv_ft)(const char *name, const char *value, int overwrite);
+ setenv_ft setenv_f;
+ CHECK_EQ(sizeof(setenv_f), sizeof(f));
+ internal_memcpy(&setenv_f, &f, sizeof(f));
+ return setenv_f(name, value, 1) == 0;
+}
+#endif
+
#ifdef __GLIBC__
extern "C" {
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc?rev=180098&r1=180097&r2=180098&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc Tue Apr 23 07:49:12 2013
@@ -20,6 +20,7 @@
#include <pthread.h>
#include <sched.h>
+#include <stdlib.h>
#include <algorithm>
#include <vector>
@@ -185,6 +186,14 @@ TEST_F(ThreadListerTest, ResetMakesNewTh
ASSERT_TRUE(HasElement(threads_after_extra, extra_tid));
}
+TEST(SanitizerCommon, SetEnvTest) {
+ const char kEnvName[] = "ENV_FOO";
+ SetEnv(kEnvName, "value");
+ EXPECT_STREQ("value", getenv(kEnvName));
+ unsetenv(kEnvName);
+ EXPECT_EQ(0, getenv(kEnvName));
+}
+
} // namespace __sanitizer
#endif // __linux__
More information about the llvm-commits
mailing list