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