Slurp a whole file into a heap buffer (NUL-terminated). NULL on error. */
| 66 | |
| 67 | /* Slurp a whole file into a heap buffer (NUL-terminated). NULL on error. */ |
| 68 | static char *ri_slurp(const char *path) { |
| 69 | FILE *f = fopen(path, "rb"); |
| 70 | if (!f) { |
| 71 | return NULL; |
| 72 | } |
| 73 | (void)fseek(f, 0, SEEK_END); |
| 74 | long n = ftell(f); |
| 75 | (void)fseek(f, 0, SEEK_SET); |
| 76 | if (n < 0) { |
| 77 | (void)fclose(f); |
| 78 | return NULL; |
| 79 | } |
| 80 | char *buf = (char *)malloc((size_t)n + 1); |
| 81 | if (!buf) { |
| 82 | (void)fclose(f); |
| 83 | return NULL; |
| 84 | } |
| 85 | size_t rd = fread(buf, 1, (size_t)n, f); |
| 86 | (void)fclose(f); |
| 87 | buf[rd] = '\0'; |
| 88 | return buf; |
| 89 | } |
| 90 | |
| 91 | /* Index the files already written under lp->tmpdir through the production MCP |
| 92 | * flow, capturing the raw response. Returns the opened graph store (NULL on |
no outgoing calls
no test coverage detected