Suggested by Sandor Zsolt <narkoskatona@yahoo.com>
Unified · Split
| @@ -1078,16 +1078,19 @@ static int strstart(const char *str, const char *val, const char **ptr) · 1077 unmodified lines | ||
| 1078 | 1078 | } |
| 1079 | 1079 | #endif |
| 1080 | 1080 | |
| 1081 | +#ifdef _WIN32 | |
| 1082 | +#define IS_PATHSEP(c) (c == '/' || c == '\\') | |
| 1083 | +#define IS_ABSPATH(p) (IS_PATHSEP(p[0]) || (p[0] && p[1] == ':' && IS_PATHSEP(p[2]))) | |
| 1084 | +#else | |
| 1085 | +#define IS_PATHSEP(c) (c == '/') | |
| 1086 | +#define IS_ABSPATH(p) IS_PATHSEP(p[0]) | |
| 1087 | +#endif | |
| 1088 | + | |
| 1081 | 1089 | /* extract the basename of a file */ |
| 1082 | 1090 | static char *tcc_basename(const char *name) |
| 1083 | 1091 | { |
| 1084 | 1092 | char *p = strchr(name, 0); |
| 1085 | − while (p > name | |
| 1086 | − && p[-1] != '/' | |
| 1087 | −#ifdef _WIN32 | |
| 1088 | − && p[-1] != '\\' | |
| 1089 | −#endif | |
| 1090 | − ) | |
| 1093 | + while (p > name && !IS_PATHSEP(p[-1])) | |
| 1091 | 1094 | --p; |
| 1092 | 1095 | return p; |
| 1093 | 1096 | } |
| @@ -3086,6 +3089,13 @@ static void preprocess(int is_bof) · 1992 unmodified lines | ||
| 3086 | 3089 | /* push current file in stack */ |
| 3087 | 3090 | /* XXX: fix current line init */ |
| 3088 | 3091 | *s1->include_stack_ptr++ = file; |
| 3092 | + | |
| 3093 | + /* check absolute include path */ | |
| 3094 | + if (IS_ABSPATH(buf)) { | |
| 3095 | + f = tcc_open(s1, buf); | |
| 3096 | + if (f) | |
| 3097 | + goto found; | |
| 3098 | + } | |
| 3089 | 3099 | if (c == '\"') { |
| 3090 | 3100 | /* first search in current dir if "header.h" */ |
| 3091 | 3101 | size = tcc_basename(file->filename) - file->filename; |