[PATCH] Fix getting environment variables for sanitizers needs on FreeBSD
Viktor Kutuzov
vkutuzov at accesssoftek.com
Fri Jun 20 06:33:29 PDT 2014
Hi kcc, samsonov,
http://reviews.llvm.org/D4229
Files:
lib/sanitizer_common/sanitizer_linux.cc
Index: lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -56,6 +56,7 @@
// FreeBSD 9.2 and 10.0.
#include <sys/umtx.h>
}
+extern char **environ;
#endif // SANITIZER_FREEBSD
#if !SANITIZER_ANDROID
@@ -315,9 +316,17 @@
return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}
-// Like getenv, but reads env directly from /proc and does not use libc.
-// This function should be called first inside __asan_init.
+// Like getenv, but reads env directly from /proc (on Linux) or parses the
+// 'environ' array (on FreeBSD) and does not use libc. This function should be
+// called first inside __asan_init.
const char *GetEnv(const char *name) {
+#if SANITIZER_FREEBSD
+ uptr NameLen = internal_strlen(name);
+ for (char **Env = ::environ; *Env != NULL; Env++) {
+ if (internal_strncmp(*Env, name, NameLen) == 0 && (*Env)[NameLen] == '=')
+ return (*Env) + NameLen + 1;
+ }
+#else
static char *environ;
static uptr len;
static bool inited;
@@ -340,6 +349,7 @@
return p + namelen + 1; // point after =
p = endp + 1;
}
+#endif
return 0; // Not found.
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4229.10693.patch
Type: text/x-patch
Size: 1258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140620/2b590d91/attachment.bin>
More information about the llvm-commits
mailing list