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

Function cli_config_cmd_capture

tests/test_cli.c:14774–14800  ·  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

14772 * tmpfile+dup2+rewind is the file's established portable capture idiom —
14773 * pread/mkstemp/setenv do not exist on the MinGW leg. */
14774static int cli_config_cmd_capture(int argc, char **argv, char *out, size_t cap) {
14775 out[0] = '\0';
14776 FILE *capture = tmpfile();
14777 int saved = capture ? dup(fileno(stdout)) : -1;
14778 if (!capture || saved < 0) {
14779 if (capture)
14780 fclose(capture);
14781 if (saved >= 0)
14782 close(saved);
14783 return -1000;
14784 }
14785 fflush(stdout);
14786 if (dup2(fileno(capture), fileno(stdout)) < 0) {
14787 fclose(capture);
14788 close(saved);
14789 return -1000;
14790 }
14791 int rc = cbm_cmd_config(argc, argv);
14792 fflush(stdout);
14793 (void)dup2(saved, fileno(stdout));
14794 close(saved);
14795 rewind(capture);
14796 size_t got = fread(out, 1, cap - 1, capture);
14797 out[got] = '\0';
14798 fclose(capture);
14799 return rc;
14800}
14801
14802/* The user-facing config contract (#1522 bug 2): `get` of an UNSET key prints
14803 * that key's real default — the same fallback the runtime readers use — with

Callers 1

test_cli.cFile · 0.85

Calls 1

cbm_cmd_configFunction · 0.85

Tested by

no test coverage detected