1 /*===- InstrProfilingUtil.c - Support library for PGO instrumentation -----===*\ 2 |* 3 |* The LLVM Compiler Infrastructure 4 |* 5 |* This file is distributed under the University of Illinois Open Source 6 |* License. See LICENSE.TXT for details. 7 |* 8 \*===----------------------------------------------------------------------===*/ 9 10 #include "InstrProfilingUtil.h" 11 #include "InstrProfiling.h" 12 13 #ifdef _WIN32 14 #include <direct.h> 15 #else 16 #include <sys/stat.h> 17 #include <sys/types.h> 18 #endif 19 20 #ifdef COMPILER_RT_HAS_UNAME 21 #include <sys/utsname.h> 22 #endif 23 24 #include <string.h> 25 26 COMPILER_RT_VISIBILITY 27 void __llvm_profile_recursive_mkdir(char *path) { 28 int i; 29 30 for (i = 1; path[i] != '\0'; ++i) { 31 if (path[i] != '/') continue; 32 path[i] = '\0'; 33 #ifdef _WIN32 34 _mkdir(path); 35 #else 36 mkdir(path, 0755); /* Some of these will fail, ignore it. */ 37 #endif 38 path[i] = '/'; 39 } 40 } 41 42 #if COMPILER_RT_HAS_ATOMICS != 1 43 COMPILER_RT_VISIBILITY 44 uint32_t lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV) { 45 void *R = *Ptr; 46 if (R == OldV) { 47 *Ptr = NewV; 48 return 1; 49 } 50 return 0; 51 } 52 #endif 53 54 #ifdef COMPILER_RT_HAS_UNAME 55 int lprofGetHostName(char *Name, int Len) { 56 struct utsname N; 57 int R; 58 if (!(R = uname(&N))) 59 strncpy(Name, N.nodename, Len); 60 return R; 61 } 62 #endif 63 64 65