summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfilingUtil.c
diff options
context:
space:
mode:
authorBob Haarman <llvm@inglorion.net>2016-11-29 15:24:00 +0000
committerBob Haarman <llvm@inglorion.net>2016-11-29 15:24:00 +0000
commit835a29632377870f0d7863f0101e1be441327476 (patch)
tree03a3a1bd1ca1808303dfb31c732e11f0ecea1c71 /lib/profile/InstrProfilingUtil.c
parente575309787fb237fa6accae95c46f4d6c67ca772 (diff)
[profile] use GetComputerNameExW instead of gethostname on Windows
Summary: In profile data paths, we replace "%h" with the hostname of the machine the program is running on. On Windows, we used gethostname() to obtain the hostname. This requires linking with ws2_32. With this change, we instead get the hostname from GetComputerNameExW(), which does not require ws2_32. Reviewers: rnk, vsk, amccarth Subscribers: zturner, ruiu, hans Differential Revision: https://reviews.llvm.org/D27178 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@288146 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingUtil.c')
-rw-r--r--lib/profile/InstrProfilingUtil.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/profile/InstrProfilingUtil.c b/lib/profile/InstrProfilingUtil.c
index ead537df9..321c7192c 100644
--- a/lib/profile/InstrProfilingUtil.c
+++ b/lib/profile/InstrProfilingUtil.c
@@ -66,7 +66,19 @@ void *lprofPtrFetchAdd(void **Mem, long ByteIncr) {
#endif
-#ifdef COMPILER_RT_HAS_UNAME
+#ifdef _MSC_VER
+COMPILER_RT_VISIBILITY int lprofGetHostName(char *Name, int Len) {
+ WCHAR Buffer[COMPILER_RT_MAX_HOSTLEN];
+ DWORD BufferSize = sizeof(Buffer);
+ BOOL Result =
+ GetComputerNameExW(ComputerNameDnsFullyQualified, Buffer, &BufferSize);
+ if (!Result)
+ return -1;
+ if (WideCharToMultiByte(CP_UTF8, 0, Buffer, -1, Name, Len, NULL, NULL) == 0)
+ return -1;
+ return 0;
+}
+#elif defined(COMPILER_RT_HAS_UNAME)
COMPILER_RT_VISIBILITY int lprofGetHostName(char *Name, int Len) {
struct utsname N;
int R;