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

Function th_write_file

tests/test_helpers.h:41–66  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

39
40/* Write content to a file, creating parent directories as needed. */
41static inline int th_write_file(const char *path, const char *content) {
42 /* Create parent directories */
43 char dir[1024];
44 snprintf(dir, sizeof(dir), "%s", path);
45 char *last_slash = strrchr(dir, '/');
46#ifdef _WIN32
47 char *last_bslash = strrchr(dir, '\\');
48 if (last_bslash && (!last_slash || last_bslash > last_slash)) {
49 last_slash = last_bslash;
50 }
51#endif
52 if (last_slash) {
53 *last_slash = '\0';
54 cbm_mkdir_p(dir, 0755);
55 }
56
57 FILE *f = fopen(path, "w");
58 if (!f) {
59 return -1;
60 }
61 if (content && content[0]) {
62 fputs(content, f);
63 }
64 fclose(f);
65 return 0;
66}
67
68/* Append content to a file. */
69static 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
prune_fixture_setupFunction · 0.85
test_watcher.cFile · 0.85
ui_delete_make_db_fileFunction · 0.85
ui_delete_make_sidecarsFunction · 0.85
test_pipeline.cFile · 0.85
test_discover.cFile · 0.85
repro_issue520.cFile · 0.85

Calls 1

cbm_mkdir_pFunction · 0.85

Tested by

no test coverage detected