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

Function cli_config_cmd_capture

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

11991 * tmpfile+dup2+rewind is the file's established portable capture idiom —
11992 * pread/mkstemp/setenv do not exist on the MinGW leg. */
11993static int cli_config_cmd_capture(int argc, char **argv, char *out, size_t cap) {
11994 out[0] = '\0';
11995 FILE *capture = tmpfile();
11996 int saved = capture ? dup(fileno(stdout)) : -1;
11997 if (!capture || saved < 0) {
11998 if (capture)
11999 fclose(capture);
12000 if (saved >= 0)
12001 close(saved);
12002 return -1000;
12003 }
12004 fflush(stdout);
12005 if (dup2(fileno(capture), fileno(stdout)) < 0) {
12006 fclose(capture);
12007 close(saved);
12008 return -1000;
12009 }
12010 int rc = cbm_cmd_config(argc, argv);
12011 fflush(stdout);
12012 (void)dup2(saved, fileno(stdout));
12013 close(saved);
12014 rewind(capture);
12015 size_t got = fread(out, 1, cap - 1, capture);
12016 out[got] = '\0';
12017 fclose(capture);
12018 return rc;
12019}
12020
12021/* The user-facing config contract (#1522 bug 2): `get` of an UNSET key prints
12022 * 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