Read an entire file into a core-owned buffer (class extract; release with * cbm_free(CBM_MEM_CLASS_EXTRACT, ...)). Returns NULL on failure. */
| 37 | /* Read an entire file into a core-owned buffer (class extract; release with |
| 38 | * cbm_free(CBM_MEM_CLASS_EXTRACT, ...)). Returns NULL on failure. */ |
| 39 | static char *pkgmap_read_file(const char *path, int *out_len) { |
| 40 | FILE *f = cbm_fopen(path, "rb"); |
| 41 | if (!f) { |
| 42 | return NULL; |
| 43 | } |
| 44 | (void)fseek(f, 0, SEEK_END); |
| 45 | long size = ftell(f); |
| 46 | (void)fseek(f, 0, SEEK_SET); |
| 47 | if (size <= 0 || size > (long)CBM_SZ_1K * CBM_SZ_1K) { /* 1MB cap for manifests */ |
| 48 | (void)fclose(f); |
| 49 | return NULL; |
| 50 | } |
| 51 | char *buf = (char *)cbm_alloc(CBM_MEM_CLASS_EXTRACT, (size_t)size + SKIP_ONE); |
| 52 | if (!buf) { |
| 53 | (void)fclose(f); |
| 54 | return NULL; |
| 55 | } |
| 56 | size_t nread = fread(buf, SKIP_ONE, (size_t)size, f); |
| 57 | (void)fclose(f); |
| 58 | buf[nread] = '\0'; |
| 59 | *out_len = (int)nread; |
| 60 | return buf; |
| 61 | } |
| 62 | |
| 63 | /* ── Constants ─────────────────────────────────────────────────── */ |
| 64 |
no test coverage detected