| 194 | } |
| 195 | |
| 196 | std::unique_ptr<char[]> IFile::readAll() |
| 197 | { |
| 198 | auto memsize = this->size(); |
| 199 | std::unique_ptr<char[]> mem(new char[memsize]); |
| 200 | if (!mem) |
| 201 | { |
| 202 | LogError("Failed to allocate memory for %llu bytes", |
| 203 | static_cast<long long unsigned>(memsize)); |
| 204 | return nullptr; |
| 205 | } |
| 206 | |
| 207 | // We don't want this to change the state (such as the offset) of the file |
| 208 | // stream so store off the current pos and restore it after the read |
| 209 | auto currentPos = this->tellg(); |
| 210 | this->seekg(0, this->beg); |
| 211 | |
| 212 | this->read(mem.get(), memsize); |
| 213 | |
| 214 | this->seekg(currentPos); |
| 215 | |
| 216 | return mem; |
| 217 | } |
| 218 | |
| 219 | IFile::~IFile() = default; |
| 220 |
no test coverage detected