forked from OSchip/llvm-project
[Profile] instroduce portability macro for dir separator(s
llvm-svn: 275597
This commit is contained in:
parent
2b353a9522
commit
aeff1518e0
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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__);
|
||||
|
||||
|
|
Loading…
Reference in New Issue