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

Function cli_config_cmd_capture

tests/test_cli.c:16613–16639  ·  view source on GitHub ↗

Capture stdout across one cbm_cmd_config invocation. Returns the command's * rc and copies captured stdout (NUL-terminated, truncated to cap) out. * tmpfile+dup2+rewind is the file's established portable capture idiom — * pread/mkstemp/setenv do not exist on the MinGW leg. */

Source from the content-addressed store, hash-verified

16611 * tmpfile+dup2+rewind is the file's established portable capture idiom —
16612 * pread/mkstemp/setenv do not exist on the MinGW leg. */
16613static int cli_config_cmd_capture(int argc, char **argv, char *out, size_t cap) {
16614 out[0] = '\0';
16615 FILE *capture = tmpfile();
16616 int saved = capture ? dup(fileno(stdout)) : -1;
16617 if (!capture || saved < 0) {
16618 if (capture)
16619 fclose(capture);
16620 if (saved >= 0)
16621 close(saved);
16622 return -1000;
16623 }
16624 fflush(stdout);
16625 if (dup2(fileno(capture), fileno(stdout)) < 0) {
16626 fclose(capture);
16627 close(saved);
16628 return -1000;
16629 }
16630 int rc = cbm_cmd_config(argc, argv);
16631 fflush(stdout);
16632 (void)dup2(saved, fileno(stdout));
16633 close(saved);
16634 rewind(capture);
16635 size_t got = fread(out, 1, cap - 1, capture);
16636 out[got] = '\0';
16637 fclose(capture);
16638 return rc;
16639}
16640
16641/* The user-facing config contract (#1522 bug 2): `get` of an UNSET key prints
16642 * that key's real default — the same fallback the runtime readers use — with

Callers 1

test_cli.cFile · 0.85

Calls 3

cbm_cmd_configFunction · 0.85
freadFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected