void free_all_right(t_bin *tmp) { t_bin *bfree; if (tmp->right) tmp = tmp->right; while (tmp->right) { bfree = tmp; tmp = tmp->right; free_part(bfree); } }
void free_bin(t_bin *bin) { t_bin *tmp; tmp = bin->head; while (tmp) { free_all_right(tmp); tmp = tmp->left; } tmp = bin->head; free_all_left(tmp); free_part(bin->head); }
void free_all_left(t_bin *tmp) { t_bin *bfree; if (tmp->left) tmp = tmp->left; else return ; while (tmp->left) { bfree = tmp; tmp = tmp->left; free_part(bfree); } }
static ssize_t multipart_read(hFILE *fpv, void *buffer, size_t nbytes) { hFILE_multipart *fp = (hFILE_multipart *) fpv; size_t n; open_next: if (fp->currentfp == NULL) { if (fp->current < fp->nparts) { const hfile_part *p = &fp->parts[fp->current]; hts_log_debug("Opening part #%zu of %zu: \"%.120s%s\"", fp->current+1, fp->nparts, p->url, (strlen(p->url) > 120)? "..." : ""); fp->currentfp = p->headers? hopen(p->url, "r:", "httphdr:v", p->headers, NULL) : hopen(p->url, "r"); if (fp->currentfp == NULL) return -1; } else return 0; // No more parts, so we're truly at EOF } n = fp->currentfp->mobile? fp->currentfp->backend->read(fp->currentfp, buffer, nbytes) : hread(fp->currentfp, buffer, nbytes); if (n == 0) { // We're at EOF on this part, so set up the next part hFILE *prevfp = fp->currentfp; free_part(&fp->parts[fp->current]); fp->current++; fp->currentfp = NULL; if (hclose(prevfp) < 0) return -1; goto open_next; } return n; // Number of bytes read by (or an error from) fp->currentfp }
static void free_all_parts(hFILE_multipart *fp) { size_t i; for (i = 0; i < fp->nparts; i++) free_part(&fp->parts[i]); free(fp->parts); }