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

Function read_small_file

src/foundation/system_info.c:124–136  ·  view source on GitHub ↗

Read up to (bufsz-1) bytes from `path` into `buf`, NUL-terminate, and strip * trailing whitespace. Returns the (stripped) byte count, or -1 if the file * could not be opened or read. */

Source from the content-addressed store, hash-verified

122 * trailing whitespace. Returns the (stripped) byte count, or -1 if the file
123 * could not be opened or read. */
124static int read_small_file(const char *path, char *buf, size_t bufsz) {
125 FILE *fp = fopen(path, "re");
126 if (fp == NULL) {
127 return -1;
128 }
129 size_t n = fread(buf, 1, bufsz - 1, fp);
130 fclose(fp);
131 while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == ' ' || buf[n - 1] == '\t')) {
132 n--;
133 }
134 buf[n] = '\0';
135 return (int)n;
136}
137
138/* Effective CPU count from a cgroup file tree. See header for contract. */
139int cbm_detect_cgroup_cpus(const char *cgroup_root) {

Callers 2

cbm_detect_cgroup_cpusFunction · 0.85
cbm_detect_cgroup_memFunction · 0.85

Calls 2

fopenFunction · 0.85
freadFunction · 0.85

Tested by

no test coverage detected