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

Function sh_read

src/pipeline/pass_shell.c:2806–2829  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2804}
2805
2806static char *sh_read(const char *path, size_t *len) {
2807 FILE *f = cbm_fopen(path, "rb");
2808 if (!f) {
2809 return NULL;
2810 }
2811 (void)fseek(f, 0, SEEK_END);
2812 long size = ftell(f);
2813 (void)fseek(f, 0, SEEK_SET);
2814 if (size <= 0 || size > cbm_max_file_bytes()) {
2815 (void)fclose(f);
2816 return NULL;
2817 }
2818 enum { SH_TS_PAD = 16 }; /* tree-sitter's lexer reads past the end */
2819 char *buf = cbm_alloc(CBM_MEM_CLASS_OTHER, (size_t)size + SH_TS_PAD);
2820 if (!buf) {
2821 (void)fclose(f);
2822 return NULL;
2823 }
2824 size_t got = fread(buf, SKIP_ONE, (size_t)size, f);
2825 (void)fclose(f);
2826 memset(buf + got, 0, SH_TS_PAD);
2827 *len = got;
2828 return buf;
2829}
2830
2831typedef struct {
2832 sh_index_t *ix;

Callers 2

mk_closure_fileFunction · 0.85
sh_pass_fileFunction · 0.85

Calls 4

cbm_fopenFunction · 0.85
cbm_max_file_bytesFunction · 0.85
cbm_allocFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected