summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--def.h4
-rw-r--r--include.c24
-rw-r--r--main.c2
3 files changed, 21 insertions, 9 deletions
diff --git a/def.h b/def.h
index c5a5830..9cbbe61 100644
--- a/def.h
+++ b/def.h
@@ -112,6 +112,7 @@ struct symtab {
struct inclist {
char *i_incstring; /* string from #include line */
char *i_file; /* path name of the include file */
+ char *i_realpath; /* path name processed by realpath() */
struct inclist **i_list; /* list of files it itself includes */
struct symtab **i_defs; /* symbol table for this file and its
children when merged */
@@ -146,7 +147,8 @@ struct symtab **fdefined(const char *symbol, struct inclist *file,
struct inclist **srcfile);
struct filepointer *getfile(const char *file);
void included_by(struct inclist *ip, struct inclist *newfile);
-struct inclist *newinclude(const char *newfile, const char *incstring);
+struct inclist *newinclude(const char *newfile, const char *incstring,
+ const char *incpath);
void inc_clean(void);
struct inclist *inc_path(const char *file, const char *include, int type);
diff --git a/include.c b/include.c
index f07fb70..b638011 100644
--- a/include.c
+++ b/include.c
@@ -143,7 +143,7 @@ remove_dotdot(char *path)
* Add an include file to the list of those included by 'file'.
*/
struct inclist *
-newinclude(const char *newfile, const char *incstring)
+newinclude(const char *newfile, const char *incstring, const char *incpath)
{
struct inclist *ip;
@@ -165,6 +165,20 @@ newinclude(const char *newfile, const char *incstring)
fatalerr("strdup() failure in %s()\n", __func__);
}
+ if (incpath == NULL) {
+ char r_include[PATHMAX + 1];
+
+ if (realpath(ip->i_file, r_include) == NULL)
+ ip->i_realpath = ip->i_file;
+ else
+ ip->i_realpath = strdup(r_include);
+ }
+ else {
+ ip->i_realpath = strdup(incpath);
+ }
+ if (ip->i_realpath == NULL)
+ fatalerr("strdup() failure in %s()\n", __func__);
+
inclistnext = inclistp;
return (ip);
}
@@ -328,16 +342,12 @@ inc_path(const char *file, const char *include, int type)
/*
* Same filename but same file ?
*/
- char r_saved_path[PATHMAX + 1];
-
- if (realpath(ip->i_file, r_saved_path) == NULL)
- continue;
- if (!strcmp(r_include, r_saved_path)) {
+ if (!strcmp(r_include, ip->i_realpath)) {
inclistnext = ip + 1;
return ip;
}
}
}
- return newinclude(fp, include);
+ return newinclude(fp, include, r_include);
}
diff --git a/main.c b/main.c
index 0fcd0c2..9ebe101 100644
--- a/main.c
+++ b/main.c
@@ -518,7 +518,7 @@ main(int argc, char *argv[])
DBG_PRINT(stderr, "file: %s\n", *fp);
filecontent = getfile(*fp);
setfile_cmdinc(filecontent, cmdinc_count, cmdinc_list);
- ip = newinclude(*fp, (char *) NULL);
+ ip = newinclude(*fp, NULL, NULL);
find_includes(filecontent, ip, ip, 0, FALSE);
freefile(filecontent);