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

Function xmlLoadFileContent

ThirdParty/libxml2/vtklibxml2/catalog.c:921–985  ·  view source on GitHub ↗

* xmlLoadFileContent: * @filename: a file path * * Load a file content into memory. * * Returns a pointer to the 0 terminated string or NULL in case of error */

Source from the content-addressed store, hash-verified

919 * Returns a pointer to the 0 terminated string or NULL in case of error
920 */
921static xmlChar *
922xmlLoadFileContent(const char *filename)
923{
924#ifdef HAVE_STAT
925 int fd;
926#else
927 FILE *fd;
928#endif
929 int len;
930 long size;
931
932#ifdef HAVE_STAT
933 struct stat info;
934#endif
935 xmlChar *content;
936
937 if (filename == NULL)
938 return (NULL);
939
940#ifdef HAVE_STAT
941 if (stat(filename, &info) < 0)
942 return (NULL);
943#endif
944
945#ifdef HAVE_STAT
946 if ((fd = open(filename, O_RDONLY)) < 0)
947#else
948 if ((fd = fopen(filename, "rb")) == NULL)
949#endif
950 {
951 return (NULL);
952 }
953#ifdef HAVE_STAT
954 size = info.st_size;
955#else
956 if (fseek(fd, 0, SEEK_END) || (size = ftell(fd)) == EOF || fseek(fd, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */
957 fclose(fd);
958 return (NULL);
959 }
960#endif
961 content = (xmlChar*)xmlMallocAtomic(size + 10);
962 if (content == NULL) {
963 xmlCatalogErrMemory();
964#ifdef HAVE_STAT
965 close(fd);
966#else
967 fclose(fd);
968#endif
969 return (NULL);
970 }
971#ifdef HAVE_STAT
972 len = read(fd, content, size);
973 close(fd);
974#else
975 len = fread(content, 1, size, fd);
976 fclose(fd);
977#endif
978 if (len < 0) {

Callers 3

xmlLoadSGMLSuperCatalogFunction · 0.85
xmlLoadACatalogFunction · 0.85
xmlExpandCatalogFunction · 0.85

Calls 3

xmlCatalogErrMemoryFunction · 0.85
closeFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected