| 141 | } |
| 142 | |
| 143 | static cbm_store_t *lrp_index(LRP_Proj *lp, const LRP_File *files, int nfiles) { |
| 144 | memset(lp, 0, sizeof(*lp)); |
| 145 | snprintf(lp->tmpdir, sizeof(lp->tmpdir), "/tmp/cbm_lrp_XXXXXX"); |
| 146 | if (!cbm_mkdtemp(lp->tmpdir)) return NULL; |
| 147 | lrp_to_fwd_slashes(lp->tmpdir); |
| 148 | for (int i = 0; i < nfiles; i++) { |
| 149 | char path[700]; |
| 150 | snprintf(path, sizeof(path), "%s/%s", lp->tmpdir, files[i].name); |
| 151 | char *slash = strrchr(path, '/'); |
| 152 | if (slash && slash > path + strlen(lp->tmpdir)) { |
| 153 | *slash = '\0'; |
| 154 | cbm_mkdir_p(path, 0755); |
| 155 | *slash = '/'; |
| 156 | } |
| 157 | FILE *f = fopen(path, "wb"); |
| 158 | if (!f) return NULL; |
| 159 | fputs(files[i].content, f); |
| 160 | fclose(f); |
| 161 | } |
| 162 | return lrp_open_indexed(lp); |
| 163 | } |
| 164 | |
| 165 | static void lrp_cleanup(LRP_Proj *lp, cbm_store_t *store) { |
| 166 | if (store) cbm_store_close(store); |
no test coverage detected