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

Function pkgmap_read_file

src/pipeline/pass_pkgmap.c:39–61  ·  view source on GitHub ↗

Read an entire file into a core-owned buffer (class extract; release with * cbm_free(CBM_MEM_CLASS_EXTRACT, ...)). Returns NULL on failure. */

Source from the content-addressed store, hash-verified

37/* Read an entire file into a core-owned buffer (class extract; release with
38 * cbm_free(CBM_MEM_CLASS_EXTRACT, ...)). Returns NULL on failure. */
39static char *pkgmap_read_file(const char *path, int *out_len) {
40 FILE *f = cbm_fopen(path, "rb");
41 if (!f) {
42 return NULL;
43 }
44 (void)fseek(f, 0, SEEK_END);
45 long size = ftell(f);
46 (void)fseek(f, 0, SEEK_SET);
47 if (size <= 0 || size > (long)CBM_SZ_1K * CBM_SZ_1K) { /* 1MB cap for manifests */
48 (void)fclose(f);
49 return NULL;
50 }
51 char *buf = (char *)cbm_alloc(CBM_MEM_CLASS_EXTRACT, (size_t)size + SKIP_ONE);
52 if (!buf) {
53 (void)fclose(f);
54 return NULL;
55 }
56 size_t nread = fread(buf, SKIP_ONE, (size_t)size, f);
57 (void)fclose(f);
58 buf[nread] = '\0';
59 *out_len = (int)nread;
60 return buf;
61}
62
63/* ── Constants ─────────────────────────────────────────────────── */
64

Callers 3

pkgmap_walk_dirFunction · 0.85

Calls 3

cbm_fopenFunction · 0.85
cbm_allocFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected