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

Function read_file

src/pipeline/pass_parallel.c:243–291  ·  view source on GitHub ↗

Read file into a malloc'd buffer (= mimalloc in production). * *out_size receives the on-disk size and *out_status the failure reason so the * caller can attribute a skip to the right phase (read vs oversized) instead of * a silent drop. Both out params may be NULL. */

Source from the content-addressed store, hash-verified

241 * caller can attribute a skip to the right phase (read vs oversized) instead of
242 * a silent drop. Both out params may be NULL. */
243static char *read_file(const char *path, int *out_len, long *out_size,
244 cbm_read_status_t *out_status) {
245 if (out_size) {
246 *out_size = 0;
247 }
248 if (out_status) {
249 *out_status = CBM_READ_OK;
250 }
251 FILE *f = cbm_fopen(path, "rb");
252 if (!f) {
253 if (out_status) {
254 *out_status = CBM_READ_OPEN_FAIL;
255 }
256 return NULL;
257 }
258 (void)fseek(f, 0, SEEK_END);
259 long size = ftell(f);
260 (void)fseek(f, 0, SEEK_SET);
261 if (out_size) {
262 *out_size = size;
263 }
264 if (size <= 0) {
265 (void)fclose(f);
266 if (out_status) {
267 *out_status = CBM_READ_EMPTY;
268 }
269 return NULL;
270 }
271 if (size > cbm_max_file_bytes()) { /* generous, env-configurable cap (B4) */
272 (void)fclose(f);
273 if (out_status) {
274 *out_status = CBM_READ_OVERSIZED;
275 }
276 return NULL;
277 }
278 char *buf = (char *)malloc((size_t)size + SKIP_ONE);
279 if (!buf) {
280 (void)fclose(f);
281 if (out_status) {
282 *out_status = CBM_READ_OOM;
283 }
284 return NULL;
285 }
286 size_t nread = fread(buf, SKIP_ONE, (size_t)size, f);
287 (void)fclose(f);
288 buf[nread] = '\0';
289 *out_len = (int)nread;
290 return buf;
291}
292
293/* ── Per-worker skip list (Stage 2 / Track B) ───────────────────────
294 * Each extract worker appends read/extract/oversized skips into its OWN list

Callers 2

extract_workerFunction · 0.70
resolve_workerFunction · 0.70

Calls 3

cbm_fopenFunction · 0.85
cbm_max_file_bytesFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected