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>
This commit is contained in:
Fabian Giesen 2016-04-28 13:48:15 -07:00 committed by Cyrill Gorcunov
parent 0bbc38dbd5
commit 5b838ef981
3 changed files with 8 additions and 8 deletions

View File

@ -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;

View File

@ -1504,7 +1504,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 = "";
@ -1517,7 +1517,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;
@ -1559,13 +1559,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;
@ -2512,7 +2512,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);
@ -3253,7 +3253,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 */

View File

@ -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