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

Function cli_slurp_stream

src/main.c:785–811  ·  view source on GitHub ↗

Read an open stream fully into a heap, NUL-terminated string. Caller frees. * Returns NULL on allocation failure. Reads binary-clean (UTF-8 JSON, no shell * quoting needed). */

Source from the content-addressed store, hash-verified

783 * Returns NULL on allocation failure. Reads binary-clean (UTF-8 JSON, no shell
784 * quoting needed). */
785static char *cli_slurp_stream(FILE *f) {
786 size_t cap = CLI_SLURP_CHUNK;
787 size_t len = 0;
788 char *buf = malloc(cap);
789 if (!buf) {
790 return NULL;
791 }
792 char tmp[CLI_SLURP_CHUNK];
793 size_t n;
794 while ((n = fread(tmp, 1, sizeof(tmp), f)) > 0) {
795 if (len + n + 1 > cap) {
796 while (len + n + 1 > cap) {
797 cap *= 2;
798 }
799 char *nb = realloc(buf, cap);
800 if (!nb) {
801 free(buf);
802 return NULL;
803 }
804 buf = nb;
805 }
806 memcpy(buf + len, tmp, n);
807 len += n;
808 }
809 buf[len] = '\0';
810 return buf;
811}
812
813/* Slurp a file path into a heap, NUL-terminated string. Caller frees. */
814static char *cli_slurp_file(const char *path) {

Callers 2

cli_slurp_fileFunction · 0.85
run_cliFunction · 0.85

Calls 1

freadFunction · 0.85

Tested by

no test coverage detected