mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-24 21:33:51 +03:00
applied patch from Roland Schwingel to allow UTF-8 file paths on Windows
* xmlIO.c: applied patch from Roland Schwingel to allow UTF-8 file paths on Windows Daniel
This commit is contained in:
parent
02c1f23297
commit
f741601cc7
@ -1,3 +1,8 @@
|
||||
Thu Apr 27 10:15:45 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* xmlIO.c: applied patch from Roland Schwingel to allow UTF-8
|
||||
file paths on Windows
|
||||
|
||||
Thu Apr 27 10:10:58 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* xmlwriter.c: patch from Jason Viers for line breaks after EndPI
|
||||
|
109
xmlIO.c
109
xmlIO.c
@ -36,6 +36,10 @@
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/* Figure a portable way to know if a file is a directory. */
|
||||
#ifndef HAVE_STAT
|
||||
# ifdef HAVE__STAT
|
||||
@ -189,6 +193,39 @@ static const char *IOerr[] = {
|
||||
"unknown address familly", /* EAFNOSUPPORT */
|
||||
};
|
||||
|
||||
#if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
|
||||
/**
|
||||
* __xmlIOWin32UTF8ToWChar:
|
||||
* @u8String: uft-8 string
|
||||
*
|
||||
* Convert a string from utf-8 to wchar (WINDOWS ONLY!)
|
||||
*/
|
||||
static wchar_t *
|
||||
__xmlIOWin32UTF8ToWChar(const char *u8String)
|
||||
{
|
||||
wchar_t *wString = NULL;
|
||||
|
||||
if (u8String)
|
||||
{
|
||||
int wLen = MultiByteToWideChar(CP_UTF8,0,u8String,-1,NULL,0);
|
||||
if (wLen)
|
||||
{
|
||||
wString = malloc((wLen+1) * sizeof(wchar_t));
|
||||
if (wString)
|
||||
{
|
||||
if (MultiByteToWideChar(CP_UTF8,0,u8String,-1,wString,wLen+1) == 0)
|
||||
{
|
||||
free(wString);
|
||||
wString = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wString;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* xmlIOErrMemory:
|
||||
* @extra: extra informations
|
||||
@ -552,23 +589,44 @@ xmlCleanupOutputCallbacks(void)
|
||||
int
|
||||
xmlCheckFilename (const char *path)
|
||||
{
|
||||
if (path == NULL)
|
||||
return(0);
|
||||
|
||||
#if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
wchar_t *wPath = __xmlIOWin32UTF8ToWChar(path);
|
||||
if (wPath)
|
||||
{
|
||||
struct _stat stat_buffer;
|
||||
|
||||
if (_wstat(wPath,&stat_buffer) == 0)
|
||||
{
|
||||
retval = 1;
|
||||
|
||||
if (((stat_buffer.st_mode & S_IFDIR) == S_IFDIR))
|
||||
retval = 2;
|
||||
}
|
||||
|
||||
free(wPath);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
#else
|
||||
#ifdef HAVE_STAT
|
||||
struct stat stat_buffer;
|
||||
|
||||
if (path == NULL)
|
||||
return(0);
|
||||
|
||||
if (stat(path, &stat_buffer) == -1)
|
||||
return 0;
|
||||
|
||||
#ifdef S_ISDIR
|
||||
if (S_ISDIR(stat_buffer.st_mode)) {
|
||||
if (S_ISDIR(stat_buffer.st_mode))
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (path == NULL)
|
||||
return(0);
|
||||
#endif /* S_ISDIR */
|
||||
#endif /* HAVE_STAT */
|
||||
#endif /* WIN32 */
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -692,7 +750,18 @@ xmlFileOpen_real (const char *filename) {
|
||||
return(NULL);
|
||||
|
||||
#if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
|
||||
fd = fopen(path, "rb");
|
||||
{
|
||||
wchar_t *wPath = __xmlIOWin32UTF8ToWChar(path);
|
||||
if (wPath)
|
||||
{
|
||||
fd = _wfopen(wPath, L"rb");
|
||||
free(wPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = fopen(path, "rb");
|
||||
}
|
||||
}
|
||||
#else
|
||||
fd = fopen(path, "r");
|
||||
#endif /* WIN32 */
|
||||
@ -762,8 +831,24 @@ xmlFileOpenW (const char *filename) {
|
||||
if (path == NULL)
|
||||
return(NULL);
|
||||
|
||||
fd = fopen(path, "wb");
|
||||
if (fd == NULL) xmlIOErr(0, path);
|
||||
#if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
|
||||
{
|
||||
wchar_t *wPath = __xmlIOWin32UTF8ToWChar(path);
|
||||
if (wPath)
|
||||
{
|
||||
fd = _wfopen(wPath, L"wb");
|
||||
free(wPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = fopen(path, "wb");
|
||||
}
|
||||
}
|
||||
#else
|
||||
fd = fopen(path, "wb");
|
||||
#endif /* WIN32 */
|
||||
|
||||
if (fd == NULL) xmlIOErr(0, path);
|
||||
return((void *) fd);
|
||||
}
|
||||
#endif /* LIBXML_OUTPUT_ENABLED */
|
||||
|
Loading…
Reference in New Issue
Block a user