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

Function agent_read

tests/test_agent_clients.c:82–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82static char *agent_read(const char *path) {
83 FILE *fp = fopen(path, "rb");
84 if (!fp || fseek(fp, 0L, SEEK_END) != 0) {
85 if (fp) {
86 fclose(fp);
87 }
88 return NULL;
89 }
90 long length = ftell(fp);
91 if (length < 0L || fseek(fp, 0L, SEEK_SET) != 0) {
92 fclose(fp);
93 return NULL;
94 }
95 char *text = (char *)malloc((size_t)length + 1U);
96 if (!text) {
97 fclose(fp);
98 return NULL;
99 }
100 size_t read_count = fread(text, 1U, (size_t)length, fp);
101 int close_rc = fclose(fp);
102 if (read_count != (size_t)length || close_rc != 0) {
103 free(text);
104 return NULL;
105 }
106 text[read_count] = '\0';
107 return text;
108}
109
110static size_t agent_occurrences(const char *text, const char *needle) {
111 size_t count = 0U;

Callers 1

Calls 2

fopenFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected