1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-19 10:03:34 +03:00

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.
This commit is contained in:
Nick Wellnhofer 2022-02-28 23:39:00 +01:00
parent 3f8655db97
commit 655cf3f46f
7 changed files with 7 additions and 45 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 -<sven@zen.org> */
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,