| diff -Naur ccache-3.4.2.orig/src/ccache.c ccache-3.4.2/src/ccache.c |
| --- ccache-3.4.2.orig/src/ccache.c 2018-08-16 17:13:29.359895100 -0400 |
| +++ ccache-3.4.2/src/ccache.c 2018-08-16 17:15:51.861247500 -0400 |
| @@ -855,6 +855,13 @@ |
| } |
| // p and q span the include file path. |
| char *inc_path = x_strndup(p, q - p); |
| +#ifdef _WIN32 |
| + // gcc-E [file.c] -g adds CWD with double forward slashes |
| + // like: |
| + // # 1 "C:\\msys64\\home\\user\\test//" |
| + // double forward slashes should be replaced with simple slashes |
| + str_replace(inc_path, "\\\\", "\\"); |
| +#endif |
| if (!has_absolute_include_headers) { |
| has_absolute_include_headers = is_absolute_path(inc_path); |
| } |
| diff -Naur ccache-3.7.orig/src/ccache.h ccache-3.7/src/ccache.h |
| --- ccache-3.7.orig/src/ccache.h 2019-04-23 21:37:37.438109100 -0400 |
| +++ ccache-3.7/src/ccache.h 2019-04-23 21:38:16.908721300 -0400 |
| @@ -213,6 +213,7 @@ |
| char *read_text_file(const char *path, size_t size_hint); |
| char *subst_env_in_string(const char *str, char **errmsg); |
| void set_cloexec_flag(int fd); |
| +void str_replace(char *target, const char *needle, const char *replacement); |
| double time_seconds(void); |
| |
| // ---------------------------------------------------------------------------- |
| diff -Naur ccache-3.4.2.orig/src/util.c ccache-3.4.2/src/util.c |
| --- ccache-3.4.2.orig/src/util.c 2018-08-16 17:13:29.344270000 -0400 |
| +++ ccache-3.4.2/src/util.c 2018-08-16 17:19:32.688548500 -0400 |
| @@ -1097,6 +1097,13 @@ |
| } else { |
| snprintf(ret, maxlen, "%s", path); |
| p = ret; |
| + |
| + //replace forward slashes with backward slashes inplace |
| + char *tmp; |
| + for(tmp = p; *tmp; tmp++) { |
| + if(*tmp == '/') |
| + *tmp = '\\'; |
| + } |
| } |
| #else |
| // Yes, there are such systems. This replacement relies on the fact that when |
| @@ -1286,11 +1293,17 @@ |
| const char *p1 = s1; |
| const char *p2 = s2; |
| |
| +#ifndef _WIN32 |
| + char dirseparator = '/'; |
| +#else |
| + char dirseparator = '\\'; |
| +#endif |
| + |
| while (*p1 && *p2 && *p1 == *p2) { |
| ++p1; |
| ++p2; |
| } |
| - while ((*p1 && *p1 != '/') || (*p2 && *p2 != '/')) { |
| + while ((*p1 && *p1 != dirseparator) || (*p2 && *p2 != dirseparator)) { |
| p1--; |
| p2--; |
| } |
| @@ -1688,3 +1701,36 @@ |
| (void)fd; |
| #endif |
| } |
| + |
| +void str_replace(char *target, const char *needle, const char *replacement) |
| +{ |
| + char buffer[1024] = { 0 }; |
| + char *insert_point = &buffer[0]; |
| + const char *tmp = target; |
| + size_t needle_len = strlen(needle); |
| + size_t repl_len = strlen(replacement); |
| + |
| + while (1) { |
| + const char *p = strstr(tmp, needle); |
| + |
| + // walked past last occurrence of needle; copy remaining part |
| + if (p == NULL) { |
| + strcpy(insert_point, tmp); |
| + break; |
| + } |
| + |
| + // copy part before needle |
| + memcpy(insert_point, tmp, p - tmp); |
| + insert_point += p - tmp; |
| + |
| + // copy replacement string |
| + memcpy(insert_point, replacement, repl_len); |
| + insert_point += repl_len; |
| + |
| + // adjust pointers, move on |
| + tmp = p + needle_len; |
| + } |
| + |
| + // write altered string back to target |
| + strcpy(target, buffer); |
| +} |