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

Function scan_fixture_add

tests/test_mcp.c:24597–24616  ·  view source on GitHub ↗

Add a file holding exactly `length` bytes (NUL bytes allowed). */

Source from the content-addressed store, hash-verified

24595
24596/* Add a file holding exactly `length` bytes (NUL bytes allowed). */
24597static bool scan_fixture_add(scan_fixture_t *fx, const char *name, const char *data,
24598 size_t length) {
24599 if (fx->count >= 4) {
24600 return false;
24601 }
24602 /* Format from a copy: GCC's -Werror=restrict rejects a source and a
24603 * destination inside the same struct. */
24604 char dir[sizeof(fx->dir)];
24605 memcpy(dir, fx->dir, sizeof(dir));
24606 char *path = fx->files[fx->count];
24607 snprintf(path, sizeof(fx->files[0]), "%s/%s", dir, name);
24608 FILE *fp = cbm_fopen(path, "wb");
24609 if (!fp) {
24610 return false;
24611 }
24612 bool ok = fwrite(data, 1, length, fp) == length;
24613 ok = fclose(fp) == 0 && ok;
24614 fx->count += ok ? 1 : 0;
24615 return ok;
24616}
24617
24618/* Write the scoped file list as search_code does (NUL records on POSIX,
24619 * lines on Windows); `extra` names one more path that need not exist. */

Callers 1

test_mcp.cFile · 0.85

Calls 2

cbm_fopenFunction · 0.85
fwriteFunction · 0.85

Tested by

no test coverage detected