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

Function cbm_subprocess_copy_opts

src/foundation/subprocess.c:654–779  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654static cbm_subprocess_t *cbm_subprocess_copy_opts(const cbm_proc_opts_t *opts) {
655 if (!opts || !opts->bin || !opts->bin[0]) {
656 return NULL;
657 }
658 if (opts->stdout_file && (!opts->stdout_file[0] ||
659 (opts->log_file && strcmp(opts->stdout_file, opts->log_file) == 0))) {
660 return NULL;
661 }
662 if (opts->stdin_file &&
663 (!opts->stdin_file[0] ||
664 (opts->log_file && strcmp(opts->stdin_file, opts->log_file) == 0) ||
665 (opts->stdout_file && strcmp(opts->stdin_file, opts->stdout_file) == 0))) {
666 return NULL;
667 }
668#ifdef _WIN32
669 if (opts->windows_cmd_payload &&
670 (!opts->windows_cmd_payload[0] || opts->argv || !cbm_win_cmd_path_is_absolute(opts->bin))) {
671 return NULL;
672 }
673#else
674 if (opts->windows_cmd_payload) {
675 return NULL;
676 }
677#endif
678
679 size_t override_count = 0;
680 if (opts->env_overrides) {
681 while (override_count < CBM_SUBPROCESS_ARGV_LIMIT && opts->env_overrides[override_count]) {
682 const char *entry = opts->env_overrides[override_count];
683 const char *equals = strchr(entry, '=');
684 if (!equals || equals == entry) {
685 return NULL;
686 }
687 override_count++;
688 }
689 if (override_count == CBM_SUBPROCESS_ARGV_LIMIT) {
690 return NULL;
691 }
692 }
693
694 size_t argc = 1;
695 if (opts->argv) {
696 argc = 0;
697 while (argc < CBM_SUBPROCESS_ARGV_LIMIT && opts->argv[argc]) {
698 argc++;
699 }
700 if (argc == 0 || argc == CBM_SUBPROCESS_ARGV_LIMIT) {
701 return NULL;
702 }
703 }
704
705 cbm_subprocess_t *process = (cbm_subprocess_t *)calloc(1, sizeof(*process));
706 if (!process) {
707 return NULL;
708 }
709 cbm_arena_init_lazy(&process->stdout_arena, 256);
710 process->bin = cbm_strdup(opts->bin);
711 process->windows_cmd_payload =

Callers 1

cbm_subprocess_spawnFunction · 0.85

Calls 7

cbm_arena_init_lazyFunction · 0.85
cbm_git_child_envpFunction · 0.85
cbm_arena_strdupFunction · 0.70

Tested by

no test coverage detected