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

Function cte_read

tests/test_config_toml_edit.c:84–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Calls 2

cbm_fopenFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected