MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ReadByteFromFile

Function ReadByteFromFile

src/saveload/oldloader.cpp:59–79  ·  view source on GitHub ↗

* * Reads a byte from a file (do not call yourself, use ReadByte()) * */

Source from the content-addressed store, hash-verified

57 *
58 */
59static uint8_t ReadByteFromFile(LoadgameState &ls)
60{
61 /* To avoid slow reads, we read BUFFER_SIZE of bytes per time
62 and just return a byte per time */
63 if (ls.buffer_cur >= ls.buffer_count) {
64
65 /* Read some new bytes from the file */
66 int count = static_cast<int>(fread(ls.buffer.data(), 1, ls.buffer.size(), *ls.file));
67
68 /* We tried to read, but there is nothing in the file anymore.. */
69 if (count == 0) {
70 Debug(oldloader, 0, "Read past end of file, loading failed");
71 throw std::exception();
72 }
73
74 ls.buffer_count = count;
75 ls.buffer_cur = 0;
76 }
77
78 return ls.buffer[ls.buffer_cur++];
79}
80
81/**
82 *

Callers 1

ReadByteFunction · 0.85

Calls 3

exceptionClass · 0.85
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected