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

Function diagnostics_read_file

tests/test_diagnostics.c:75–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75static 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
104static void diagnostics_cleanup_outputs(const diagnostics_paths_t *paths) {
105 char temporary[1100];

Callers 1

test_diagnostics.cFile · 0.85

Calls 1

cbm_fopenFunction · 0.85

Tested by

no test coverage detected