MCPcopy Create free account
hub / github.com/WheretIB/nullc / get_file_size

Function get_file_size

external/pugixml/pugixml.cpp:3089–3126  ·  view source on GitHub ↗

we need to get length of entire file to load it in memory; the only (relatively) sane way to do it is via seek/tell trick

Source from the content-addressed store, hash-verified

3087
3088 // we need to get length of entire file to load it in memory; the only (relatively) sane way to do it is via seek/tell trick
3089 xml_parse_status get_file_size(FILE* file, size_t& out_result)
3090 {
3091 #if defined(_MSC_VER) && _MSC_VER >= 1400
3092 // there are 64-bit versions of fseek/ftell, let's use them
3093 typedef __int64 length_type;
3094
3095 _fseeki64(file, 0, SEEK_END);
3096 length_type length = _ftelli64(file);
3097 _fseeki64(file, 0, SEEK_SET);
3098 #elif defined(__MINGW32__) && !defined(__NO_MINGW_LFS) && !defined(__STRICT_ANSI__)
3099 // there are 64-bit versions of fseek/ftell, let's use them
3100 typedef off64_t length_type;
3101
3102 fseeko64(file, 0, SEEK_END);
3103 length_type length = ftello64(file);
3104 fseeko64(file, 0, SEEK_SET);
3105 #else
3106 // if this is a 32-bit OS, long is enough; if this is a unix system, long is 64-bit, which is enough; otherwise we can't do anything anyway.
3107 typedef long length_type;
3108
3109 fseek(file, 0, SEEK_END);
3110 length_type length = ftell(file);
3111 fseek(file, 0, SEEK_SET);
3112 #endif
3113
3114 // check for I/O errors
3115 if (length < 0) return status_io_error;
3116
3117 // check for overflow
3118 size_t result = static_cast<size_t>(length);
3119
3120 if (static_cast<length_type>(result) != length) return status_out_of_memory;
3121
3122 // finalize
3123 out_result = result;
3124
3125 return status_ok;
3126 }
3127
3128 xml_parse_result load_file_impl(xml_document& doc, FILE* file, unsigned int options, xml_encoding encoding)
3129 {

Callers 1

load_file_implFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected