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

Function pkgmap_read_file

src/pipeline/pass_pkgmap.c:35–57  ·  view source on GitHub ↗

Read an entire file into a malloc'd buffer. Returns NULL on failure. */

Source from the content-addressed store, hash-verified

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

Callers 3

pkgmap_walk_dirFunction · 0.85

Calls 1

cbm_fopenFunction · 0.85

Tested by

no test coverage detected