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

Function cbm_build_win_cmd_payload

src/foundation/subprocess.c:358–398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358bool cbm_build_win_cmd_payload(char *buf, size_t cap, const char *cmd_executable,
359 const char *payload) {
360 if (!buf || cap == 0) {
361 return false;
362 }
363 buf[0] = '\0';
364 if (!cbm_win_cmd_path_is_absolute(cmd_executable) || !payload || !payload[0]) {
365 return false;
366 }
367
368 static const char prefix[] = "\" /D /S /V:OFF /C ";
369 size_t executable_len = strlen(cmd_executable);
370 size_t payload_len = strlen(payload);
371 size_t remaining = cap - 1; /* reserve the final NUL */
372 if (remaining < 1) {
373 return false;
374 }
375 remaining--; /* opening quote */
376 if (executable_len > remaining) {
377 return false;
378 }
379 remaining -= executable_len;
380 if (sizeof(prefix) - 1 > remaining) {
381 return false;
382 }
383 remaining -= sizeof(prefix) - 1;
384 if (payload_len > remaining) {
385 return false;
386 }
387
388 size_t pos = 0;
389 buf[pos++] = '"';
390 memcpy(buf + pos, cmd_executable, executable_len);
391 pos += executable_len;
392 memcpy(buf + pos, prefix, sizeof(prefix) - 1);
393 pos += sizeof(prefix) - 1;
394 memcpy(buf + pos, payload, payload_len);
395 pos += payload_len;
396 buf[pos] = '\0';
397 return true;
398}
399
400/* ── Nonblocking contained-process supervisor ─────────────────────────────── */
401

Callers 2

cbm_subprocess_spawn_winFunction · 0.85
test_subprocess.cFile · 0.85

Calls 1

Tested by

no test coverage detected