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

Function cbm_subprocess_copy_opts

src/foundation/subprocess.c:464–531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462}
463
464static cbm_subprocess_t *cbm_subprocess_copy_opts(const cbm_proc_opts_t *opts) {
465 if (!opts || !opts->bin || !opts->bin[0]) {
466 return NULL;
467 }
468#ifdef _WIN32
469 if (opts->windows_cmd_payload &&
470 (!opts->windows_cmd_payload[0] || opts->argv || !cbm_win_cmd_path_is_absolute(opts->bin))) {
471 return NULL;
472 }
473#else
474 if (opts->windows_cmd_payload) {
475 return NULL;
476 }
477#endif
478
479 size_t argc = 1;
480 if (opts->argv) {
481 argc = 0;
482 while (argc < CBM_SUBPROCESS_ARGV_LIMIT && opts->argv[argc]) {
483 argc++;
484 }
485 if (argc == 0 || argc == CBM_SUBPROCESS_ARGV_LIMIT) {
486 return NULL;
487 }
488 }
489
490 cbm_subprocess_t *process = (cbm_subprocess_t *)calloc(1, sizeof(*process));
491 if (!process) {
492 return NULL;
493 }
494 process->bin = cbm_strdup(opts->bin);
495 process->windows_cmd_payload =
496 opts->windows_cmd_payload ? cbm_strdup(opts->windows_cmd_payload) : NULL;
497 process->argv = (char **)calloc(argc + 1, sizeof(*process->argv));
498 process->argc = argc;
499 if (!process->bin || !process->argv ||
500 (opts->windows_cmd_payload && !process->windows_cmd_payload)) {
501 cbm_subprocess_free_config(process);
502 return NULL;
503 }
504 for (size_t i = 0; i < argc; i++) {
505 const char *arg = opts->argv ? opts->argv[i] : opts->bin;
506 process->argv[i] = cbm_strdup(arg);
507 if (!process->argv[i]) {
508 cbm_subprocess_free_config(process);
509 return NULL;
510 }
511 }
512 if (opts->log_file) {
513 process->log_file = cbm_strdup(opts->log_file);
514 if (!process->log_file) {
515 cbm_subprocess_free_config(process);
516 return NULL;
517 }
518 }
519 process->on_log_line = opts->on_log_line;
520 process->log_ud = opts->log_ud;
521 process->quiet_timeout_ms = opts->quiet_timeout_ms;

Callers 1

cbm_subprocess_spawnFunction · 0.85

Calls 3

Tested by

no test coverage detected