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