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

Function cgroup_test_write

tests/test_platform.c:1002–1025  ·  view source on GitHub ↗

Write `content` to " / ". Creates parent subdir if needed. * Returns 0 on success, -1 on any failure. */

Source from the content-addressed store, hash-verified

1000/* Write `content` to "<root>/<relpath>". Creates parent subdir if needed.
1001 * Returns 0 on success, -1 on any failure. */
1002static int cgroup_test_write(const char *root, const char *relpath, const char *content) {
1003 char path[1024];
1004 const char *slash = strchr(relpath, '/');
1005 if (slash != NULL) {
1006 char subdir[1024];
1007 size_t n = (size_t)(slash - relpath);
1008 if (n >= sizeof(subdir)) {
1009 return -1;
1010 }
1011 memcpy(subdir, relpath, n);
1012 subdir[n] = '\0';
1013 snprintf(path, sizeof(path), "%s/%s", root, subdir);
1014 (void)mkdir(path, S_IRWXU);
1015 }
1016 snprintf(path, sizeof(path), "%s/%s", root, relpath);
1017 FILE *fp = fopen(path, "we");
1018 if (fp == NULL) {
1019 return -1;
1020 }
1021 size_t n = strlen(content);
1022 int rc = (fwrite(content, 1, n, fp) == n) ? 0 : -1;
1023 fclose(fp);
1024 return rc;
1025}
1026
1027/* Recursively remove a tmp dir created by cgroup_test_setup. Best-effort.
1028 * Uses opendir/unlink/rmdir rather than system("rm -rf ...") to avoid

Callers 1

test_platform.cFile · 0.85

Calls 2

fopenFunction · 0.85
fwriteFunction · 0.85

Tested by

no test coverage detected