| 3850 | } |
| 3851 | |
| 3852 | PUGI__FN xml_parse_result load_file_impl(xml_document& doc, FILE* file, unsigned int options, xml_encoding encoding) |
| 3853 | { |
| 3854 | if (!file) |
| 3855 | return make_parse_result(status_file_not_found); |
| 3856 | |
| 3857 | // get file size (can result in I/O errors) |
| 3858 | size_t size = 0; |
| 3859 | xml_parse_status size_status = get_file_size(file, size); |
| 3860 | |
| 3861 | if (size_status != status_ok) |
| 3862 | { |
| 3863 | fclose(file); |
| 3864 | return make_parse_result(size_status); |
| 3865 | } |
| 3866 | |
| 3867 | // allocate buffer for the whole file |
| 3868 | char* contents = static_cast<char*>(xml_memory::allocate(size > 0 ? size : 1)); |
| 3869 | |
| 3870 | if (!contents) |
| 3871 | { |
| 3872 | fclose(file); |
| 3873 | return make_parse_result(status_out_of_memory); |
| 3874 | } |
| 3875 | |
| 3876 | // read file in memory |
| 3877 | size_t read_size = fread(contents, 1, size, file); |
| 3878 | fclose(file); |
| 3879 | |
| 3880 | if (read_size != size) |
| 3881 | { |
| 3882 | xml_memory::deallocate(contents); |
| 3883 | return make_parse_result(status_io_error); |
| 3884 | } |
| 3885 | |
| 3886 | return doc.load_buffer_inplace_own(contents, size, options, encoding); |
| 3887 | } |
| 3888 | |
| 3889 | #ifndef PUGIXML_NO_STL |
| 3890 | template<typename T> |
nothing calls this directly
no test coverage detected