aboutsummaryrefslogtreecommitdiff
path: root/tcc.c
diff options
context:
space:
mode:
authorgrischka <grischka>2009-04-03 20:54:34 +0200
committergrischka <grischka>2009-04-18 15:07:28 +0200
commit6c10429aa5e7c65e725ed1989ddb856bbf7283aa (patch)
treef4f90944d0479c42b8c9a9fa9ea47f075e3147ca /tcc.c
parent29c8e1545a490325907e46206fd7156c7bda502b (diff)
downloadtinycc-6c10429aa5e7c65e725ed1989ddb856bbf7283aa.tar.gz
tinycc-6c10429aa5e7c65e725ed1989ddb856bbf7283aa.tar.bz2
check for absolute include paths
Suggested by Sandor Zsolt <narkoskatona@yahoo.com>
Diffstat (limited to 'tcc.c')
-rw-r--r--tcc.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/tcc.c b/tcc.c
index 97c62c1..548440d 100644
--- a/tcc.c
+++ b/tcc.c
@@ -1078,16 +1078,19 @@ static int strstart(const char *str, const char *val, const char **ptr)
}
#endif
+#ifdef _WIN32
+#define IS_PATHSEP(c) (c == '/' || c == '\\')
+#define IS_ABSPATH(p) (IS_PATHSEP(p[0]) || (p[0] && p[1] == ':' && IS_PATHSEP(p[2])))
+#else
+#define IS_PATHSEP(c) (c == '/')
+#define IS_ABSPATH(p) IS_PATHSEP(p[0])
+#endif
+
/* extract the basename of a file */
static char *tcc_basename(const char *name)
{
char *p = strchr(name, 0);
- while (p > name
- && p[-1] != '/'
-#ifdef _WIN32
- && p[-1] != '\\'
-#endif
- )
+ while (p > name && !IS_PATHSEP(p[-1]))
--p;
return p;
}
@@ -3086,6 +3089,13 @@ static void preprocess(int is_bof)
/* push current file in stack */
/* XXX: fix current line init */
*s1->include_stack_ptr++ = file;
+
+ /* check absolute include path */
+ if (IS_ABSPATH(buf)) {
+ f = tcc_open(s1, buf);
+ if (f)
+ goto found;
+ }
if (c == '\"') {
/* first search in current dir if "header.h" */
size = tcc_basename(file->filename) - file->filename;