summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-07-15 18:48:14 +0000
committerXinliang David Li <davidxl@google.com>2016-07-15 18:48:14 +0000
commit35348defd48a63d784ae35b95ddd7bad382d6bea (patch)
treee55f3693fec6691853ff57e369b706f141fbc50e
parentaff36bd0df3a81e114f3e2d3a6c0b6d6225ebc1f (diff)
downloadcompiler-rt-35348defd48a63d784ae35b95ddd7bad382d6bea.tar.gz
[Profile] instroduce portability macro for dir separator(s
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275597 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/profile/GCDAProfiling.c8
-rw-r--r--lib/profile/InstrProfilingFile.c6
-rw-r--r--lib/profile/InstrProfilingPort.h14
3 files changed, 24 insertions, 4 deletions
diff --git a/lib/profile/GCDAProfiling.c b/lib/profile/GCDAProfiling.c
index 1079f2424..51a40c5b6 100644
--- a/lib/profile/GCDAProfiling.c
+++ b/lib/profile/GCDAProfiling.c
@@ -21,6 +21,7 @@
\*===----------------------------------------------------------------------===*/
#include "InstrProfilingUtil.h"
+#include "InstrProfilingPort.h"
#include <errno.h>
#include <fcntl.h>
@@ -194,7 +195,8 @@ static char *mangle_filename(const char *orig_filename) {
for (level = 0, ptr = fname + 1; level < prefix_strip; ++ptr) {
if (*ptr == '\0')
break;
- if (*ptr != '/')
+
+ if (!IS_DIR_SEPARATOR(*ptr))
continue;
fname = ptr;
++level;
@@ -205,8 +207,8 @@ static char *mangle_filename(const char *orig_filename) {
new_filename = malloc(prefix_len + 1 + filename_len + 1);
memcpy(new_filename, prefix, prefix_len);
- if (prefix[prefix_len - 1] != '/')
- new_filename[prefix_len++] = '/';
+ if (!IS_DIR_SEPARATOR(prefix[prefix_len - 1]))
+ new_filename[prefix_len++] = DIR_SEPARATOR;
memcpy(new_filename + prefix_len, fname, filename_len + 1);
return new_filename;
diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c
index 1bd6c6339..b737baff4 100644
--- a/lib/profile/InstrProfilingFile.c
+++ b/lib/profile/InstrProfilingFile.c
@@ -229,7 +229,11 @@ static void truncateCurrentFile(void) {
return;
/* Create the directory holding the file, if needed. */
- if (strchr(Filename, '/') || strchr(Filename, '\\')) {
+ if (strchr(Filename, DIR_SEPARATOR)
+#if defined(DIR_SEPARATOR_2)
+ || strchr(Filename, DIR_SEPERATOR_2)
+#endif
+ ) {
char *Copy = (char *)COMPILER_RT_ALLOCA(Length + 1);
strncpy(Copy, Filename, Length + 1);
__llvm_profile_recursive_mkdir(Copy);
diff --git a/lib/profile/InstrProfilingPort.h b/lib/profile/InstrProfilingPort.h
index 4fd8aca4a..c947153e2 100644
--- a/lib/profile/InstrProfilingPort.h
+++ b/lib/profile/InstrProfilingPort.h
@@ -84,6 +84,20 @@
(DomType *)lprofPtrFetchAdd((void **)&PtrVar, sizeof(DomType) * PtrIncr)
#endif
+#if defined(_WIN32)
+#define DIR_SEPARATOR '\\'
+#define DIR_SEPARATOR_2 '/'
+#else
+#define DIR_SEPARATOR '/'
+#endif
+
+#ifndef DIR_SEPARATOR_2
+#define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+#define IS_DIR_SEPARATOR(ch) \
+ (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
#define PROF_ERR(Format, ...) \
fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);