MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlFileOpenSafe

Function xmlFileOpenSafe

ThirdParty/libxml2/vtklibxml2/xmlIO.c:681–732  ·  view source on GitHub ↗

* xmlFileOpenSafe: * @filename: the URI for matching * @out: pointer to resulting context * * input from FILE * * * Returns an I/O context or NULL in case of error */

Source from the content-addressed store, hash-verified

679 * Returns an I/O context or NULL in case of error
680 */
681static int
682xmlFileOpenSafe(const char *filename, int write, void **out) {
683 char *fromUri = NULL;
684 FILE *fd;
685 int ret = XML_ERR_OK;
686
687 *out = NULL;
688 if (filename == NULL)
689 return(XML_ERR_ARGUMENT);
690
691 if (xmlConvertUriToPath(filename, &fromUri) < 0)
692 return(XML_ERR_NO_MEMORY);
693
694 if (fromUri != NULL)
695 filename = fromUri;
696
697#if defined(_WIN32)
698 {
699 wchar_t *wpath;
700
701 wpath = __xmlIOWin32UTF8ToWChar(filename);
702 if (wpath == NULL) {
703 xmlFree(fromUri);
704 return(XML_ERR_NO_MEMORY);
705 }
706 fd = _wfopen(wpath, write ? L"wb" : L"rb");
707 xmlFree(wpath);
708 }
709#else
710 fd = fopen(filename, write ? "wb" : "rb");
711#endif /* WIN32 */
712
713 if (fd == NULL) {
714 /*
715 * Windows and possibly other platforms return EINVAL
716 * for invalid filenames.
717 */
718 if ((errno == ENOENT) || (errno == EINVAL)) {
719 ret = XML_IO_ENOENT;
720 } else {
721 /*
722 * This error won't be forwarded to the parser context
723 * which will report it a second time.
724 */
725 ret = xmlIOErr(0, filename);
726 }
727 }
728
729 *out = fd;
730 xmlFree(fromUri);
731 return(ret);
732}
733
734/**
735 * xmlFileOpen:

Callers 1

xmlFileOpenFunction · 0.85

Calls 3

xmlConvertUriToPathFunction · 0.85
__xmlIOWin32UTF8ToWCharFunction · 0.85
xmlIOErrFunction · 0.85

Tested by

no test coverage detected