#include "libxml.h"
#include <string.h>
+#include <stddef.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <lzma.h>
#endif
-#if defined(WIN32) || defined(_WIN32)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#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
*
*/
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
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);
(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)
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);
}
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);
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);
}
#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 */
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 */
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
- fd = xmlWrapGzOpen(path, "rb");
+ fd = xmlWrapGzOpenUtf8(path, "rb");
#else
fd = gzopen(path, "rb");
#endif
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
- fd = xmlWrapGzOpen(path, mode);
+ fd = xmlWrapGzOpenUtf8(path, mode);
#else
fd = gzopen(path, mode);
#endif
*
* 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) {
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);
}
*/
void *
-xmlIOHTTPOpenW(const char *post_uri, int compression)
+xmlIOHTTPOpenW(const char *post_uri, int compression ATTRIBUTE_UNUSED)
{
xmlIOHTTPWriteCtxtPtr ctxt = NULL;
if (xmlInputCallbackInitialized)
return;
-#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
- xmlInitPlatformSpecificIo();
-#endif
-
xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen,
xmlFileRead, xmlFileClose);
#ifdef HAVE_ZLIB_H
if (xmlOutputCallbackInitialized)
return;
-#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
- xmlInitPlatformSpecificIo();
-#endif
-
xmlRegisterOutputCallbacks(xmlFileMatch, xmlFileOpenW,
xmlFileWrite, xmlFileClose);
ret = xmlAllocParserInputBuffer(enc);
if (ret != NULL) {
- ret->context = (void *) (long) fd;
+ ret->context = (void *) (ptrdiff_t) fd;
ret->readcallback = xmlFdRead;
ret->closecallback = xmlFdClose;
}
xmlParserInputBufferPtr ret;
int errcode;
- if (size <= 0) return(NULL);
+ if (size < 0) return(NULL);
if (mem == NULL) return(NULL);
ret = xmlAllocParserInputBuffer(enc);
xmlCharEncoding enc) {
xmlParserInputBufferPtr ret;
- if (size <= 0) return(NULL);
+ if (size < 0) return(NULL);
if (mem == NULL) return(NULL);
ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer));
ret = xmlAllocOutputBufferInternal(encoder);
if (ret != NULL) {
- ret->context = (void *) (long) fd;
+ ret->context = (void *) (ptrdiff_t) fd;
ret->writecallback = xmlFdWrite;
ret->closecallback = NULL;
}
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=='/')