summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Giesen <fabiang@radgametools.com>2016-04-28 13:48:15 -0700
committerCyrill Gorcunov <gorcunov@gmail.com>2016-05-10 12:01:22 +0300
commit142285ddd8e8d2cb08003198d7186db9d3286ac1 (patch)
tree05917734ba27b9925859618f1b289281074c0225
parent86d8756f0cd255e91c8ef8a4de1ebae3c18d30f3 (diff)
downloadnasm-142285ddd8e8d2cb08003198d7186db9d3286ac1.tar.gz
codeview: Make md5sum calc read file in 'binary' mode
When assembling on Windows machines with CRLF line endings, computing the MD5 hash from the file read in "text" mode (transforms CRLF->LF) gives incorrect results. Signed-off-by: Fabian Giesen <fabiang@radgametools.com> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r--output/codeview.c2
-rw-r--r--preproc.c12
-rw-r--r--preproc.h2
3 files changed, 8 insertions, 8 deletions
diff --git a/output/codeview.c b/output/codeview.c
index 571cbabe..56c46f2c 100644
--- a/output/codeview.c
+++ b/output/codeview.c
@@ -309,7 +309,7 @@ static void calc_md5(const char *const filename,
FILE *f;
MD5_CTX ctx;
- f = pp_input_fopen(filename);
+ f = pp_input_fopen(filename, "rb");
if (!f)
goto done;
diff --git a/preproc.c b/preproc.c
index 78263fb3..d2352808 100644
--- a/preproc.c
+++ b/preproc.c
@@ -1509,7 +1509,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)
+ bool missing_ok, const char *mode)
{
FILE *fp;
char *prefix = "";
@@ -1522,7 +1522,7 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail,
sl = nasm_malloc(prefix_len+len+1+sizeof sl->next);
memcpy(sl->str, prefix, prefix_len);
memcpy(sl->str+prefix_len, file, len+1);
- fp = fopen(sl->str, "r");
+ fp = fopen(sl->str, mode);
if (fp && dhead && !in_list(*dhead, sl->str)) {
sl->next = NULL;
**dtail = sl;
@@ -1564,13 +1564,13 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail,
* that get a file:lineno pair and need to look at the file again
* (e.g. the CodeView debug backend). Returns NULL on failure.
*/
-FILE *pp_input_fopen(const char *filename)
+FILE *pp_input_fopen(const char *filename, const char *mode)
{
FILE *fp;
StrList *xsl = NULL;
StrList **xst = &xsl;
- fp = inc_fopen(filename, &xsl, &xst, true);
+ fp = inc_fopen(filename, &xsl, &xst, true, mode);
if (xsl)
nasm_free(xsl);
return fp;
@@ -2517,7 +2517,7 @@ 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);
+ inc->fp = inc_fopen(p, dephead, &deptail, pass == 0, "r");
if (!inc->fp) {
/* -MG given but file not found */
nasm_free(inc);
@@ -3260,7 +3260,7 @@ issue_error:
if (t->type != TOK_INTERNAL_STRING)
nasm_unquote(p, NULL);
- fp = inc_fopen(p, &xsl, &xst, true);
+ fp = inc_fopen(p, &xsl, &xst, true, "r");
if (fp) {
p = xsl->str;
fclose(fp); /* Don't actually care about the file */
diff --git a/preproc.h b/preproc.h
index 3dee45f2..3d1aa9c7 100644
--- a/preproc.h
+++ b/preproc.h
@@ -49,6 +49,6 @@ typedef const unsigned char macros_t;
enum preproc_token pp_token_hash(const char *token);
/* Opens an include file or input file. This uses the include path. */
-FILE *pp_input_fopen(const char *filename);
+FILE *pp_input_fopen(const char *filename, const char *mode);
#endif