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. */
| 122 | * trailing whitespace. Returns the (stripped) byte count, or -1 if the file |
| 123 | * could not be opened or read. */ |
| 124 | static 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. */ |
| 139 | int cbm_detect_cgroup_cpus(const char *cgroup_root) { |
no test coverage detected