| 1759 | } |
| 1760 | |
| 1761 | static void streamFile(const char *filename) { |
| 1762 | xmlTextReaderPtr reader; |
| 1763 | int ret; |
| 1764 | #ifdef HAVE_MMAP |
| 1765 | int fd = -1; |
| 1766 | struct stat info; |
| 1767 | const char *base = NULL; |
| 1768 | |
| 1769 | if (memory) { |
| 1770 | if (stat(filename, &info) < 0) |
| 1771 | return; |
| 1772 | if ((fd = open(filename, O_RDONLY)) < 0) |
| 1773 | return; |
| 1774 | base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
| 1775 | if (base == (void *) MAP_FAILED) { |
| 1776 | close(fd); |
| 1777 | fprintf(ERR_STREAM, "mmap failure for file %s\n", filename); |
| 1778 | progresult = XMLLINT_ERR_RDFILE; |
| 1779 | return; |
| 1780 | } |
| 1781 | |
| 1782 | reader = xmlReaderForMemory(base, info.st_size, filename, |
| 1783 | NULL, options); |
| 1784 | } else |
| 1785 | #endif |
| 1786 | if (strcmp(filename, "-") == 0) |
| 1787 | reader = xmlReaderForFd(STDIN_FILENO, "-", NULL, options); |
| 1788 | else |
| 1789 | reader = xmlReaderForFile(filename, NULL, options); |
| 1790 | #ifdef LIBXML_PATTERN_ENABLED |
| 1791 | if (patternc != NULL) { |
| 1792 | patstream = xmlPatternGetStreamCtxt(patternc); |
| 1793 | if (patstream != NULL) { |
| 1794 | ret = xmlStreamPush(patstream, NULL, NULL); |
| 1795 | if (ret < 0) { |
| 1796 | fprintf(ERR_STREAM, "xmlStreamPush() failure\n"); |
| 1797 | xmlFreeStreamCtxt(patstream); |
| 1798 | patstream = NULL; |
| 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | #endif |
| 1803 | |
| 1804 | |
| 1805 | if (reader != NULL) { |
| 1806 | if (maxAmpl > 0) |
| 1807 | xmlTextReaderSetMaxAmplification(reader, maxAmpl); |
| 1808 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 1809 | if (relaxng != NULL) { |
| 1810 | if ((timing) && (!repeat)) { |
| 1811 | startTimer(); |
| 1812 | } |
| 1813 | ret = xmlTextReaderRelaxNGValidate(reader, relaxng); |
| 1814 | if (ret < 0) { |
| 1815 | fprintf(ERR_STREAM, |
| 1816 | "Relax-NG schema %s failed to compile\n", relaxng); |
| 1817 | progresult = XMLLINT_ERR_SCHEMACOMP; |
| 1818 | relaxng = NULL; |
no test coverage detected