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

Function th_write_file

tests/test_helpers.h:45–70  ·  view source on GitHub ↗

Write content to a file, creating parent directories as needed. */

Source from the content-addressed store, hash-verified

43
44/* Write content to a file, creating parent directories as needed. */
45static inline int th_write_file(const char *path, const char *content) {
46 /* Create parent directories */
47 char dir[1024];
48 snprintf(dir, sizeof(dir), "%s", path);
49 char *last_slash = strrchr(dir, '/');
50#ifdef _WIN32
51 char *last_bslash = strrchr(dir, '\\');
52 if (last_bslash && (!last_slash || last_bslash > last_slash)) {
53 last_slash = last_bslash;
54 }
55#endif
56 if (last_slash) {
57 *last_slash = '\0';
58 cbm_mkdir_p(dir, 0755);
59 }
60
61 FILE *f = cbm_fopen(path, "wb");
62 if (!f) {
63 return -1;
64 }
65 if (content && content[0]) {
66 fputs(content, f);
67 }
68 fclose(f);
69 return 0;
70}
71
72/* Append content to a file. */
73static inline int th_append_file(const char *path, const char *content) {

Callers 15

make_git_repoFunction · 0.85
setup_sim_test_repoFunction · 0.85
test_simhash.cFile · 0.85
cte_change_before_commitFunction · 0.85
test_mcp.cFile · 0.85
prune_fixture_setupFunction · 0.85
test_watcher.cFile · 0.85
yaml_fixture_initFunction · 0.85

Calls 2

cbm_mkdir_pFunction · 0.85
cbm_fopenFunction · 0.85

Tested by

no test coverage detected