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

Function write_json_file

src/cli/cli.c:758–788  ·  view source on GitHub ↗

Write a mutable yyjson document to a file with pretty printing. */

Source from the content-addressed store, hash-verified

756
757/* Write a mutable yyjson document to a file with pretty printing. */
758static int write_json_file(const char *path, yyjson_mut_doc *doc) {
759 /* Ensure parent directory exists */
760 char dir[CLI_BUF_1K];
761 snprintf(dir, sizeof(dir), "%s", path);
762 char *last_slash = strrchr(dir, '/');
763 if (last_slash) {
764 *last_slash = '\0';
765 mkdirp(dir, DIR_PERMS);
766 }
767
768 yyjson_write_flag flags = YYJSON_WRITE_PRETTY | YYJSON_WRITE_ESCAPE_UNICODE;
769 size_t len;
770 char *json = yyjson_mut_write(doc, flags, &len);
771 if (!json) {
772 return CLI_ERR;
773 }
774
775 FILE *f = fopen(path, "w");
776 if (!f) {
777 free(json);
778 return CLI_ERR;
779 }
780
781 size_t written = fwrite(json, CLI_ELEM_SIZE, len, f);
782 /* Add trailing newline */
783 (void)fputc('\n', f);
784 (void)fclose(f);
785 free(json);
786
787 return written == len ? 0 : CLI_ERR;
788}
789
790/* ── Editor MCP: Cursor/Windsurf/Gemini (mcpServers key) ──────── */
791

Callers 12

cbm_install_editor_mcpFunction · 0.85
cbm_remove_editor_mcpFunction · 0.85
cbm_install_openclaw_mcpFunction · 0.85
cbm_remove_openclaw_mcpFunction · 0.85
cbm_install_vscode_mcpFunction · 0.85
cbm_remove_vscode_mcpFunction · 0.85
cbm_install_zed_mcpFunction · 0.85
cbm_remove_zed_mcpFunction · 0.85
cbm_upsert_opencode_mcpFunction · 0.85
cbm_remove_opencode_mcpFunction · 0.85
upsert_hooks_jsonFunction · 0.85
remove_hooks_jsonFunction · 0.85

Calls 1

mkdirpFunction · 0.85

Tested by

no test coverage detected