| 73 | } |
| 74 | |
| 75 | static char *diagnostics_read_file(const char *path) { |
| 76 | FILE *file = cbm_fopen(path, "rb"); |
| 77 | if (!file || fseek(file, 0, SEEK_END) != 0) { |
| 78 | if (file) { |
| 79 | (void)fclose(file); |
| 80 | } |
| 81 | return NULL; |
| 82 | } |
| 83 | long length = ftell(file); |
| 84 | if (length < 0 || fseek(file, 0, SEEK_SET) != 0) { |
| 85 | (void)fclose(file); |
| 86 | return NULL; |
| 87 | } |
| 88 | char *contents = malloc((size_t)length + 1); |
| 89 | if (!contents) { |
| 90 | (void)fclose(file); |
| 91 | return NULL; |
| 92 | } |
| 93 | size_t read_length = fread(contents, 1, (size_t)length, file); |
| 94 | bool closed = fclose(file) == 0; |
| 95 | bool complete = read_length == (size_t)length && closed; |
| 96 | contents[read_length] = '\0'; |
| 97 | if (!complete) { |
| 98 | free(contents); |
| 99 | return NULL; |
| 100 | } |
| 101 | return contents; |
| 102 | } |
| 103 | |
| 104 | static void diagnostics_cleanup_outputs(const diagnostics_paths_t *paths) { |
| 105 | char temporary[1100]; |
no test coverage detected