Returns true if |file| has encountered an error opening the file or reading from it. If there was an error, writes an error message to standard error.
| 52 | // Returns true if |file| has encountered an error opening the file or reading |
| 53 | // from it. If there was an error, writes an error message to standard error. |
| 54 | bool WasFileCorrectlyRead(FILE* file, const char* filename) { |
| 55 | if (file == nullptr) { |
| 56 | fprintf(stderr, "error: file does not exist '%s'\n", filename); |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | if (ftell(file) == -1L) { |
| 61 | if (ferror(file)) { |
| 62 | fprintf(stderr, "error: error reading file '%s'\n", filename); |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | // Ensure the file contained an exact number of elements, whose size is given in |
| 70 | // |alignment|. |
no outgoing calls
no test coverage detected