static int file_archive_parse_file_init(file_archive_transfer_t *state, const char *file) { state->backend = file_archive_get_default_file_backend(); if (!state->backend) return -1; state->handle = file_archive_open(file); if (!state->handle) return -1; state->zip_size = file_archive_size(state->handle); if (state->zip_size < 22) return -1; state->data = file_archive_data(state->handle); state->footer = state->data + state->zip_size - 22; for (;; state->footer--) { if (state->footer <= state->data + 22) return -1; if (read_le(state->footer, 4) == END_OF_CENTRAL_DIR_SIGNATURE) { unsigned comment_len = read_le(state->footer + 20, 2); if (state->footer + 22 + comment_len == state->data + state->zip_size) break; } } state->directory = state->data + read_le(state->footer + 16, 4); return 0; }
static int file_archive_parse_file_init(file_archive_transfer_t *state, const char *file) { char path[PATH_MAX_LENGTH]; char *last = NULL; path[0] = '\0'; strlcpy(path, file, sizeof(path)); last = (char*)path_get_archive_delim(path); if (last) *last = '\0'; state->backend = file_archive_get_file_backend(path); if (!state->backend) return -1; state->handle = file_archive_open(path); if (!state->handle) return -1; state->archive_size = file_archive_size(state->handle); state->data = file_archive_data(state->handle); state->footer = 0; state->directory = 0; return state->backend->archive_parse_file_init(state, path); }