[LIBXML2] Update to version 2.9.7. CORE-14291

This commit is contained in:
Thomas Faber 2018-02-04 17:15:47 +01:00
parent b97f0a8fed
commit fc82f8e2e3
No known key found for this signature in database
GPG key ID: 076E7C3D44720826
52 changed files with 1978 additions and 2458 deletions

View file

@ -12,6 +12,7 @@
#include "libxml.h"
#include <string.h>
#include <stddef.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
@ -39,7 +40,8 @@
#include <lzma.h>
#endif
#if defined(WIN32) || defined(_WIN32)
#if defined(_WIN32) && !defined(__CYGWIN__)
//#define WIN32_LEAN_AND_MEAN
//#include <windows.h>
#include <winnls.h>
#endif
@ -48,38 +50,14 @@
#include <winnls.h> /* for CP_UTF8 */
#endif
/* Figure a portable way to know if a file is a directory. */
#ifndef HAVE_STAT
# ifdef HAVE__STAT
/* MS C library seems to define stat and _stat. The definition
is identical. Still, mapping them to each other causes a warning. */
# ifndef _MSC_VER
# define stat(x,y) _stat(x,y)
# endif
# define HAVE_STAT
# endif
#else
# ifdef HAVE__STAT
# if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
# define stat _stat
# endif
# endif
#endif
#ifdef HAVE_STAT
# ifndef S_ISDIR
# ifdef _S_ISDIR
# define S_ISDIR(x) _S_ISDIR(x)
# else
# ifdef S_IFDIR
# ifndef S_IFMT
# ifdef _S_IFMT
# define S_IFMT _S_IFMT
# endif
# endif
# ifdef S_IFMT
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# endif
# endif
#ifndef S_ISDIR
# ifdef _S_ISDIR
# define S_ISDIR(x) _S_ISDIR(x)
# elif defined(S_IFDIR)
# ifdef S_IFMT
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# elif defined(_S_IFMT)
# define S_ISDIR(m) (((m) & _S_IFMT) == S_IFDIR)
# endif
# endif
#endif
@ -657,99 +635,19 @@ xmlWrapGzOpenUtf8(const char *path, const char *mode)
*
*/
static int
xmlWrapStatUtf8(const char *path,struct stat *info)
{
#ifdef HAVE_STAT
xmlWrapStatUtf8(const char *path, struct _stat *info) {
int retval = -1;
wchar_t *wPath;
wPath = __xmlIOWin32UTF8ToWChar(path);
if (wPath)
{
retval = _wstat(wPath,info);
if (wPath) {
retval = _wstat(wPath, info);
xmlFree(wPath);
}
/* maybe path in native encoding */
if(retval < 0)
retval = stat(path,info);
retval = _stat(path, info);
return retval;
#else
return -1;
#endif
}
/**
* xmlWrapOpenNative:
* @path: the path
* @mode: type of access (0 - read, 1 - write)
*
* function opens the file specified by @path
*
*/
static FILE*
xmlWrapOpenNative(const char *path,int mode)
{
return fopen(path,mode ? "wb" : "rb");
}
/**
* xmlWrapStatNative:
* @path: the path
* @info: structure that stores results
*
* function obtains information about the file or directory
*
*/
static int
xmlWrapStatNative(const char *path,struct stat *info)
{
#ifdef HAVE_STAT
return stat(path,info);
#else
return -1;
#endif
}
typedef int (* xmlWrapStatFunc) (const char *f, struct stat *s);
static xmlWrapStatFunc xmlWrapStat = xmlWrapStatNative;
typedef FILE* (* xmlWrapOpenFunc)(const char *f,int mode);
static xmlWrapOpenFunc xmlWrapOpen = xmlWrapOpenNative;
#ifdef HAVE_ZLIB_H
typedef gzFile (* xmlWrapGzOpenFunc) (const char *f, const char *mode);
static xmlWrapGzOpenFunc xmlWrapGzOpen = gzopen;
#endif
/**
* xmlInitPlatformSpecificIo:
*
* Initialize platform specific features.
*/
static void
xmlInitPlatformSpecificIo(void)
{
static int xmlPlatformIoInitialized = 0;
OSVERSIONINFO osvi;
if(xmlPlatformIoInitialized)
return;
osvi.dwOSVersionInfoSize = sizeof(osvi);
if(GetVersionEx(&osvi) && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)) {
xmlWrapStat = xmlWrapStatUtf8;
xmlWrapOpen = xmlWrapOpenUtf8;
#ifdef HAVE_ZLIB_H
xmlWrapGzOpen = xmlWrapGzOpenUtf8;
#endif
} else {
xmlWrapStat = xmlWrapStatNative;
xmlWrapOpen = xmlWrapOpenNative;
#ifdef HAVE_ZLIB_H
xmlWrapGzOpen = gzopen;
#endif
}
xmlPlatformIoInitialized = 1;
return;
}
#endif
@ -772,7 +670,11 @@ int
xmlCheckFilename (const char *path)
{
#ifdef HAVE_STAT
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
struct _stat stat_buffer;
#else
struct stat stat_buffer;
#endif
#endif
if (path == NULL)
return(0);
@ -787,7 +689,7 @@ xmlCheckFilename (const char *path)
(path[3] == '\\') )
return 1;
if (xmlWrapStat(path, &stat_buffer) == -1)
if (xmlWrapStatUtf8(path, &stat_buffer) == -1)
return 0;
#else
if (stat(path, &stat_buffer) == -1)
@ -827,7 +729,7 @@ static int
xmlFdRead (void * context, char * buffer, int len) {
int ret;
ret = read((int) (long) context, &buffer[0], len);
ret = read((int) (ptrdiff_t) context, &buffer[0], len);
if (ret < 0) xmlIOErr(0, "read()");
return(ret);
}
@ -848,7 +750,7 @@ xmlFdWrite (void * context, const char * buffer, int len) {
int ret = 0;
if (len > 0) {
ret = write((int) (long) context, &buffer[0], len);
ret = write((int) (ptrdiff_t) context, &buffer[0], len);
if (ret < 0) xmlIOErr(0, "write()");
}
return(ret);
@ -866,7 +768,7 @@ xmlFdWrite (void * context, const char * buffer, int len) {
static int
xmlFdClose (void * context) {
int ret;
ret = close((int) (long) context);
ret = close((int) (ptrdiff_t) context);
if (ret < 0) xmlIOErr(0, "close()");
return(ret);
}
@ -927,11 +829,14 @@ xmlFileOpen_real (const char *filename) {
#endif
}
/* Do not check DDNAME on zOS ! */
#if !defined(__MVS__)
if (!xmlCheckFilename(path))
return(NULL);
#endif
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapOpen(path, 0);
fd = xmlWrapOpenUtf8(path, 0);
#else
fd = fopen(path, "r");
#endif /* WIN32 */
@ -1004,12 +909,14 @@ xmlFileOpenW (const char *filename) {
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapOpen(path, 1);
fd = xmlWrapOpenUtf8(path, 1);
#elif(__MVS__)
fd = fopen(path, "w");
#else
fd = fopen(path, "wb");
fd = fopen(path, "wb");
#endif /* WIN32 */
if (fd == NULL) xmlIOErr(0, path);
if (fd == NULL) xmlIOErr(0, path);
return((void *) fd);
}
#endif /* LIBXML_OUTPUT_ENABLED */
@ -1194,7 +1101,7 @@ xmlGzfileOpen_real (const char *filename) {
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapGzOpen(path, "rb");
fd = xmlWrapGzOpenUtf8(path, "rb");
#else
fd = gzopen(path, "rb");
#endif
@ -1271,7 +1178,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapGzOpen(path, mode);
fd = xmlWrapGzOpenUtf8(path, mode);
#else
fd = gzopen(path, mode);
#endif
@ -1287,7 +1194,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
*
* Read @len bytes to @buffer from the compressed I/O channel.
*
* Returns the number of bytes written
* Returns the number of bytes read.
*/
static int
xmlGzfileRead (void * context, char * buffer, int len) {
@ -1675,7 +1582,7 @@ xmlZMemBuffExtend( xmlZMemBuffPtr buff, size_t ext_amt ) {
xmlStrPrintf(msg, 500,
"xmlZMemBuffExtend: %s %lu bytes.\n",
"Allocation failure extending output buffer to",
new_size );
(unsigned long) new_size );
xmlIOErr(XML_IO_WRITE, (const char *) msg);
}
@ -1877,7 +1784,7 @@ xmlIOHTTPOpen (const char *filename) {
*/
void *
xmlIOHTTPOpenW(const char *post_uri, int compression)
xmlIOHTTPOpenW(const char *post_uri, int compression ATTRIBUTE_UNUSED)
{
xmlIOHTTPWriteCtxtPtr ctxt = NULL;
@ -2319,10 +2226,6 @@ xmlRegisterDefaultInputCallbacks(void) {
if (xmlInputCallbackInitialized)
return;
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
xmlInitPlatformSpecificIo();
#endif
xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen,
xmlFileRead, xmlFileClose);
#ifdef HAVE_ZLIB_H
@ -2357,10 +2260,6 @@ xmlRegisterDefaultOutputCallbacks (void) {
if (xmlOutputCallbackInitialized)
return;
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
xmlInitPlatformSpecificIo();
#endif
xmlRegisterOutputCallbacks(xmlFileMatch, xmlFileOpenW,
xmlFileWrite, xmlFileClose);
@ -3004,7 +2903,7 @@ xmlParserInputBufferCreateFd(int fd, xmlCharEncoding enc) {
ret = xmlAllocParserInputBuffer(enc);
if (ret != NULL) {
ret->context = (void *) (long) fd;
ret->context = (void *) (ptrdiff_t) fd;
ret->readcallback = xmlFdRead;
ret->closecallback = xmlFdClose;
}
@ -3028,7 +2927,7 @@ xmlParserInputBufferCreateMem(const char *mem, int size, xmlCharEncoding enc) {
xmlParserInputBufferPtr ret;
int errcode;
if (size <= 0) return(NULL);
if (size < 0) return(NULL);
if (mem == NULL) return(NULL);
ret = xmlAllocParserInputBuffer(enc);
@ -3064,7 +2963,7 @@ xmlParserInputBufferCreateStatic(const char *mem, int size,
xmlCharEncoding enc) {
xmlParserInputBufferPtr ret;
if (size <= 0) return(NULL);
if (size < 0) return(NULL);
if (mem == NULL) return(NULL);
ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer));
@ -3110,7 +3009,7 @@ xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) {
ret = xmlAllocOutputBufferInternal(encoder);
if (ret != NULL) {
ret->context = (void *) (long) fd;
ret->context = (void *) (ptrdiff_t) fd;
ret->writecallback = xmlFdWrite;
ret->closecallback = NULL;
}
@ -3824,7 +3723,7 @@ xmlParserGetDirectory(const char *filename) {
if (filename == NULL) return(NULL);
#if defined(WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32) && !defined(__CYGWIN__)
# define IS_XMLPGD_SEP(ch) ((ch=='/')||(ch=='\\'))
#else
# define IS_XMLPGD_SEP(ch) (ch=='/')