The default FileReader loads the whole file into the vector of char, returning false on error.
| 357 | // The default FileReader loads the whole file into the vector of char, |
| 358 | // returning false on error. |
| 359 | inline bool LoadDataFromFile(const STRING& filename, |
| 360 | GenericVector<char>* data) { |
| 361 | bool result = false; |
| 362 | FILE* fp = fopen(filename.string(), "rb"); |
| 363 | if (fp != NULL) { |
| 364 | fseek(fp, 0, SEEK_END); |
| 365 | size_t size = ftell(fp); |
| 366 | fseek(fp, 0, SEEK_SET); |
| 367 | if (size > 0) { |
| 368 | // reserve an extra byte in case caller wants to append a '\0' character |
| 369 | data->reserve(size + 1); |
| 370 | data->resize_no_init(size); |
| 371 | result = fread(&(*data)[0], 1, size, fp) == size; |
| 372 | } |
| 373 | fclose(fp); |
| 374 | } |
| 375 | return result; |
| 376 | } |
| 377 | // The default FileWriter writes the vector of char to the filename file, |
| 378 | // returning false on error. |
| 379 | inline bool SaveDataToFile(const GenericVector<char>& data, |
no test coverage detected