static int add_data(struct zip *za, struct zip_source *zs, struct zip_dirent *de, FILE *ft) { off_t offstart, offend; zip_source_callback cb; void *ud; struct zip_stat st; cb = zs->f; ud = zs->ud; if (cb(ud, &st, sizeof(st), ZIP_SOURCE_STAT) < (ssize_t)sizeof(st)) { ch_set_error(&za->error, cb, ud); return -1; } if (cb(ud, NULL, 0, ZIP_SOURCE_OPEN) < 0) { ch_set_error(&za->error, cb, ud); return -1; } offstart = ftello(ft); if (_zip_dirent_write(de, ft, 1, &za->error) < 0) return -1; if (st.comp_method != ZIP_CM_STORE) { if (add_data_comp(cb, ud, &st, ft, &za->error) < 0) return -1; } else { if (add_data_uncomp(za, cb, ud, &st, ft) < 0) return -1; } if (cb(ud, NULL, 0, ZIP_SOURCE_CLOSE) < 0) { ch_set_error(&za->error, cb, ud); return -1; } offend = ftello(ft); if (fseeko(ft, offstart, SEEK_SET) < 0) { _zip_error_set(&za->error, ZIP_ER_SEEK, errno); return -1; } de->last_mod = st.mtime; de->comp_method = st.comp_method; de->crc = st.crc; de->uncomp_size = (unsigned int)st.size; de->comp_size = (unsigned int)st.comp_size; if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0)) _zip_dirent_torrent_normalize(de); if (_zip_dirent_write(de, ft, 1, &za->error) < 0) return -1; if (fseeko(ft, offend, SEEK_SET) < 0) { _zip_error_set(&za->error, ZIP_ER_SEEK, errno); return -1; } return 0; }
static int add_data(struct zip *za, int idx, struct zip_dirent *de, FILE *ft) { off_t offstart, offend; zip_source_callback cb; void *ud; struct zip_stat st; cb = za->entry[idx].source->f; ud = za->entry[idx].source->ud; if (cb(ud, &st, sizeof(st), ZIP_SOURCE_STAT) < sizeof(st)) { ch_set_error(&za->error, cb, ud); return -1; } if (cb(ud, NULL, 0, ZIP_SOURCE_OPEN) < 0) { ch_set_error(&za->error, cb, ud); return -1; } offstart = ftell(ft); if (_zip_dirent_write(de, ft, 1, &za->error) < 0) return -1; if (st.comp_method != ZIP_CM_STORE) { if (add_data_comp(cb, ud, &st, ft, &za->error) < 0) return -1; } else { if (add_data_uncomp(cb, ud, &st, ft, &za->error) < 0) return -1; } if (cb(ud, NULL, 0, ZIP_SOURCE_CLOSE) < 0) { ch_set_error(&za->error, cb, ud); return -1; } offend = ftell(ft); if (fseek(ft, offstart, SEEK_SET) < 0) { _zip_error_set(&za->error, ZIP_ER_SEEK, errno); return -1; } de->comp_method = st.comp_method; de->last_mod = st.mtime; de->crc = st.crc; de->uncomp_size = st.size; de->comp_size = st.comp_size; if (_zip_dirent_write(de, ft, 1, &za->error) < 0) return -1; if (fseek(ft, offend, SEEK_SET) < 0) { _zip_error_set(&za->error, ZIP_ER_SEEK, errno); return -1; } return 0; }