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 char save = path[i]; 32 if (!(path[i] == '/' || path[i] == '\\')) 33 continue; 34 path[i] = '\0'; 35 #ifdef _WIN32 36 _mkdir(path); 37 #else 38 mkdir(path, 0755); /* Some of these will fail, ignore it. */ 39 #endif 40 path[i] = save; 41 } 42 } 43 44 #if COMPILER_RT_HAS_ATOMICS != 1 45 COMPILER_RT_VISIBILITY 46 uint32_t lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV) { 47 void *R = *Ptr; 48 if (R == OldV) { 49 *Ptr = NewV; 50 return 1; 51 } 52 return 0; 53 } 54 #endif 55 56 #ifdef COMPILER_RT_HAS_UNAME 57 int lprofGetHostName(char *Name, int Len) { 58 struct utsname N; 59 int R; 60 if (!(R = uname(&N))) 61 strncpy(Name, N.nodename, Len); 62 return R; 63 } 64 #endif 65 66 67