[LIBXML2]
[reactos.git] / reactos / lib / 3rdparty / libxml2 / xmlIO.c
index 16a7b3d..2a2dd3b 100644 (file)
@@ -801,6 +801,13 @@ xmlCheckFilename (const char *path)
     return 1;
 }
 
+/**
+ * xmlNop:
+ *
+ * No Operation function, does nothing, no input
+ *
+ * Returns zero
+ */
 int
 xmlNop(void) {
     return(0);
@@ -888,7 +895,7 @@ xmlFileMatch (const char *filename ATTRIBUTE_UNUSED) {
  */
 static void *
 xmlFileOpen_real (const char *filename) {
-    const char *path = NULL;
+    const char *path = filename;
     FILE *fd;
 
     if (filename == NULL)
@@ -918,11 +925,8 @@ xmlFileOpen_real (const char *filename) {
 #else
        path = &filename[5];
 #endif
-    } else
-       path = filename;
+    }
 
-    if (path == NULL)
-       return(NULL);
     if (!xmlCheckFilename(path))
         return(NULL);
 
@@ -1160,7 +1164,12 @@ xmlGzfileOpen_real (const char *filename) {
     gzFile fd;
 
     if (!strcmp(filename, "-")) {
-        fd = gzdopen(dup(0), "rb");
+        int duped_fd = dup(fileno(stdin));
+        fd = gzdopen(duped_fd, "rb");
+        if (fd == Z_NULL && duped_fd >= 0) {
+            close(duped_fd);  /* gzdOpen() does not close on failure */
+        }
+
        return((void *) fd);
     }
 
@@ -1234,7 +1243,12 @@ xmlGzfileOpenW (const char *filename, int compression) {
 
     snprintf(mode, sizeof(mode), "wb%d", compression);
     if (!strcmp(filename, "-")) {
-        fd = gzdopen(dup(1), mode);
+        int duped_fd = dup(fileno(stdout));
+        fd = gzdopen(duped_fd, "rb");
+        if (fd == Z_NULL && duped_fd >= 0) {
+            close(duped_fd);  /* gzdOpen() does not close on failure */
+        }
+
        return((void *) fd);
     }
 
@@ -1356,7 +1370,7 @@ xmlXzfileOpen_real (const char *filename) {
     xzFile fd;
 
     if (!strcmp(filename, "-")) {
-        fd = __libxml2_xzdopen(dup(0), "rb");
+        fd = __libxml2_xzdopen(dup(fileno(stdin)), "rb");
        return((void *) fd);
     }
 
@@ -2669,6 +2683,12 @@ __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
            }
 #endif
        }
+#endif
+#ifdef HAVE_LZMA_H
+       if ((xmlInputCallbackTable[i].opencallback == xmlXzfileOpen) &&
+               (strcmp(URI, "-") != 0)) {
+            ret->compressed = __libxml2_xzcompressed(context);
+       }
 #endif
     }
     else
@@ -3326,6 +3346,17 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
     if (res < 0) {
        return(-1);
     }
+
+    /*
+     * try to establish compressed status of input if not done already
+     */
+    if (in->compressed == -1) {
+#ifdef HAVE_LZMA_H
+       if (in->readcallback == xmlXzfileRead)
+            in->compressed = __libxml2_xzcompressed(in->context);
+#endif
+    }
+
     len = res;
     if (in->encoder != NULL) {
         unsigned int use;