| 3126 | } |
| 3127 | |
| 3128 | xml_parse_result load_file_impl(xml_document& doc, FILE* file, unsigned int options, xml_encoding encoding) |
| 3129 | { |
| 3130 | if (!file) return make_parse_result(status_file_not_found); |
| 3131 | |
| 3132 | // get file size (can result in I/O errors) |
| 3133 | size_t size = 0; |
| 3134 | xml_parse_status size_status = get_file_size(file, size); |
| 3135 | |
| 3136 | if (size_status != status_ok) |
| 3137 | { |
| 3138 | fclose(file); |
| 3139 | return make_parse_result(size_status); |
| 3140 | } |
| 3141 | |
| 3142 | // allocate buffer for the whole file |
| 3143 | char* contents = static_cast<char*>(global_allocate(size > 0 ? size : 1)); |
| 3144 | |
| 3145 | if (!contents) |
| 3146 | { |
| 3147 | fclose(file); |
| 3148 | return make_parse_result(status_out_of_memory); |
| 3149 | } |
| 3150 | |
| 3151 | // read file in memory |
| 3152 | size_t read_size = fread(contents, 1, size, file); |
| 3153 | fclose(file); |
| 3154 | |
| 3155 | if (read_size != size) |
| 3156 | { |
| 3157 | global_deallocate(contents); |
| 3158 | return make_parse_result(status_io_error); |
| 3159 | } |
| 3160 | |
| 3161 | return doc.load_buffer_inplace_own(contents, size, options, encoding); |
| 3162 | } |
| 3163 | |
| 3164 | #ifndef PUGIXML_NO_STL |
| 3165 | template <typename T> xml_parse_result load_stream_impl(xml_document& doc, std::basic_istream<T>& stream, unsigned int options, xml_encoding encoding) |
no test coverage detected