io: Fix return value of xmlFileRead

This broke in commit 6d27c54.

Fixes #766.
This commit is contained in:
Nick Wellnhofer 2024-07-09 12:29:53 +02:00
parent e30cb632e7
commit bf43e8a888
3 changed files with 33 additions and 2 deletions

View File

@ -528,7 +528,7 @@ if(LIBXML2_WITH_TESTS)
endif()
add_test(NAME testchar COMMAND testchar)
add_test(NAME testdict COMMAND testdict)
add_test(NAME testparser COMMAND testparser)
add_test(NAME testparser COMMAND testparser WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME testrecurse COMMAND testrecurse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME testThreads COMMAND testThreads WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

View File

@ -4,6 +4,8 @@
* See Copyright for the status of this software.
*/
#define XML_DEPRECATED
#include <libxml/parser.h>
#include <libxml/uri.h>
#include <libxml/xmlreader.h>
@ -95,6 +97,34 @@ testNodeGetContent(void) {
return err;
}
static int
testCFileIO(void) {
xmlDocPtr doc;
int err = 0;
/* Deprecated FILE-based API */
xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen, xmlFileRead,
xmlFileClose);
doc = xmlReadFile("test/ent1", NULL, 0);
if (doc == NULL) {
err = 1;
} else {
xmlNodePtr root = xmlDocGetRootElement(doc);
if (root == NULL || !xmlStrEqual(root->name, BAD_CAST "EXAMPLE"))
err = 1;
}
xmlFreeDoc(doc);
xmlPopInputCallbacks();
if (err)
fprintf(stderr, "xmlReadFile failed with FILE input callbacks\n");
return err;
}
#ifdef LIBXML_SAX1_ENABLED
static int
testBalancedChunk(void) {
@ -540,6 +570,7 @@ main(void) {
err |= testStandaloneWithEncoding();
err |= testUnsupportedEncoding();
err |= testNodeGetContent();
err |= testCFileIO();
#ifdef LIBXML_SAX1_ENABLED
err |= testBalancedChunk();
#endif

View File

@ -776,7 +776,7 @@ xmlFileRead(void * context, char * buffer, int len) {
if ((bytes < (size_t) len) && (ferror(file)))
return(-xmlIOErr(0, "fread()"));
return(len);
return(bytes);
}
#ifdef LIBXML_OUTPUT_ENABLED