From 655cf3f46f4dc8d2919aca70bb4aaddeeedf54bc Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Mon, 28 Feb 2022 23:39:00 +0100 Subject: [PATCH] Always fopen files with "rb" We never want translation of newlines when reading files, so it should be safe to always specify "rb". On sane platforms, the "b" flag is simply ignored. --- testAutomata.c | 2 +- testHTML.c | 14 +------------- testRegexp.c | 4 ++-- testSAX.c | 8 -------- testXPath.c | 2 +- xmlIO.c | 2 +- xmllint.c | 20 +------------------- 7 files changed, 7 insertions(+), 45 deletions(-) diff --git a/testAutomata.c b/testAutomata.c index 13213c69c..b89611cf4 100644 --- a/testAutomata.c +++ b/testAutomata.c @@ -41,7 +41,7 @@ testRegexpFile(const char *filename) { for (i = 0;i<1000;i++) states[i] = NULL; - input = fopen(filename, "r"); + input = fopen(filename, "rb"); if (input == NULL) { xmlGenericError(xmlGenericErrorContext, "Cannot open %s for reading\n", filename); diff --git a/testHTML.c b/testHTML.c index 98414b4a9..ee4d3e45b 100644 --- a/testHTML.c +++ b/testHTML.c @@ -627,11 +627,7 @@ parseSAXFile(char *filename) { if (push) { FILE *f; -#if defined(_WIN32) f = fopen(filename, "rb"); -#else - f = fopen(filename, "r"); -#endif if (f != NULL) { int res, size = 3; char chars[4096]; @@ -657,11 +653,7 @@ parseSAXFile(char *filename) { fclose(f); } if (!noout) { -#if defined(_WIN32) - f = fopen(filename, "rb"); -#else - f = fopen(filename, "r"); -#endif + f = fopen(filename, "rb"); if (f != NULL) { int res, size = 3; char chars[4096]; @@ -721,11 +713,7 @@ parseAndPrintFile(char *filename) { if (push) { FILE *f; -#if defined(_WIN32) f = fopen(filename, "rb"); -#else - f = fopen(filename, "r"); -#endif if (f != NULL) { int res, size = 3; char chars[4096]; diff --git a/testRegexp.c b/testRegexp.c index 218174144..2511b2109 100644 --- a/testRegexp.c +++ b/testRegexp.c @@ -40,7 +40,7 @@ testRegexpFile(const char *filename) { char expression[5000]; int len; - input = fopen(filename, "r"); + input = fopen(filename, "rb"); if (input == NULL) { xmlGenericError(xmlGenericErrorContext, "Cannot open %s for reading\n", filename); @@ -94,7 +94,7 @@ runFileTest(xmlExpCtxtPtr ctxt, const char *filename) { char expression[5000]; int len; - input = fopen(filename, "r"); + input = fopen(filename, "rb"); if (input == NULL) { xmlGenericError(xmlGenericErrorContext, "Cannot open %s for reading\n", filename); diff --git a/testSAX.c b/testSAX.c index ff774657b..b2d1363a7 100644 --- a/testSAX.c +++ b/testSAX.c @@ -1012,11 +1012,7 @@ parseAndPrintFile(char *filename) { /* * Empty callbacks for checking */ -#if defined(_WIN32) f = fopen(filename, "rb"); -#else - f = fopen(filename, "r"); -#endif if (f != NULL) { int ret; char chars[10]; @@ -1041,11 +1037,7 @@ parseAndPrintFile(char *filename) { /* * Debug callback */ -#if defined(_WIN32) f = fopen(filename, "rb"); -#else - f = fopen(filename, "r"); -#endif if (f != NULL) { int ret; char chars[10]; diff --git a/testXPath.c b/testXPath.c index ebb9ff7bb..d120f4e5c 100644 --- a/testXPath.c +++ b/testXPath.c @@ -118,7 +118,7 @@ testXPathFile(const char *filename) { char expression[5000]; int len; - input = fopen(filename, "r"); + input = fopen(filename, "rb"); if (input == NULL) { xmlGenericError(xmlGenericErrorContext, "Cannot open %s for reading\n", filename); diff --git a/xmlIO.c b/xmlIO.c index 3ec4f25b4..c76365e3d 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -866,7 +866,7 @@ xmlFileOpen_real (const char *filename) { #if defined(_WIN32) fd = xmlWrapOpenUtf8(path, 0); #else - fd = fopen(path, "r"); + fd = fopen(path, "rb"); #endif /* WIN32 */ if (fd == NULL) xmlIOErr(0, path); return((void *) fd); diff --git a/xmllint.c b/xmllint.c index 59a116d9e..fd5b243f8 100644 --- a/xmllint.c +++ b/xmllint.c @@ -2202,13 +2202,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { if ((filename[0] == '-') && (filename[1] == 0)) { f = stdin; } else { -#if defined(_WIN32) f = fopen(filename, "rb"); -#elif defined(__OS400__) - f = fopen(filename, "rb"); -#else - f = fopen(filename, "r"); -#endif } if (f != NULL) { int res; @@ -2276,15 +2270,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { /* '-' Usually means stdin - */ if ((filename[0] == '-') && (filename[1] == 0)) { - f = stdin; + f = stdin; } else { -#if defined(_WIN32) f = fopen(filename, "rb"); -#elif defined(__OS400__) - f = fopen(filename, "rb"); -#else - f = fopen(filename, "r"); -#endif } if (f != NULL) { int ret; @@ -2327,13 +2315,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { } else { FILE *f; -#if defined(_WIN32) f = fopen(filename, "rb"); -#elif defined(__OS400__) - f = fopen(filename, "rb"); -#else - f = fopen(filename, "r"); -#endif if (f != NULL) { if (rectxt == NULL) doc = xmlReadIO(myRead, myClose, f, filename, NULL,