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

Function read_file

src/pipeline/pass_parallel.c:227–275  ·  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

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

Callers 2

extract_workerFunction · 0.70
resolve_workerFunction · 0.70

Calls 2

cbm_fopenFunction · 0.85
cbm_max_file_bytesFunction · 0.85

Tested by

no test coverage detected