1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-12 09:17:37 +03:00

574393 – utf-8 filename magic for compressed files

* xmlIO.c: windows specific magic to have UTF-8 file name work with
  compressed files too.
This commit is contained in:
Hans Breuer 2009-08-11 17:51:22 +02:00 committed by Daniel Veillard
parent 489f9671e7
commit 2ad41cad3e

38
xmlIO.c
View File

@ -613,6 +613,32 @@ xmlWrapOpenUtf8(const char *path,int mode)
return fd;
}
static gzFile
xmlWrapGzOpenUtf8(const char *path, const char *mode)
{
gzFile fd;
wchar_t *wPath;
fd = gzopen (path, mode);
if (fd)
return fd;
wPath = __xmlIOWin32UTF8ToWChar(path);
if(wPath)
{
int d, m = (strstr(mode, "r") ? O_RDONLY : O_RDWR);
#ifdef _O_BINARY
m |= (strstr(mode, "b") ? _O_BINARY : 0);
#endif
d = _wopen(wPath, m);
if (d >= 0)
fd = gzdopen(d, mode);
xmlFree(wPath);
}
return fd;
}
/**
* xmlWrapStatUtf8:
* @path: the path in utf-8 encoding
@ -679,6 +705,8 @@ 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;
typedef gzFile (* xmlWrapGzOpenFunc) (const char *f, const char *mode);
static xmlWrapGzOpenFunc xmlWrapGzOpen = gzopen;
/**
* xmlInitPlatformSpecificIo:
@ -699,9 +727,11 @@ xmlInitPlatformSpecificIo(void)
if(GetVersionEx(&osvi) && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)) {
xmlWrapStat = xmlWrapStatUtf8;
xmlWrapOpen = xmlWrapOpenUtf8;
xmlWrapGzOpen = xmlWrapGzOpenUtf8;
} else {
xmlWrapStat = xmlWrapStatNative;
xmlWrapOpen = xmlWrapOpenNative;
xmlWrapGzOpen = gzopen;
}
xmlPlatformIoInitialized = 1;
@ -1132,7 +1162,11 @@ xmlGzfileOpen_real (const char *filename) {
if (!xmlCheckFilename(path))
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapGzOpen(path, "rb");
#else
fd = gzopen(path, "rb");
#endif
return((void *) fd);
}
@ -1200,7 +1234,11 @@ xmlGzfileOpenW (const char *filename, int compression) {
if (path == NULL)
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapGzOpen(path, mode);
#else
fd = gzopen(path, mode);
#endif
return((void *) fd);
}
#endif /* LIBXML_OUTPUT_ENABLED */