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

Function cte_read

tests/test_config_toml_edit.c:82–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82static int cte_read(const char *path, char *output, size_t output_size) {
83 if (!path || !output || output_size == 0) {
84 return -1;
85 }
86 FILE *file = cbm_fopen(path, "rb");
87 if (!file) {
88 return -1;
89 }
90 if (fseek(file, 0, SEEK_END) != 0) {
91 fclose(file);
92 return -1;
93 }
94 long raw_size = ftell(file);
95 if (raw_size < 0 || (size_t)raw_size >= output_size || fseek(file, 0, SEEK_SET) != 0) {
96 fclose(file);
97 return -1;
98 }
99 size_t size = (size_t)raw_size;
100 size_t read_count = size ? fread(output, 1, size, file) : 0;
101 int close_error = fclose(file);
102 if (read_count != size || close_error != 0) {
103 return -1;
104 }
105 output[size] = '\0';
106 return 0;
107}
108
109static int cte_occurrences(const char *text, const char *needle) {
110 int count = 0;

Calls 1

cbm_fopenFunction · 0.85

Tested by

no test coverage detected