MCPcopy Create free account
hub / github.com/BVLC/caffe / ReadEntireFile

Method ReadEntireFile

src/gtest/gtest-all.cpp:8363–8383  ·  view source on GitHub ↗

Reads the entire content of a file as a string.

Source from the content-addressed store, hash-verified

8361
8362// Reads the entire content of a file as a string.
8363String CapturedStream::ReadEntireFile(FILE* file) {
8364 const size_t file_size = GetFileSize(file);
8365 char* const buffer = new char[file_size];
8366
8367 size_t bytes_last_read = 0; // # of bytes read in the last fread()
8368 size_t bytes_read = 0; // # of bytes read so far
8369
8370 fseek(file, 0, SEEK_SET);
8371
8372 // Keeps reading the file until we cannot read further or the
8373 // pre-determined file size is reached.
8374 do {
8375 bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
8376 bytes_read += bytes_last_read;
8377 } while (bytes_last_read > 0 && bytes_read < file_size);
8378
8379 const String content(buffer, bytes_read);
8380 delete[] buffer;
8381
8382 return content;
8383}
8384
8385# ifdef _MSC_VER
8386# pragma warning(pop)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected