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:350–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

cbm_subprocess_spawn_winFunction · 0.85
test_subprocess.cFile · 0.85

Calls 1

Tested by

no test coverage detected