| 89 | } |
| 90 | |
| 91 | static cbm_store_t *mkc_index(MKC_Proj *lp, const MKC_File *files, int nfiles) { |
| 92 | memset(lp, 0, sizeof(*lp)); |
| 93 | snprintf(lp->tmpdir, sizeof(lp->tmpdir), "/tmp/cbm_mkc_XXXXXX"); |
| 94 | if (!cbm_mkdtemp(lp->tmpdir)) |
| 95 | return NULL; |
| 96 | mkc_to_fwd_slashes(lp->tmpdir); |
| 97 | for (int i = 0; i < nfiles; i++) { |
| 98 | char path[700]; |
| 99 | snprintf(path, sizeof(path), "%s/%s", lp->tmpdir, files[i].name); |
| 100 | char *slash = strrchr(path, '/'); |
| 101 | if (slash && slash > path + strlen(lp->tmpdir)) { |
| 102 | *slash = '\0'; |
| 103 | cbm_mkdir_p(path, 0755); |
| 104 | *slash = '/'; |
| 105 | } |
| 106 | FILE *f = fopen(path, "wb"); |
| 107 | if (!f) |
| 108 | return NULL; |
| 109 | fputs(files[i].content, f); |
| 110 | fclose(f); |
| 111 | } |
| 112 | return mkc_open_indexed(lp); |
| 113 | } |
| 114 | |
| 115 | static void mkc_cleanup(MKC_Proj *lp, cbm_store_t *store) { |
| 116 | if (store) |
no test coverage detected