summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Kukunas <james.t.kukunas@linux.intel.com>2016-06-13 16:00:42 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2016-06-16 15:07:32 -0700
commit65a8afcabafa6d477b7fd52807113bdce1defd1c (patch)
treee99d23d7d5db701d11b7eb46f0129d719fc9586d
parentb41952986b3cd7558cb128790bb94e1f60fd088a (diff)
downloadnasm-65a8afcabafa6d477b7fd52807113bdce1defd1c.tar.gz
preproc: for include files, include correct path in filename
The codeview backend needs to be able to open each source file passed in so that it can calculate its checksum. In order to take into account include paths, this patch updates the filename to include the path where the file was found. Signed-off-by: Jim Kukunas <james.t.kukunas@linux.intel.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> [ hpa: resolved one conflict in preproc.c ]
-rw-r--r--preproc.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/preproc.c b/preproc.c
index 9dc3d88d..0cefa7d7 100644
--- a/preproc.c
+++ b/preproc.c
@@ -1508,7 +1508,7 @@ static bool in_list(const StrList *list, const char *str)
* the end of the path.
*/
static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail,
- bool missing_ok, const char *mode)
+ char **found_path, bool missing_ok, const char *mode)
{
FILE *fp;
char *prefix = "";
@@ -1516,11 +1516,20 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail,
int len = strlen(file);
size_t prefix_len = 0;
StrList *sl;
+ size_t path_len;
while (1) {
- sl = nasm_malloc(prefix_len+len+1+sizeof sl->next);
+ path_len = prefix_len + len + 1;
+
+ sl = nasm_malloc(path_len + sizeof sl->next);
memcpy(sl->str, prefix, prefix_len);
memcpy(sl->str+prefix_len, file, len+1);
+
+ if (found_path != NULL) {
+ *found_path = nasm_malloc(path_len);
+ memcpy(*found_path, sl->str, path_len);
+ }
+
fp = fopen(sl->str, mode);
if (fp && dhead && !in_list(*dhead, sl->str)) {
sl->next = NULL;
@@ -1531,6 +1540,12 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail,
}
if (fp)
return fp;
+
+ if (found_path != NULL && *found_path != NULL) {
+ nasm_free(*found_path);
+ *found_path == NULL;
+ }
+
if (!ip) {
if (!missing_ok)
break;
@@ -1569,7 +1584,7 @@ FILE *pp_input_fopen(const char *filename, const char *mode)
StrList *xsl = NULL;
StrList **xst = &xsl;
- fp = inc_fopen(filename, &xsl, &xst, true, mode);
+ fp = inc_fopen(filename, &xsl, &xst, NULL, true, mode);
if (xsl)
nasm_free(xsl);
return fp;
@@ -2174,7 +2189,7 @@ static int do_directive(Token * tline)
bool casesense;
int k, m;
int offset;
- char *p, *pp;
+ char *p, *pp, *found_path;
const char *mname;
Include *inc;
Context *ctx;
@@ -2516,12 +2531,13 @@ static int do_directive(Token * tline)
inc = nasm_malloc(sizeof(Include));
inc->next = istk;
inc->conds = NULL;
- inc->fp = inc_fopen(p, dephead, &deptail, pass == 0, "r");
+ found_path = NULL;
+ inc->fp = inc_fopen(p, dephead, &deptail, &found_path, pass == 0, "r");
if (!inc->fp) {
/* -MG given but file not found */
nasm_free(inc);
} else {
- inc->fname = src_set_fname(p);
+ inc->fname = src_set_fname(found_path ? found_path : p);
inc->lineno = src_set_linnum(0);
inc->lineinc = 1;
inc->expansion = NULL;
@@ -3259,7 +3275,7 @@ issue_error:
if (t->type != TOK_INTERNAL_STRING)
nasm_unquote(p, NULL);
- fp = inc_fopen(p, &xsl, &xst, true, "r");
+ fp = inc_fopen(p, &xsl, &xst, NULL, true, "r");
if (fp) {
p = xsl->str;
fclose(fp); /* Don't actually care about the file */