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

Function cgroup_test_write

tests/test_platform.c:147–170  ·  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

145/* Write `content` to "<root>/<relpath>". Creates parent subdir if needed.
146 * Returns 0 on success, -1 on any failure. */
147static int cgroup_test_write(const char *root, const char *relpath, const char *content) {
148 char path[1024];
149 const char *slash = strchr(relpath, '/');
150 if (slash != NULL) {
151 char subdir[1024];
152 size_t n = (size_t)(slash - relpath);
153 if (n >= sizeof(subdir)) {
154 return -1;
155 }
156 memcpy(subdir, relpath, n);
157 subdir[n] = '\0';
158 snprintf(path, sizeof(path), "%s/%s", root, subdir);
159 (void)mkdir(path, S_IRWXU);
160 }
161 snprintf(path, sizeof(path), "%s/%s", root, relpath);
162 FILE *fp = fopen(path, "we");
163 if (fp == NULL) {
164 return -1;
165 }
166 size_t n = strlen(content);
167 int rc = (fwrite(content, 1, n, fp) == n) ? 0 : -1;
168 fclose(fp);
169 return rc;
170}
171
172/* Recursively remove a tmp dir created by cgroup_test_setup. Best-effort.
173 * Uses opendir/unlink/rmdir rather than system("rm -rf ...") to avoid

Callers 1

test_platform.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected