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

Function dk_read

src/pipeline/pass_docker.c:1439–1462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1437}
1438
1439static char *dk_read(const char *path, size_t *len) {
1440 FILE *f = cbm_fopen(path, "rb");
1441 if (!f) {
1442 return NULL;
1443 }
1444 (void)fseek(f, 0, SEEK_END);
1445 long size = ftell(f);
1446 (void)fseek(f, 0, SEEK_SET);
1447 if (size <= 0 || size > cbm_max_file_bytes()) {
1448 (void)fclose(f);
1449 return NULL;
1450 }
1451 enum { DK_TS_PAD = 16 }; /* tree-sitter's lexer reads past the end */
1452 char *buf = cbm_alloc(CBM_MEM_CLASS_OTHER, (size_t)size + DK_TS_PAD);
1453 if (!buf) {
1454 (void)fclose(f);
1455 return NULL;
1456 }
1457 size_t got = fread(buf, SKIP_ONE, (size_t)size, f);
1458 (void)fclose(f);
1459 memset(buf + got, 0, DK_TS_PAD);
1460 *len = got;
1461 return buf;
1462}
1463
1464/* Does the line [b, e) hold a parser directive `# escape=...`? */
1465static bool dk_escape_directive(const char *s, size_t b, size_t e) {

Callers 4

dk_ignore_addFunction · 0.85
dk_read_dotenvFunction · 0.85
dk_link_buildsFunction · 0.85
cbm_pipeline_pass_dockerFunction · 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