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

Function ri_slurp

tests/test_index_resilience.c:68–89  ·  view source on GitHub ↗

Slurp a whole file into a heap buffer (NUL-terminated). NULL on error. */

Source from the content-addressed store, hash-verified

66
67/* Slurp a whole file into a heap buffer (NUL-terminated). NULL on error. */
68static char *ri_slurp(const char *path) {
69 FILE *f = fopen(path, "rb");
70 if (!f) {
71 return NULL;
72 }
73 (void)fseek(f, 0, SEEK_END);
74 long n = ftell(f);
75 (void)fseek(f, 0, SEEK_SET);
76 if (n < 0) {
77 (void)fclose(f);
78 return NULL;
79 }
80 char *buf = (char *)malloc((size_t)n + 1);
81 if (!buf) {
82 (void)fclose(f);
83 return NULL;
84 }
85 size_t rd = fread(buf, 1, (size_t)n, f);
86 (void)fclose(f);
87 buf[rd] = '\0';
88 return buf;
89}
90
91/* Index the files already written under lp->tmpdir through the production MCP
92 * flow, capturing the raw response. Returns the opened graph store (NULL on

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected