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

Function ri_slurp

tests/test_index_resilience.c:56–77  ·  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

54
55/* Slurp a whole file into a heap buffer (NUL-terminated). NULL on error. */
56static char *ri_slurp(const char *path) {
57 FILE *f = fopen(path, "rb");
58 if (!f) {
59 return NULL;
60 }
61 (void)fseek(f, 0, SEEK_END);
62 long n = ftell(f);
63 (void)fseek(f, 0, SEEK_SET);
64 if (n < 0) {
65 (void)fclose(f);
66 return NULL;
67 }
68 char *buf = (char *)malloc((size_t)n + 1);
69 if (!buf) {
70 (void)fclose(f);
71 return NULL;
72 }
73 size_t rd = fread(buf, 1, (size_t)n, f);
74 (void)fclose(f);
75 buf[rd] = '\0';
76 return buf;
77}
78
79/* Index the files already written under lp->tmpdir through the production MCP
80 * flow, capturing the raw response. Returns the opened graph store (NULL on

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected