MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / diagnostics_read_file

Function diagnostics_read_file

tests/test_diagnostics.c:74–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

test_diagnostics.cFile · 0.85

Calls 1

cbm_fopenFunction · 0.85

Tested by

no test coverage detected