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

Function cte_read

tests/test_config_toml_edit.c:50–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50static int cte_read(const char *path, char *output, size_t output_size) {
51 if (!path || !output || output_size == 0) {
52 return -1;
53 }
54 FILE *file = cbm_fopen(path, "rb");
55 if (!file) {
56 return -1;
57 }
58 if (fseek(file, 0, SEEK_END) != 0) {
59 fclose(file);
60 return -1;
61 }
62 long raw_size = ftell(file);
63 if (raw_size < 0 || (size_t)raw_size >= output_size || fseek(file, 0, SEEK_SET) != 0) {
64 fclose(file);
65 return -1;
66 }
67 size_t size = (size_t)raw_size;
68 size_t read_count = size ? fread(output, 1, size, file) : 0;
69 int close_error = fclose(file);
70 if (read_count != size || close_error != 0) {
71 return -1;
72 }
73 output[size] = '\0';
74 return 0;
75}
76
77static int cte_occurrences(const char *text, const char *needle) {
78 int count = 0;

Calls 1

cbm_fopenFunction · 0.85

Tested by

no test coverage detected