1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-10 08:58:16 +03:00

Justin Fletcher provided cleaup code in case HAVE_STAT is not defined Igor

* catalog.c: Justin Fletcher provided cleaup code in case
  HAVE_STAT is not defined
* include/win32config.h: Igor Zlatkovic suggested to have
  HAVE_STAT defined there
Daniel
This commit is contained in:
Daniel Veillard 2001-10-01 07:36:25 +00:00
parent 5e1cac1ac0
commit 16756b627b
3 changed files with 90 additions and 51 deletions

View File

@ -1,3 +1,10 @@
Mon Oct 1 09:34:51 CEST 2001 Daniel Veillard <daniel@veillard.com>
* catalog.c: Justin Fletcher provided cleaup code in case
HAVE_STAT is not defined
* include/win32config.h: Igor Zlatkovic suggested to have
HAVE_STAT defined there
Sat Sep 29 00:15:00 HKT 2001 William Brack <wbrack@mmm.com.hk>
* catalog.c - fixed typing error reported by M. Barros

View File

@ -2016,9 +2016,19 @@ xmlInitializeCatalog(void) {
* Returns 0 in case of success -1 in case of error
*/
int
xmlLoadCatalog(const char *filename) {
int fd, len, ret, i;
xmlLoadCatalog(const char *filename)
{
#ifdef HAVE_STAT
int fd;
#else
FILE *fd;
#endif
int len, ret, i;
long size;
#ifdef HAVE_STAT
struct stat info;
#endif
xmlChar *content;
if (filename == NULL)
@ -2060,26 +2070,45 @@ xmlLoadCatalog(const char *filename) {
}
catalTab[catalNr++] = filename;
#ifdef HAVE_STAT
if ((fd = open(filename, O_RDONLY)) < 0) {
#else
if ((fd = fopen(filename, "rb")) == NULL) {
#endif
catalNr--;
return (-1);
}
content = xmlMalloc(info.st_size + 10);
#ifdef HAVE_STAT
size = info.st_size;
#else
if (fseek(fd, 0, SEEK_END) || (size = ftell(fd)) == EOF || fseek(fd, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */
fclose(fd);
return (-1);
}
#endif
content = xmlMalloc(size + 10);
if (content == NULL) {
xmlGenericError(xmlGenericErrorContext,
"realloc of %d byte failed\n", info.st_size + 10);
"realloc of %d byte failed\n", size + 10);
catalNr--;
return (-1);
}
len = read(fd, content, info.st_size);
#ifdef HAVE_STAT
len = read(fd, content, size);
#else
len = fread(content, 1, size, fd);
#endif
if (len < 0) {
xmlFree(content);
catalNr--;
return (-1);
}
content[len] = 0;
#ifdef HAVE_STAT
close(fd);
#else
fclose(fd);
#endif
if ((content[0] == ' ') || (content[0] == '-') ||
((content[0] >= 'A') && (content[0] <= 'Z')) ||
@ -2087,8 +2116,10 @@ xmlLoadCatalog(const char *filename) {
ret = xmlParseSGMLCatalog(content, filename);
else {
xmlCatalogEntryPtr catal, tmp;
/* TODO: allow to switch the default preference */
catal = xmlParseXMLCatalog(content, XML_CATA_PREFER_PUBLIC, filename);
catal =
xmlParseXMLCatalog(content, XML_CATA_PREFER_PUBLIC, filename);
if (catal != NULL) {
if (xmlDefaultXMLCatalogList == NULL)
xmlDefaultXMLCatalogList = catal;

View File

@ -110,6 +110,7 @@ static int isnan (double d) {
#define HAVE_SYS_STAT_H
#define HAVE__STAT
#define HAVE_STAT
#include <libxml/xmlwin32version.h>