From: Tobias Stoeckmann Date: Sat, 18 Jul 2026 17:39:41 +0000 (+0200) Subject: Unify format data access names X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6c3bab2480877bd20f574b1f2f8bcbbf2a3d2bdb;p=thirdparty%2Flibarchive.git Unify format data access names It's generally the pattern "struct format *format". Unify for easier readability. Signed-off-by: Tobias Stoeckmann --- diff --git a/libarchive/archive_read_support_format_rar5.c b/libarchive/archive_read_support_format_rar5.c index 517054e4e..cd46a6d2d 100644 --- a/libarchive/archive_read_support_format_rar5.c +++ b/libarchive/archive_read_support_format_rar5.c @@ -372,10 +372,10 @@ struct rar5 { static void rar5_signature(char *buf); static int verify_global_checksums(struct archive_read* a); static int rar5_read_data_skip(struct archive_read *a); -static int push_data_ready(struct archive_read* a, struct rar5* rar, +static int push_data_ready(struct archive_read* a, struct rar5 *rar5, const uint8_t* buf, size_t size, int64_t offset); -static void clear_data_ready_stack(struct rar5* rar); -static void rar5_deinit(struct rar5* rar); +static void clear_data_ready_stack(struct rar5 *rar5); +static void rar5_deinit(struct rar5 *rar5); /* CDE_xxx = Circular Double Ended (Queue) return values. */ enum CDE_RETURN_VALUES { @@ -529,28 +529,28 @@ static void circular_memcpy(uint8_t* dst, uint8_t* window, const ssize_t mask, } } -static uint32_t read_filter_data(struct rar5* rar, uint32_t offset) { +static uint32_t read_filter_data(struct rar5 *rar5, uint32_t offset) { uint8_t linear_buf[4]; - circular_memcpy(linear_buf, rar->cstate.window_buf, - rar->cstate.window_mask, offset, offset + 4); + circular_memcpy(linear_buf, rar5->cstate.window_buf, + rar5->cstate.window_mask, offset, offset + 4); return archive_le32dec(linear_buf); } -static void write_filter_data(struct rar5* rar, uint32_t offset, +static void write_filter_data(struct rar5 *rar5, uint32_t offset, uint32_t value) { - archive_le32enc(&rar->cstate.filtered_buf[offset], value); + archive_le32enc(&rar5->cstate.filtered_buf[offset], value); } /* Allocates a new filter descriptor and adds it to the filter array. */ -static struct filter_info* add_new_filter(struct rar5* rar) { +static struct filter_info* add_new_filter(struct rar5 *rar5) { struct filter_info* f = calloc(1, sizeof(*f)); if(!f) { return NULL; } - if (CDE_OK != cdeque_push_back(&rar->cstate.filters, cdeque_filter(f))) { + if (CDE_OK != cdeque_push_back(&rar5->cstate.filters, cdeque_filter(f))) { free(f); return NULL; } @@ -558,7 +558,7 @@ static struct filter_info* add_new_filter(struct rar5* rar) { return f; } -static int run_delta_filter(struct rar5* rar, struct filter_info* flt) { +static int run_delta_filter(struct rar5 *rar5, struct filter_info* flt) { int i; ssize_t dest_pos, src_pos = 0; @@ -570,12 +570,12 @@ static int run_delta_filter(struct rar5* rar, struct filter_info* flt) { { uint8_t byte; - byte = rar->cstate.window_buf[ - (rar->cstate.solid_offset + flt->block_start + - src_pos) & rar->cstate.window_mask]; + byte = rar5->cstate.window_buf[ + (rar5->cstate.solid_offset + flt->block_start + + src_pos) & rar5->cstate.window_mask]; prev_byte -= byte; - rar->cstate.filtered_buf[dest_pos] = prev_byte; + rar5->cstate.filtered_buf[dest_pos] = prev_byte; src_pos++; } } @@ -583,21 +583,21 @@ static int run_delta_filter(struct rar5* rar, struct filter_info* flt) { return ARCHIVE_OK; } -static int run_e8e9_filter(struct rar5* rar, struct filter_info* flt, +static int run_e8e9_filter(struct rar5 *rar5, struct filter_info* flt, int extended) { const uint32_t file_size = 0x1000000; ssize_t i; - circular_memcpy(rar->cstate.filtered_buf, - rar->cstate.window_buf, rar->cstate.window_mask, - rar->cstate.solid_offset + flt->block_start, - rar->cstate.solid_offset + flt->block_start + flt->block_length); + circular_memcpy(rar5->cstate.filtered_buf, + rar5->cstate.window_buf, rar5->cstate.window_mask, + rar5->cstate.solid_offset + flt->block_start, + rar5->cstate.solid_offset + flt->block_start + flt->block_length); for(i = 0; i < flt->block_length - 4;) { - uint8_t b = rar->cstate.window_buf[ - (rar->cstate.solid_offset + flt->block_start + - i++) & rar->cstate.window_mask]; + uint8_t b = rar5->cstate.window_buf[ + (rar5->cstate.solid_offset + flt->block_start + + i++) & rar5->cstate.window_mask]; /* * 0xE8 = x86's call (function call) @@ -608,19 +608,19 @@ static int run_e8e9_filter(struct rar5* rar, struct filter_info* flt, uint32_t addr; uint32_t offset = (i + flt->block_start) % file_size; - addr = read_filter_data(rar, - (uint32_t)(rar->cstate.solid_offset + - flt->block_start + i) & rar->cstate.window_mask); + addr = read_filter_data(rar5, + (uint32_t)(rar5->cstate.solid_offset + + flt->block_start + i) & rar5->cstate.window_mask); if(addr & 0x80000000) { if(((addr + offset) & 0x80000000) == 0) { - write_filter_data(rar, (uint32_t)i, + write_filter_data(rar5, (uint32_t)i, addr + file_size); } } else { if((addr - file_size) & 0x80000000) { uint32_t naddr = addr - offset; - write_filter_data(rar, (uint32_t)i, + write_filter_data(rar5, (uint32_t)i, naddr); } } @@ -632,29 +632,29 @@ static int run_e8e9_filter(struct rar5* rar, struct filter_info* flt, return ARCHIVE_OK; } -static int run_arm_filter(struct rar5* rar, struct filter_info* flt) { +static int run_arm_filter(struct rar5 *rar5, struct filter_info* flt) { ssize_t i = 0; uint32_t offset; - circular_memcpy(rar->cstate.filtered_buf, - rar->cstate.window_buf, rar->cstate.window_mask, - rar->cstate.solid_offset + flt->block_start, - rar->cstate.solid_offset + flt->block_start + flt->block_length); + circular_memcpy(rar5->cstate.filtered_buf, + rar5->cstate.window_buf, rar5->cstate.window_mask, + rar5->cstate.solid_offset + flt->block_start, + rar5->cstate.solid_offset + flt->block_start + flt->block_length); for(i = 0; i < flt->block_length - 3; i += 4) { - uint8_t* b = &rar->cstate.window_buf[ - (rar->cstate.solid_offset + - flt->block_start + i + 3) & rar->cstate.window_mask]; + uint8_t* b = &rar5->cstate.window_buf[ + (rar5->cstate.solid_offset + + flt->block_start + i + 3) & rar5->cstate.window_mask]; if(*b == 0xEB) { /* 0xEB = ARM's BL (branch + link) instruction. */ - offset = read_filter_data(rar, - (rar->cstate.solid_offset + flt->block_start + i) & - (uint32_t)rar->cstate.window_mask) & 0x00ffffff; + offset = read_filter_data(rar5, + (rar5->cstate.solid_offset + flt->block_start + i) & + (uint32_t)rar5->cstate.window_mask) & 0x00ffffff; offset -= (uint32_t) ((i + flt->block_start) / 4); offset = (offset & 0x00ffffff) | 0xeb000000; - write_filter_data(rar, (uint32_t)i, offset); + write_filter_data(rar5, (uint32_t)i, offset); } } @@ -662,14 +662,14 @@ static int run_arm_filter(struct rar5* rar, struct filter_info* flt) { } static int run_filter(struct archive_read* a, struct filter_info* flt) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int ret; - clear_data_ready_stack(rar); - free(rar->cstate.filtered_buf); + clear_data_ready_stack(rar5); + free(rar5->cstate.filtered_buf); - rar->cstate.filtered_buf = malloc(flt->block_length); - if(!rar->cstate.filtered_buf) { + rar5->cstate.filtered_buf = malloc(flt->block_length); + if(!rar5->cstate.filtered_buf) { archive_set_error(&a->archive, ENOMEM, "Can't allocate memory for filter data"); return ARCHIVE_FATAL; @@ -677,18 +677,18 @@ static int run_filter(struct archive_read* a, struct filter_info* flt) { switch(flt->type) { case FILTER_DELTA: - ret = run_delta_filter(rar, flt); + ret = run_delta_filter(rar5, flt); break; case FILTER_E8: /* fallthrough */ case FILTER_E8E9: - ret = run_e8e9_filter(rar, flt, + ret = run_e8e9_filter(rar5, flt, flt->type == FILTER_E8E9); break; case FILTER_ARM: - ret = run_arm_filter(rar, flt); + ret = run_arm_filter(rar5, flt); break; default: @@ -704,8 +704,8 @@ static int run_filter(struct archive_read* a, struct filter_info* flt) { return ret; } - if(ARCHIVE_OK != push_data_ready(a, rar, rar->cstate.filtered_buf, - flt->block_length, rar->cstate.last_write_ptr)) + if(ARCHIVE_OK != push_data_ready(a, rar5, rar5->cstate.filtered_buf, + flt->block_length, rar5->cstate.last_write_ptr)) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Stack overflow when submitting unpacked data"); @@ -713,7 +713,7 @@ static int run_filter(struct archive_read* a, struct filter_info* flt) { return ARCHIVE_FATAL; } - rar->cstate.last_write_ptr += flt->block_length; + rar5->cstate.last_write_ptr += flt->block_length; return ARCHIVE_OK; } @@ -721,15 +721,15 @@ static int run_filter(struct archive_read* a, struct filter_info* flt) { * Next call of `use_data` will use the pointer, size and offset arguments * that are specified here. These arguments are pushed to the FIFO stack here, * and popped from the stack by the `use_data` function. */ -static void push_data(struct archive_read* a, struct rar5* rar, +static void push_data(struct archive_read* a, struct rar5 *rar5, const uint8_t* buf, int64_t idx_begin, int64_t idx_end) { - const ssize_t wmask = rar->cstate.window_mask; - const ssize_t solid_write_ptr = (rar->cstate.solid_offset + - rar->cstate.last_write_ptr) & wmask; + const ssize_t wmask = rar5->cstate.window_mask; + const ssize_t solid_write_ptr = (rar5->cstate.solid_offset + + rar5->cstate.last_write_ptr) & wmask; - idx_begin += rar->cstate.solid_offset; - idx_end += rar->cstate.solid_offset; + idx_begin += rar5->cstate.solid_offset; + idx_end += rar5->cstate.solid_offset; /* Check if our unpacked data is wrapped inside the window circular * buffer. If it's not wrapped, it can be copied out by using @@ -739,57 +739,57 @@ static void push_data(struct archive_read* a, struct rar5* rar, if((idx_begin & wmask) > (idx_end & wmask)) { /* The data is wrapped (begin offset sis bigger than end * offset). */ - const ssize_t frag1_size = rar->cstate.window_size - + const ssize_t frag1_size = rar5->cstate.window_size - (idx_begin & wmask); const ssize_t frag2_size = idx_end & wmask; /* Copy the first part of the buffer first. */ - push_data_ready(a, rar, buf + solid_write_ptr, frag1_size, - rar->cstate.last_write_ptr); + push_data_ready(a, rar5, buf + solid_write_ptr, frag1_size, + rar5->cstate.last_write_ptr); /* Copy the second part of the buffer. */ - push_data_ready(a, rar, buf, frag2_size, - rar->cstate.last_write_ptr + frag1_size); + push_data_ready(a, rar5, buf, frag2_size, + rar5->cstate.last_write_ptr + frag1_size); - rar->cstate.last_write_ptr += frag1_size + frag2_size; + rar5->cstate.last_write_ptr += frag1_size + frag2_size; } else { /* Data is not wrapped, so we can just use one call to copy the * data. */ - push_data_ready(a, rar, + push_data_ready(a, rar5, buf + solid_write_ptr, (idx_end - idx_begin) & wmask, - rar->cstate.last_write_ptr); + rar5->cstate.last_write_ptr); - rar->cstate.last_write_ptr += idx_end - idx_begin; + rar5->cstate.last_write_ptr += idx_end - idx_begin; } } /* Convenience function that submits the data to the user. It uses the * unpack window buffer as a source location. */ -static void push_window_data(struct archive_read* a, struct rar5* rar, +static void push_window_data(struct archive_read* a, struct rar5 *rar5, int64_t idx_begin, int64_t idx_end) { - push_data(a, rar, rar->cstate.window_buf, idx_begin, idx_end); + push_data(a, rar5, rar5->cstate.window_buf, idx_begin, idx_end); } static int apply_filters(struct archive_read* a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; struct filter_info* flt; int ret; - rar->cstate.all_filters_applied = 0; + rar5->cstate.all_filters_applied = 0; /* Get the first filter that can be applied to our data. The data * needs to be fully unpacked before the filter can be run. */ - if(CDE_OK == cdeque_front(&rar->cstate.filters, + if(CDE_OK == cdeque_front(&rar5->cstate.filters, cdeque_filter_p(&flt))) { /* Check if our unpacked data fully covers this filter's * range. */ - if(rar->cstate.write_ptr > flt->block_start && - rar->cstate.write_ptr >= flt->block_start + + if(rar5->cstate.write_ptr > flt->block_start && + rar5->cstate.write_ptr >= flt->block_start + flt->block_length) { /* Check if we have some data pending to be written * right before the filter's start offset. */ - if(rar->cstate.last_write_ptr == flt->block_start) { + if(rar5->cstate.last_write_ptr == flt->block_start) { /* Run the filter specified by descriptor * `flt`. */ ret = run_filter(a, flt); @@ -801,15 +801,15 @@ static int apply_filters(struct archive_read* a) { /* Filter descriptor won't be needed anymore * after it's used, * so remove it from the * filter list and free its memory. */ - (void) cdeque_pop_front(&rar->cstate.filters, + (void) cdeque_pop_front(&rar5->cstate.filters, cdeque_filter_p(&flt)); free(flt); } else { /* We can't run filters yet, dump the memory * right before the filter. */ - push_window_data(a, rar, - rar->cstate.last_write_ptr, + push_window_data(a, rar5, + rar5->cstate.last_write_ptr, flt->block_start); } @@ -819,12 +819,12 @@ static int apply_filters(struct archive_read* a) { } } - rar->cstate.all_filters_applied = 1; + rar5->cstate.all_filters_applied = 1; return ARCHIVE_OK; } -static void dist_cache_push(struct rar5* rar, int value) { - int* q = rar->cstate.dist_cache; +static void dist_cache_push(struct rar5 *rar5, int value) { + int* q = rar5->cstate.dist_cache; q[3] = q[2]; q[2] = q[1]; @@ -832,8 +832,8 @@ static void dist_cache_push(struct rar5* rar, int value) { q[0] = value; } -static int dist_cache_touch(struct rar5* rar, int idx) { - int* q = rar->cstate.dist_cache; +static int dist_cache_touch(struct rar5 *rar5, int idx) { + int* q = rar5->cstate.dist_cache; int i, dist = q[idx]; for(i = idx; i > 0; i--) @@ -843,8 +843,8 @@ static int dist_cache_touch(struct rar5* rar, int idx) { return dist; } -static void free_filters(struct rar5* rar) { - struct cdeque* d = &rar->cstate.filters; +static void free_filters(struct rar5 *rar5) { + struct cdeque* d = &rar5->cstate.filters; /* Free any remaining filters. All filters should be naturally * consumed by the unpacking function, so remaining filters after @@ -864,28 +864,28 @@ static void free_filters(struct rar5* rar) { cdeque_clear(d); /* Also clear out the variables needed for sanity checking. */ - rar->cstate.last_block_start = 0; - rar->cstate.last_block_length = 0; + rar5->cstate.last_block_start = 0; + rar5->cstate.last_block_length = 0; } -static void reset_file_context(struct rar5* rar) { - memset(&rar->file, 0, sizeof(rar->file)); - blake2sp_init(&rar->file.b2state, 32); +static void reset_file_context(struct rar5 *rar5) { + memset(&rar5->file, 0, sizeof(rar5->file)); + blake2sp_init(&rar5->file.b2state, 32); - if(rar->main.solid) { - rar->cstate.solid_offset += rar->cstate.write_ptr; + if(rar5->main.solid) { + rar5->cstate.solid_offset += rar5->cstate.write_ptr; } else { - rar->cstate.solid_offset = 0; + rar5->cstate.solid_offset = 0; } - rar->cstate.write_ptr = 0; - rar->cstate.last_write_ptr = 0; - rar->cstate.last_unstore_ptr = 0; + rar5->cstate.write_ptr = 0; + rar5->cstate.last_write_ptr = 0; + rar5->cstate.last_unstore_ptr = 0; - rar->file.redir_type = REDIR_TYPE_NONE; - rar->file.redir_flags = 0; + rar5->file.redir_type = REDIR_TYPE_NONE; + rar5->file.redir_flags = 0; - free_filters(rar); + free_filters(rar5); } static inline int get_archive_read(struct archive* a, @@ -1031,47 +1031,47 @@ static int read_var_sized(struct archive_read* a, size_t* pvalue, return ret; } -static int read_bits_32(struct archive_read* a, struct rar5* rar, +static int read_bits_32(struct archive_read* a, struct rar5 *rar5, const uint8_t* p, uint32_t* value) { - if(rar->bits.in_addr >= rar->cstate.cur_block_size) { + if(rar5->bits.in_addr >= rar5->cstate.cur_block_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Premature end of stream during extraction of data (#1)"); return ARCHIVE_FATAL; } - uint32_t bits = archive_be32dec(p + rar->bits.in_addr); - bits <<= rar->bits.bit_addr; - bits |= p[rar->bits.in_addr + 4] >> (8 - rar->bits.bit_addr); + uint32_t bits = archive_be32dec(p + rar5->bits.in_addr); + bits <<= rar5->bits.bit_addr; + bits |= p[rar5->bits.in_addr + 4] >> (8 - rar5->bits.bit_addr); *value = bits; return ARCHIVE_OK; } -static int read_bits_16(struct archive_read* a, struct rar5* rar, +static int read_bits_16(struct archive_read* a, struct rar5 *rar5, const uint8_t* p, uint16_t* value) { - if(rar->bits.in_addr >= rar->cstate.cur_block_size) { + if(rar5->bits.in_addr >= rar5->cstate.cur_block_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Premature end of stream during extraction of data (#2)"); return ARCHIVE_FATAL; } - uint32_t bits = archive_be24dec(p + (unsigned)rar->bits.in_addr); - bits >>= (8 - rar->bits.bit_addr); + uint32_t bits = archive_be24dec(p + (unsigned)rar5->bits.in_addr); + bits >>= (8 - rar5->bits.bit_addr); *value = bits & 0xffff; return ARCHIVE_OK; } -static void skip_bits(struct rar5* rar, int bits) { - const int new_bits = rar->bits.bit_addr + bits; - rar->bits.in_addr += new_bits >> 3; - rar->bits.bit_addr = new_bits & 7; +static void skip_bits(struct rar5 *rar5, int bits) { + const int new_bits = rar5->bits.bit_addr + bits; + rar5->bits.in_addr += new_bits >> 3; + rar5->bits.bit_addr = new_bits & 7; } /* n = up to 16 */ -static int read_consume_bits(struct archive_read* a, struct rar5* rar, +static int read_consume_bits(struct archive_read* a, struct rar5 *rar5, const uint8_t* p, int n, int* value) { uint16_t v; @@ -1083,14 +1083,14 @@ static int read_consume_bits(struct archive_read* a, struct rar5* rar, return ARCHIVE_FATAL; } - ret = read_bits_16(a, rar, p, &v); + ret = read_bits_16(a, rar5, p, &v); if(ret != ARCHIVE_OK) return ret; num = (int) v; num >>= 16 - n; - skip_bits(rar, n); + skip_bits(rar5, n); if(value) *value = num; @@ -1205,11 +1205,11 @@ static void init_header(struct archive_read* a) { a->archive.archive_format_name = "RAR5"; } -static void init_window_mask(struct rar5* rar) { - if (rar->cstate.window_size) - rar->cstate.window_mask = rar->cstate.window_size - 1; +static void init_window_mask(struct rar5 *rar5) { + if (rar5->cstate.window_size) + rar5->cstate.window_mask = rar5->cstate.window_size - 1; else - rar->cstate.window_mask = 0; + rar5->cstate.window_mask = 0; } enum HEADER_FLAGS { @@ -1223,7 +1223,7 @@ enum HEADER_FLAGS { }; static int process_main_locator_extra_block(struct archive_read* a, - struct rar5* rar) + struct rar5 *rar5) { uint64_t locator_flags; @@ -1236,7 +1236,7 @@ static int process_main_locator_extra_block(struct archive_read* a, } if(locator_flags & QLIST) { - if(!read_var(a, &rar->qlist_offset, NULL)) { + if(!read_var(a, &rar5->qlist_offset, NULL)) { return ARCHIVE_EOF; } @@ -1244,7 +1244,7 @@ static int process_main_locator_extra_block(struct archive_read* a, } if(locator_flags & RECOVERY) { - if(!read_var(a, &rar->rr_offset, NULL)) { + if(!read_var(a, &rar5->rr_offset, NULL)) { return ARCHIVE_EOF; } @@ -1254,7 +1254,7 @@ static int process_main_locator_extra_block(struct archive_read* a, return ARCHIVE_OK; } -static int parse_file_extra_hash(struct archive_read* a, struct rar5* rar, +static int parse_file_extra_hash(struct archive_read* a, struct rar5 *rar5, int64_t* extra_data_size) { size_t hash_type = 0; @@ -1276,13 +1276,13 @@ static int parse_file_extra_hash(struct archive_read* a, struct rar5* rar, * CRC32. */ if(hash_type == BLAKE2sp) { const uint8_t* p; - const int hash_size = sizeof(rar->file.blake2sp); + const int hash_size = sizeof(rar5->file.blake2sp); if(!read_ahead(a, hash_size, &p)) return ARCHIVE_EOF; - rar->file.has_blake2 = 1; - memcpy(&rar->file.blake2sp, p, hash_size); + rar5->file.has_blake2 = 1; + memcpy(&rar5->file.blake2sp, p, hash_size); if(ARCHIVE_OK != consume(a, hash_size)) { return ARCHIVE_EOF; @@ -1375,7 +1375,7 @@ static int parse_file_extra_version(struct archive_read* a, } static int parse_file_extra_htime(struct archive_read* a, - struct archive_entry* e, struct rar5* rar, int64_t* extra_data_size) + struct archive_entry* e, struct rar5 *rar5, int64_t* extra_data_size) { char unix_time, has_unix_ns, has_mtime, has_ctime, has_atime; size_t flags = 0; @@ -1402,39 +1402,39 @@ static int parse_file_extra_htime(struct archive_read* a, has_mtime = flags & HAS_MTIME; has_atime = flags & HAS_ATIME; has_ctime = flags & HAS_CTIME; - rar->file.e_atime_ns = rar->file.e_ctime_ns = rar->file.e_mtime_ns = 0; + rar5->file.e_atime_ns = rar5->file.e_ctime_ns = rar5->file.e_mtime_ns = 0; if(has_mtime) { - parse_htime_item(a, unix_time, &rar->file.e_mtime, - &rar->file.e_mtime_ns, extra_data_size); + parse_htime_item(a, unix_time, &rar5->file.e_mtime, + &rar5->file.e_mtime_ns, extra_data_size); } if(has_ctime) { - parse_htime_item(a, unix_time, &rar->file.e_ctime, - &rar->file.e_ctime_ns, extra_data_size); + parse_htime_item(a, unix_time, &rar5->file.e_ctime, + &rar5->file.e_ctime_ns, extra_data_size); } if(has_atime) { - parse_htime_item(a, unix_time, &rar->file.e_atime, - &rar->file.e_atime_ns, extra_data_size); + parse_htime_item(a, unix_time, &rar5->file.e_atime, + &rar5->file.e_atime_ns, extra_data_size); } if(has_mtime && has_unix_ns) { - if(!read_u32(a, &rar->file.e_mtime_ns)) + if(!read_u32(a, &rar5->file.e_mtime_ns)) return ARCHIVE_EOF; *extra_data_size -= 4; } if(has_ctime && has_unix_ns) { - if(!read_u32(a, &rar->file.e_ctime_ns)) + if(!read_u32(a, &rar5->file.e_ctime_ns)) return ARCHIVE_EOF; *extra_data_size -= 4; } if(has_atime && has_unix_ns) { - if(!read_u32(a, &rar->file.e_atime_ns)) + if(!read_u32(a, &rar5->file.e_atime_ns)) return ARCHIVE_EOF; *extra_data_size -= 4; @@ -1443,35 +1443,35 @@ static int parse_file_extra_htime(struct archive_read* a, /* The seconds and nanoseconds are either together, or separated in two * fields so we parse them, then set the archive_entry's times. */ if(has_mtime) { - archive_entry_set_mtime(e, rar->file.e_mtime, rar->file.e_mtime_ns); + archive_entry_set_mtime(e, rar5->file.e_mtime, rar5->file.e_mtime_ns); } if(has_ctime) { - archive_entry_set_ctime(e, rar->file.e_ctime, rar->file.e_ctime_ns); + archive_entry_set_ctime(e, rar5->file.e_ctime, rar5->file.e_ctime_ns); } if(has_atime) { - archive_entry_set_atime(e, rar->file.e_atime, rar->file.e_atime_ns); + archive_entry_set_atime(e, rar5->file.e_atime, rar5->file.e_atime_ns); } return ARCHIVE_OK; } static int parse_file_extra_redir(struct archive_read* a, - struct archive_entry* e, struct rar5* rar, int64_t* extra_data_size) + struct archive_entry* e, struct rar5 *rar5, int64_t* extra_data_size) { uint64_t value_size = 0; size_t target_size = 0; char target_utf8_buf[MAX_NAME_IN_BYTES]; const uint8_t* p; - if(!read_var(a, &rar->file.redir_type, &value_size)) + if(!read_var(a, &rar5->file.redir_type, &value_size)) return ARCHIVE_EOF; if(ARCHIVE_OK != consume(a, (int64_t)value_size)) return ARCHIVE_EOF; *extra_data_size -= value_size; - if(!read_var(a, &rar->file.redir_flags, &value_size)) + if(!read_var(a, &rar5->file.redir_flags, &value_size)) return ARCHIVE_EOF; if(ARCHIVE_OK != consume(a, (int64_t)value_size)) return ARCHIVE_EOF; @@ -1502,12 +1502,12 @@ static int parse_file_extra_redir(struct archive_read* a, if(ARCHIVE_OK != consume(a, (int64_t)target_size)) return ARCHIVE_EOF; - switch(rar->file.redir_type) { + switch(rar5->file.redir_type) { case REDIR_TYPE_UNIXSYMLINK: case REDIR_TYPE_WINSYMLINK: archive_entry_set_filetype(e, AE_IFLNK); archive_entry_update_symlink_utf8(e, target_utf8_buf); - if (rar->file.redir_flags & REDIR_SYMLINK_IS_DIR) { + if (rar5->file.redir_flags & REDIR_SYMLINK_IS_DIR) { archive_entry_set_symlink_type(e, AE_SYMLINK_TYPE_DIRECTORY); } else { @@ -1609,7 +1609,7 @@ static int parse_file_extra_owner(struct archive_read* a, } static int process_head_file_extra(struct archive_read* a, - struct archive_entry* e, struct rar5* rar, int64_t extra_data_size) + struct archive_entry* e, struct rar5 *rar5, int64_t extra_data_size) { uint64_t extra_field_size; uint64_t extra_field_id = 0; @@ -1639,15 +1639,15 @@ static int process_head_file_extra(struct archive_read* a, switch(extra_field_id) { case EX_HASH: - ret = parse_file_extra_hash(a, rar, + ret = parse_file_extra_hash(a, rar5, &extra_data_size); break; case EX_HTIME: - ret = parse_file_extra_htime(a, e, rar, + ret = parse_file_extra_htime(a, e, rar5, &extra_data_size); break; case EX_REDIR: - ret = parse_file_extra_redir(a, e, rar, + ret = parse_file_extra_redir(a, e, rar5, &extra_data_size); break; case EX_UOWNER: @@ -1661,8 +1661,8 @@ static int process_head_file_extra(struct archive_read* a, case EX_CRYPT: /* Mark the entry as encrypted */ archive_entry_set_is_data_encrypted(e, 1); - rar->has_encrypted_entries = 1; - rar->cstate.data_encrypted = 1; + rar5->has_encrypted_entries = 1; + rar5->cstate.data_encrypted = 1; /* fallthrough */ case EX_SUBDATA: /* fallthrough */ @@ -1724,7 +1724,7 @@ static int file_entry_sanity_checks(struct archive_read* a, return ARCHIVE_OK; } -static int process_head_file(struct archive_read* a, struct rar5* rar, +static int process_head_file(struct archive_read* a, struct rar5 *rar5, struct archive_entry* entry, size_t block_flags) { int64_t extra_data_size = 0; @@ -1763,8 +1763,8 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, archive_entry_clear(entry); /* Do not reset file context if we're switching archives. */ - if(!rar->cstate.switch_multivolume) { - reset_file_context(rar); + if(!rar5->cstate.switch_multivolume) { + reset_file_context(rar5); } if(block_flags & HFL_EXTRA_DATA) { @@ -1787,9 +1787,9 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, return ARCHIVE_FATAL; } - rar->file.bytes_remaining = data_size; + rar5->file.bytes_remaining = data_size; } else { - rar->file.bytes_remaining = 0; + rar5->file.bytes_remaining = 0; } if(!read_var_sized(a, &file_flags, NULL)) @@ -1804,9 +1804,9 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, return ARCHIVE_FATAL; } - rar->file.dir = (uint8_t) ((file_flags & DIRECTORY) > 0); + rar5->file.dir = (uint8_t) ((file_flags & DIRECTORY) > 0); - sanity_ret = file_entry_sanity_checks(a, block_flags, rar->file.dir, + sanity_ret = file_entry_sanity_checks(a, block_flags, rar5->file.dir, unpacked_size, data_size); if (sanity_ret != ARCHIVE_OK) { @@ -1833,19 +1833,19 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, c_version = (int) (compression_info & 0x3f); /* RAR5 seems to limit the dictionary size to 64MB. */ - window_size = (rar->file.dir > 0) ? + window_size = (rar5->file.dir > 0) ? 0 : g_unpack_window_size << ((compression_info >> 10) & 15); - rar->cstate.method = c_method; - rar->cstate.version = c_version + 50; - rar->file.solid = (compression_info & SOLID) > 0; + rar5->cstate.method = c_method; + rar5->cstate.version = c_version + 50; + rar5->file.solid = (compression_info & SOLID) > 0; /* Archives which declare solid files without initializing the window * buffer first are invalid, unless previous data was encrypted, in * which case we may never have had the chance */ - if(rar->file.solid > 0 && rar->cstate.data_encrypted == 0 && - rar->cstate.window_buf == NULL) { + if(rar5->file.solid > 0 && rar5->cstate.data_encrypted == 0 && + rar5->cstate.window_buf == NULL) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Declared solid file, but no window buffer " "initialized yet"); @@ -1855,18 +1855,18 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, /* Check if window_size is a sane value. Also, if the file is not * declared as a directory, disallow window_size == 0. */ if(window_size > (64 * 1024 * 1024) || - (rar->file.dir == 0 && window_size == 0)) + (rar5->file.dir == 0 && window_size == 0)) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Declared dictionary size is not supported"); return ARCHIVE_FATAL; } - if(rar->file.solid > 0) { + if(rar5->file.solid > 0) { /* Re-check if current window size is the same as previous * window size (for solid files only). */ - if(rar->file.solid_window_size > 0 && - rar->file.solid_window_size != (ssize_t) window_size) + if(rar5->file.solid_window_size > 0 && + rar5->file.solid_window_size != (ssize_t) window_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Window size for this solid file doesn't match " @@ -1875,23 +1875,23 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, } } else - rar->cstate.data_encrypted = 0; /* Reset for new buffer */ + rar5->cstate.data_encrypted = 0; /* Reset for new buffer */ - if(rar->cstate.window_size < (ssize_t) window_size && - rar->cstate.window_buf) + if(rar5->cstate.window_size < (ssize_t) window_size && + rar5->cstate.window_buf) { /* The `data_ready` stack contains pointers to the `window_buf` or * `filtered_buf` buffers. Since we're about to reallocate the first * buffer, some of those pointers could become invalid. Therefore, we * need to dispose of all entries from the stack before attempting the * realloc. */ - clear_data_ready_stack(rar); + clear_data_ready_stack(rar5); /* If window_buf has been allocated before, reallocate it, so * that its size will match new window_size. */ uint8_t* new_window_buf = - realloc(rar->cstate.window_buf, (size_t) window_size); + realloc(rar5->cstate.window_buf, (size_t) window_size); if(!new_window_buf) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, @@ -1900,23 +1900,23 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, return ARCHIVE_FATAL; } - rar->cstate.window_buf = new_window_buf; + rar5->cstate.window_buf = new_window_buf; } /* Values up to 64M should fit into ssize_t on every * architecture. */ - rar->cstate.window_size = (ssize_t) window_size; + rar5->cstate.window_size = (ssize_t) window_size; - if(rar->file.solid > 0 && rar->file.solid_window_size == 0) { + if(rar5->file.solid > 0 && rar5->file.solid_window_size == 0) { /* Solid files have to have the same window_size across whole archive. Remember the window_size parameter for first solid file found. */ - rar->file.solid_window_size = rar->cstate.window_size; + rar5->file.solid_window_size = rar5->cstate.window_size; } - init_window_mask(rar); + init_window_mask(rar5); - rar->file.service = 0; + rar5->file.service = 0; if(!read_var_sized(a, &host_os, NULL)) return ARCHIVE_EOF; @@ -1999,7 +1999,7 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, archive_entry_update_pathname_utf8(entry, name_utf8_buf); if(extra_data_size > 0) { - int ret = process_head_file_extra(a, entry, rar, + int ret = process_head_file_extra(a, entry, rar5, extra_data_size); /* @@ -2018,8 +2018,8 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, } if((file_flags & UNKNOWN_UNPACKED_SIZE) == 0) { - rar->file.unpacked_size = (ssize_t) unpacked_size; - if(rar->file.redir_type == REDIR_TYPE_NONE) + rar5->file.unpacked_size = (ssize_t) unpacked_size; + if(rar5->file.redir_type == REDIR_TYPE_NONE) archive_entry_set_size(entry, unpacked_size); } @@ -2028,18 +2028,18 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, } if(file_flags & CRC32) { - rar->file.stored_crc32 = crc; + rar5->file.stored_crc32 = crc; } - if(!rar->cstate.switch_multivolume) { + if(!rar5->cstate.switch_multivolume) { /* Do not reinitialize unpacking state if we're switching * archives. */ - rar->cstate.block_parsing_finished = 1; - rar->cstate.all_filters_applied = 1; - rar->cstate.initialized = 0; + rar5->cstate.block_parsing_finished = 1; + rar5->cstate.all_filters_applied = 1; + rar5->cstate.initialized = 0; } - if(rar->generic.split_before > 0) { + if(rar5->generic.split_before > 0) { /* If now we're standing on a header that has a 'split before' * mark, it means we're standing on a 'continuation' file * header. Signal the caller that if it wants to move to @@ -2052,15 +2052,15 @@ static int process_head_file(struct archive_read* a, struct rar5* rar, } } -static int process_head_service(struct archive_read* a, struct rar5* rar, +static int process_head_service(struct archive_read* a, struct rar5 *rar5, struct archive_entry* entry, size_t block_flags) { /* Process this SERVICE block the same way as FILE blocks. */ - int ret = process_head_file(a, rar, entry, block_flags); + int ret = process_head_file(a, rar5, entry, block_flags); if(ret != ARCHIVE_OK) return ret; - rar->file.service = 1; + rar5->file.service = 1; /* But skip the data part automatically. It's no use for the user * anyway. It contains only service data, not even needed to @@ -2073,7 +2073,7 @@ static int process_head_service(struct archive_read* a, struct rar5* rar, return ARCHIVE_RETRY; } -static int process_head_main(struct archive_read* a, struct rar5* rar, +static int process_head_main(struct archive_read* a, struct rar5 *rar5, struct archive_entry* entry, size_t block_flags) { int ret; @@ -2109,8 +2109,8 @@ static int process_head_main(struct archive_read* a, struct rar5* rar, return ARCHIVE_EOF; } - rar->main.volume = (archive_flags & VOLUME) > 0; - rar->main.solid = (archive_flags & SOLID) > 0; + rar5->main.volume = (archive_flags & VOLUME) > 0; + rar5->main.solid = (archive_flags & SOLID) > 0; if(archive_flags & VOLUME_NUMBER) { size_t v = 0; @@ -2125,13 +2125,13 @@ static int process_head_main(struct archive_read* a, struct rar5* rar, return ARCHIVE_FATAL; } - rar->main.vol_no = (unsigned int) v; + rar5->main.vol_no = (unsigned int) v; } else { - rar->main.vol_no = 0; + rar5->main.vol_no = 0; } - if(rar->vol.expected_vol_no > 0 && - rar->main.vol_no != rar->vol.expected_vol_no) + if(rar5->vol.expected_vol_no > 0 && + rar5->main.vol_no != rar5->vol.expected_vol_no) { /* Returning EOF instead of FATAL because of strange * libarchive behavior. When opening multiple files via @@ -2162,7 +2162,7 @@ static int process_head_main(struct archive_read* a, struct rar5* rar, switch(extra_field_id) { case LOCATOR: - ret = process_main_locator_extra_block(a, rar); + ret = process_main_locator_extra_block(a, rar5); if(ret != ARCHIVE_OK) { /* Error while parsing main locator extra * block. */ @@ -2182,25 +2182,25 @@ static int process_head_main(struct archive_read* a, struct rar5* rar, } static int skip_unprocessed_bytes(struct archive_read* a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int ret; - if(rar->file.bytes_remaining) { + if(rar5->file.bytes_remaining) { /* Use different skipping method in block merging mode than in * normal mode. If merge mode is active, rar5_read_data_skip * can't be used, because it could allow recursive use of * merge_block() * function, and this function doesn't support * recursive use. */ - if(rar->merge_mode) { + if(rar5->merge_mode) { /* Discard whole merged block. This is valid in solid * mode as well, because the code will discard blocks * only if those blocks are safe to discard (i.e. * they're not FILE blocks). */ - ret = consume(a, rar->file.bytes_remaining); + ret = consume(a, rar5->file.bytes_remaining); if(ret != ARCHIVE_OK) { return ret; } - rar->file.bytes_remaining = 0; + rar5->file.bytes_remaining = 0; } else { /* If we're not in merge mode, use safe skipping code. * This will ensure we'll handle solid archives @@ -2294,7 +2294,7 @@ static int process_base_block(struct archive_read* a, { const size_t SMALLEST_RAR5_BLOCK_SIZE = 3; - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; uint32_t hdr_crc, computed_crc; size_t raw_hdr_size = 0, hdr_size_len, hdr_size; size_t header_id = 0; @@ -2377,16 +2377,16 @@ static int process_base_block(struct archive_read* a, if(!read_var_sized(a, &header_flags, NULL)) return ARCHIVE_EOF; - rar->generic.split_after = (header_flags & HFL_SPLIT_AFTER) > 0; - rar->generic.split_before = (header_flags & HFL_SPLIT_BEFORE) > 0; - rar->generic.size = (int)hdr_size; - rar->generic.last_header_id = (int)header_id; - rar->main.endarc = 0; + rar5->generic.split_after = (header_flags & HFL_SPLIT_AFTER) > 0; + rar5->generic.split_before = (header_flags & HFL_SPLIT_BEFORE) > 0; + rar5->generic.size = (int)hdr_size; + rar5->generic.last_header_id = (int)header_id; + rar5->main.endarc = 0; /* Those are possible header ids in RARv5. */ switch(header_id) { case HEAD_MAIN: - ret = process_head_main(a, rar, entry, header_flags); + ret = process_head_main(a, rar5, entry, header_flags); /* Main header doesn't have any files in it, so it's * pointless to return to the caller. Retry to next @@ -2399,28 +2399,28 @@ static int process_base_block(struct archive_read* a, return ret; case HEAD_SERVICE: - ret = process_head_service(a, rar, entry, header_flags); + ret = process_head_service(a, rar5, entry, header_flags); return ret; case HEAD_FILE: - ret = process_head_file(a, rar, entry, header_flags); + ret = process_head_file(a, rar5, entry, header_flags); return ret; case HEAD_CRYPT: archive_entry_set_is_metadata_encrypted(entry, 1); archive_entry_set_is_data_encrypted(entry, 1); - rar->has_encrypted_entries = 1; - rar->headers_are_encrypted = 1; + rar5->has_encrypted_entries = 1; + rar5->headers_are_encrypted = 1; archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Encryption is not supported"); return ARCHIVE_FATAL; case HEAD_ENDARC: - rar->main.endarc = 1; + rar5->main.endarc = 1; /* After encountering an end of file marker, we need * to take into consideration if this archive is * continued in another file (i.e. is it part01.rar: * is there a part02.rar?) */ - if(rar->main.volume) { + if(rar5->main.volume) { /* In case there is part02.rar, position the * read pointer in a proper place, so we can * resume parsing. */ @@ -2428,7 +2428,7 @@ static int process_base_block(struct archive_read* a, if(ret == ARCHIVE_FATAL) { return ARCHIVE_EOF; } else { - if(rar->vol.expected_vol_no == + if(rar5->vol.expected_vol_no == UINT_MAX) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, @@ -2436,8 +2436,8 @@ static int process_base_block(struct archive_read* a, return ARCHIVE_FATAL; } - rar->vol.expected_vol_no = - rar->main.vol_no + 1; + rar5->vol.expected_vol_no = + rar5->main.vol_no + 1; return ARCHIVE_OK; } } else { @@ -2470,7 +2470,7 @@ static int process_base_block(struct archive_read* a, } static int skip_base_block(struct archive_read* a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int ret; /* Create a new local archive_entry structure that will be operated on @@ -2487,7 +2487,7 @@ static int skip_base_block(struct archive_read* a) { if(ret == ARCHIVE_FATAL) return ret; - if(rar->generic.last_header_id == 2 && rar->generic.split_before > 0) + if(rar5->generic.last_header_id == 2 && rar5->generic.split_before > 0) return ARCHIVE_OK; if(ret == ARCHIVE_OK) @@ -2555,76 +2555,77 @@ fatal: static int rar5_read_header(struct archive_read *a, struct archive_entry *entry) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int ret; /* * It should be sufficient to call archive_read_next_header() for * a reader to determine if an entry is encrypted or not. */ - if (rar->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { - rar->has_encrypted_entries = 0; + if (rar5->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + rar5->has_encrypted_entries = 0; } - if(rar->header_initialized == 0) { + if(rar5->header_initialized == 0) { init_header(a); if ((ret = try_skip_sfx(a)) < ARCHIVE_WARN) return ret; - rar->header_initialized = 1; + rar5->header_initialized = 1; } - if(rar->skipped_magic == 0) { + if(rar5->skipped_magic == 0) { if(ARCHIVE_OK != consume(a, sizeof(rar5_signature_xor))) { return ARCHIVE_EOF; } - rar->skipped_magic = 1; + rar5->skipped_magic = 1; } do { ret = process_base_block(a, entry); } while(ret == ARCHIVE_RETRY || - (rar->main.endarc > 0 && ret == ARCHIVE_OK)); + (rar5->main.endarc > 0 && ret == ARCHIVE_OK)); return ret; } -static int init_unpack(struct rar5* rar) { - rar->file.calculated_crc32 = 0; - init_window_mask(rar); +static int init_unpack(struct rar5 *rar5) { + rar5->file.calculated_crc32 = 0; + init_window_mask(rar5); - free(rar->cstate.window_buf); - free(rar->cstate.filtered_buf); + free(rar5->cstate.window_buf); + free(rar5->cstate.filtered_buf); - rar->cstate.window_buf = NULL; - rar->cstate.filtered_buf = NULL; + rar5->cstate.window_buf = NULL; + rar5->cstate.filtered_buf = NULL; - if(rar->cstate.window_size > 0) { - rar->cstate.window_buf = calloc(1, rar->cstate.window_size); - if(rar->cstate.window_buf == NULL) + if(rar5->cstate.window_size > 0) { + rar5->cstate.window_buf = calloc(1, rar5->cstate.window_size); + if(rar5->cstate.window_buf == NULL) return ARCHIVE_FATAL; - rar->cstate.filtered_buf = calloc(1, rar->cstate.window_size); - if(rar->cstate.filtered_buf == NULL) + rar5->cstate.filtered_buf = calloc(1, + rar5->cstate.window_size); + if(rar5->cstate.filtered_buf == NULL) return ARCHIVE_FATAL; } - clear_data_ready_stack(rar); + clear_data_ready_stack(rar5); - rar->cstate.write_ptr = 0; - rar->cstate.last_write_ptr = 0; + rar5->cstate.write_ptr = 0; + rar5->cstate.last_write_ptr = 0; - memset(&rar->cstate.bd, 0, sizeof(rar->cstate.bd)); - memset(&rar->cstate.ld, 0, sizeof(rar->cstate.ld)); - memset(&rar->cstate.dd, 0, sizeof(rar->cstate.dd)); - memset(&rar->cstate.ldd, 0, sizeof(rar->cstate.ldd)); - memset(&rar->cstate.rd, 0, sizeof(rar->cstate.rd)); + memset(&rar5->cstate.bd, 0, sizeof(rar5->cstate.bd)); + memset(&rar5->cstate.ld, 0, sizeof(rar5->cstate.ld)); + memset(&rar5->cstate.dd, 0, sizeof(rar5->cstate.dd)); + memset(&rar5->cstate.ldd, 0, sizeof(rar5->cstate.ldd)); + memset(&rar5->cstate.rd, 0, sizeof(rar5->cstate.rd)); return ARCHIVE_OK; } -static void update_crc(struct rar5* rar, const uint8_t* p, size_t to_read) { +static void update_crc(struct rar5 *rar5, const uint8_t* p, size_t to_read) { int verify_crc; - if(rar->skip_mode) { + if(rar5->skip_mode) { #if defined CHECK_CRC_ON_SOLID_SKIP verify_crc = 1; #else @@ -2636,17 +2637,19 @@ static void update_crc(struct rar5* rar, const uint8_t* p, size_t to_read) { if(verify_crc) { /* Don't update CRC32 if the file doesn't have the * `stored_crc32` info filled in. */ - if(rar->file.stored_crc32 > 0) { - rar->file.calculated_crc32 = - crc32(rar->file.calculated_crc32, p, (unsigned int)to_read); + if(rar5->file.stored_crc32 > 0) { + rar5->file.calculated_crc32 = + crc32(rar5->file.calculated_crc32, p, + (unsigned int)to_read); } /* Check if the file uses an optional BLAKE2sp checksum * algorithm. */ - if(rar->file.has_blake2 > 0) { + if(rar5->file.has_blake2 > 0) { /* Return value of the `update` function is always 0, * so we can explicitly ignore it here. */ - (void) blake2sp_update(&rar->file.b2state, p, to_read); + (void) blake2sp_update(&rar5->file.b2state, p, + to_read); } } } @@ -2730,12 +2733,12 @@ static int create_decode_tables(uint8_t* bit_length, static int decode_number(struct archive_read* a, struct decode_table* table, const uint8_t* p, uint16_t* num) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int i, bits, dist, ret; uint16_t bitfield; uint32_t pos; - if(ARCHIVE_OK != (ret = read_bits_16(a, rar, p, &bitfield))) { + if(ARCHIVE_OK != (ret = read_bits_16(a, rar5, p, &bitfield))) { return ret; } @@ -2743,7 +2746,7 @@ static int decode_number(struct archive_read* a, struct decode_table* table, if(bitfield < table->decode_len[table->quick_bits]) { int code = bitfield >> (16 - table->quick_bits); - skip_bits(rar, table->quick_len[code]); + skip_bits(rar5, table->quick_len[code]); *num = table->quick_num[code]; return ARCHIVE_OK; } @@ -2757,7 +2760,7 @@ static int decode_number(struct archive_read* a, struct decode_table* table, } } - skip_bits(rar, bits); + skip_bits(rar5, bits); dist = bitfield - table->decode_len[bits - 1]; dist >>= (16 - bits); @@ -2771,7 +2774,7 @@ static int decode_number(struct archive_read* a, struct decode_table* table, } /* Reads and parses Huffman tables from the beginning of the block. */ -static int parse_tables(struct archive_read* a, struct rar5* rar, +static int parse_tables(struct archive_read* a, struct rar5 *rar5, const uint8_t* p) { int ret, value, i, w, idx = 0; @@ -2785,7 +2788,7 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, /* The data for table generation is compressed using a simple RLE-like * algorithm when storing zeroes, so we need to unpack it first. */ for(w = 0, i = 0; w < HUFF_BC;) { - if(i >= rar->cstate.cur_block_size) { + if(i >= rar5->cstate.cur_block_size) { /* Truncated data, can't continue. */ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, @@ -2829,10 +2832,10 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, } } - rar->bits.in_addr = i; - rar->bits.bit_addr = nibble_shift ^ 4; + rar5->bits.in_addr = i; + rar5->bits.bit_addr = nibble_shift ^ 4; - ret = create_decode_tables(bit_length, &rar->cstate.bd, HUFF_BC); + ret = create_decode_tables(bit_length, &rar5->cstate.bd, HUFF_BC); if(ret != ARCHIVE_OK) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Decoding huffman tables failed"); @@ -2842,7 +2845,7 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, for(i = 0; i < HUFF_TABLE_SIZE;) { uint16_t num; - ret = decode_number(a, &rar->cstate.bd, p, &num); + ret = decode_number(a, &rar5->cstate.bd, p, &num); if(ret != ARCHIVE_OK) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, @@ -2858,17 +2861,17 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, /* 16..17: repeat previous code */ uint16_t n; - if(ARCHIVE_OK != (ret = read_bits_16(a, rar, p, &n))) + if(ARCHIVE_OK != (ret = read_bits_16(a, rar5, p, &n))) return ret; if(num == 16) { n >>= 13; n += 3; - skip_bits(rar, 3); + skip_bits(rar5, 3); } else { n >>= 9; n += 11; - skip_bits(rar, 7); + skip_bits(rar5, 7); } if(i > 0) { @@ -2887,17 +2890,17 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, /* other codes: fill with zeroes `n` times */ uint16_t n; - if(ARCHIVE_OK != (ret = read_bits_16(a, rar, p, &n))) + if(ARCHIVE_OK != (ret = read_bits_16(a, rar5, p, &n))) return ret; if(num == 18) { n >>= 13; n += 3; - skip_bits(rar, 3); + skip_bits(rar5, 3); } else { n >>= 9; n += 11; - skip_bits(rar, 7); + skip_bits(rar5, 7); } while(n-- > 0 && i < HUFF_TABLE_SIZE) @@ -2905,7 +2908,7 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, } } - ret = create_decode_tables(&table[idx], &rar->cstate.ld, HUFF_NC); + ret = create_decode_tables(&table[idx], &rar5->cstate.ld, HUFF_NC); if(ret != ARCHIVE_OK) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Failed to create literal table"); @@ -2914,7 +2917,7 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, idx += HUFF_NC; - ret = create_decode_tables(&table[idx], &rar->cstate.dd, HUFF_DC); + ret = create_decode_tables(&table[idx], &rar5->cstate.dd, HUFF_DC); if(ret != ARCHIVE_OK) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Failed to create distance table"); @@ -2923,7 +2926,7 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, idx += HUFF_DC; - ret = create_decode_tables(&table[idx], &rar->cstate.ldd, HUFF_LDC); + ret = create_decode_tables(&table[idx], &rar5->cstate.ldd, HUFF_LDC); if(ret != ARCHIVE_OK) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Failed to create lower bits of distances table"); @@ -2932,7 +2935,7 @@ static int parse_tables(struct archive_read* a, struct rar5* rar, idx += HUFF_LDC; - ret = create_decode_tables(&table[idx], &rar->cstate.rd, HUFF_RC); + ret = create_decode_tables(&table[idx], &rar5->cstate.rd, HUFF_RC); if(ret != ARCHIVE_OK) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Failed to create repeating distances table"); @@ -3006,13 +3009,13 @@ static int parse_block_header(struct archive_read* a, const uint8_t* p, } /* Convenience function used during filter processing. */ -static int parse_filter_data(struct archive_read* a, struct rar5* rar, +static int parse_filter_data(struct archive_read* a, struct rar5 *rar5, const uint8_t* p, uint32_t* filter_data) { int i, bytes, ret; uint32_t data = 0; - if(ARCHIVE_OK != (ret = read_consume_bits(a, rar, p, 2, &bytes))) + if(ARCHIVE_OK != (ret = read_consume_bits(a, rar5, p, 2, &bytes))) return ret; bytes++; @@ -3020,14 +3023,14 @@ static int parse_filter_data(struct archive_read* a, struct rar5* rar, for(i = 0; i < bytes; i++) { uint16_t byte; - if(ARCHIVE_OK != (ret = read_bits_16(a, rar, p, &byte))) { + if(ARCHIVE_OK != (ret = read_bits_16(a, rar5, p, &byte))) { return ret; } /* Cast to uint32_t will ensure the shift operation will not * produce undefined result. */ data += ((uint32_t) byte >> 8) << (i * 8); - skip_bits(rar, 8); + skip_bits(rar5, 8); } *filter_data = data; @@ -3035,12 +3038,12 @@ static int parse_filter_data(struct archive_read* a, struct rar5* rar, } /* Function is used during sanity checking. */ -static int is_valid_filter_block_start(struct rar5* rar, +static int is_valid_filter_block_start(struct rar5 *rar5, uint32_t start) { - const int64_t block_start = (ssize_t) start + rar->cstate.write_ptr; - const int64_t last_bs = rar->cstate.last_block_start; - const ssize_t last_bl = rar->cstate.last_block_length; + const int64_t block_start = (ssize_t) start + rar5->cstate.write_ptr; + const int64_t last_bs = rar5->cstate.last_block_start; + const ssize_t last_bl = rar5->cstate.last_block_length; if(last_bs == 0 || last_bl == 0) { /* We didn't have any filters yet, so accept this offset. */ @@ -3060,32 +3063,32 @@ static int is_valid_filter_block_start(struct rar5* rar, /* The function will create a new filter, read its parameters from the input * stream and add it to the filter collection. */ static int parse_filter(struct archive_read* ar, const uint8_t* p) { - struct rar5 *rar = ar->format->data; + struct rar5 *rar5 = ar->format->data; uint32_t block_start, block_length; uint16_t filter_type; struct filter_info* filt = NULL; int ret; /* Read the parameters from the input stream. */ - if(ARCHIVE_OK != (ret = parse_filter_data(ar, rar, p, &block_start))) + if(ARCHIVE_OK != (ret = parse_filter_data(ar, rar5, p, &block_start))) return ret; - if(ARCHIVE_OK != (ret = parse_filter_data(ar, rar, p, &block_length))) + if(ARCHIVE_OK != (ret = parse_filter_data(ar, rar5, p, &block_length))) return ret; - if(ARCHIVE_OK != (ret = read_bits_16(ar, rar, p, &filter_type))) + if(ARCHIVE_OK != (ret = read_bits_16(ar, rar5, p, &filter_type))) return ret; filter_type >>= 13; - skip_bits(rar, 3); + skip_bits(rar5, 3); /* Perform some sanity checks on this filter parameters. */ if(block_length < 4 || block_length > 0x400000 || - !is_valid_filter_block_start(rar, block_start) || - (rar->cstate.window_size > 0 && - (ssize_t)block_length > rar->cstate.window_size >> 1)) + !is_valid_filter_block_start(rar5, block_start) || + (rar5->cstate.window_size > 0 && + (ssize_t)block_length > rar5->cstate.window_size >> 1)) { archive_set_error(&ar->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Invalid filter encountered"); @@ -3093,7 +3096,7 @@ static int parse_filter(struct archive_read* ar, const uint8_t* p) { } /* Allocate a new filter. */ - filt = add_new_filter(rar); + filt = add_new_filter(rar5); if(filt == NULL) { archive_set_error(&ar->archive, ENOMEM, "Can't allocate memory for a filter descriptor"); @@ -3101,11 +3104,11 @@ static int parse_filter(struct archive_read* ar, const uint8_t* p) { } filt->type = filter_type; - filt->block_start = rar->cstate.write_ptr + block_start; + filt->block_start = rar5->cstate.write_ptr + block_start; filt->block_length = block_length; - rar->cstate.last_block_start = filt->block_start; - rar->cstate.last_block_length = filt->block_length; + rar5->cstate.last_block_start = filt->block_start; + rar5->cstate.last_block_length = filt->block_length; /* Read some more data in case this is a DELTA filter. Other filter * types don't require any additional data over what was already @@ -3113,7 +3116,7 @@ static int parse_filter(struct archive_read* ar, const uint8_t* p) { if(filter_type == FILTER_DELTA) { int channels; - if(ARCHIVE_OK != (ret = read_consume_bits(ar, rar, p, 5, &channels))) + if(ARCHIVE_OK != (ret = read_consume_bits(ar, rar5, p, 5, &channels))) return ret; filt->channels = channels + 1; @@ -3122,7 +3125,7 @@ static int parse_filter(struct archive_read* ar, const uint8_t* p) { return ARCHIVE_OK; } -static int decode_code_length(struct archive_read* a, struct rar5* rar, +static int decode_code_length(struct archive_read* a, struct rar5 *rar5, const uint8_t* p, uint16_t code) { int lbits, length = 2; @@ -3138,7 +3141,7 @@ static int decode_code_length(struct archive_read* a, struct rar5* rar, if(lbits > 0) { int add; - if(ARCHIVE_OK != read_consume_bits(a, rar, p, lbits, &add)) + if(ARCHIVE_OK != read_consume_bits(a, rar5, p, lbits, &add)) return -1; length += add; @@ -3148,20 +3151,20 @@ static int decode_code_length(struct archive_read* a, struct rar5* rar, } static int copy_string(struct archive_read* a, int len, int dist) { - struct rar5 *rar = a->format->data; - const ssize_t cmask = rar->cstate.window_mask; - const uint64_t write_ptr = rar->cstate.write_ptr + - rar->cstate.solid_offset; + struct rar5 *rar5 = a->format->data; + const ssize_t cmask = rar5->cstate.window_mask; + const uint64_t write_ptr = rar5->cstate.write_ptr + + rar5->cstate.solid_offset; int i; - if (rar->cstate.window_buf == NULL) + if (rar5->cstate.window_buf == NULL) return ARCHIVE_FATAL; - if (rar->cstate.write_ptr > rar->file.unpacked_size || - len > rar->file.unpacked_size - rar->cstate.write_ptr) { + if (rar5->cstate.write_ptr > rar5->file.unpacked_size || + len > rar5->file.unpacked_size - rar5->cstate.write_ptr) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Uncompressed data exceeds declared size"); - return rar->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; + return rar5->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; } /* The unpacker spends most of the time in this function. It would be @@ -3174,26 +3177,26 @@ static int copy_string(struct archive_read* a, int len, int dist) { for(i = 0; i < len; i++) { const ssize_t write_idx = (write_ptr + i) & cmask; const ssize_t read_idx = (write_ptr + i - dist) & cmask; - rar->cstate.window_buf[write_idx] = - rar->cstate.window_buf[read_idx]; + rar5->cstate.window_buf[write_idx] = + rar5->cstate.window_buf[read_idx]; } - rar->cstate.write_ptr += len; + rar5->cstate.write_ptr += len; return ARCHIVE_OK; } static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; uint16_t num; int ret; - const uint64_t cmask = rar->cstate.window_mask; - const struct compressed_block_header* hdr = &rar->last_block_hdr; + const uint64_t cmask = rar5->cstate.window_mask; + const struct compressed_block_header* hdr = &rar5->last_block_hdr; const uint8_t bit_size = 1 + bf_bit_size(hdr); while(1) { - if(rar->cstate.write_ptr - rar->cstate.last_write_ptr > - (rar->cstate.window_size >> 1)) { + if(rar5->cstate.write_ptr - rar5->cstate.last_write_ptr > + (rar5->cstate.window_size >> 1)) { /* Don't allow growing data by more than half of the * window size at a time. In such case, break the loop; * next call to this function will continue processing @@ -3201,18 +3204,18 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { break; } - if(rar->bits.in_addr > rar->cstate.cur_block_size - 1 || - (rar->bits.in_addr == rar->cstate.cur_block_size - 1 && - rar->bits.bit_addr >= bit_size)) + if(rar5->bits.in_addr > rar5->cstate.cur_block_size - 1 || + (rar5->bits.in_addr == rar5->cstate.cur_block_size - 1 && + rar5->bits.bit_addr >= bit_size)) { /* If the program counter is here, it means the * function has finished processing the block. */ - rar->cstate.block_parsing_finished = 1; + rar5->cstate.block_parsing_finished = 1; break; } /* Decode the next literal. */ - if(ARCHIVE_OK != decode_number(a, &rar->cstate.ld, p, &num)) { + if(ARCHIVE_OK != decode_number(a, &rar5->cstate.ld, p, &num)) { return ARCHIVE_EOF; } @@ -3235,22 +3238,22 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { int64_t write_idx; /* A literal write emits one byte; copy_string() checks len. */ - if(rar->cstate.write_ptr >= rar->file.unpacked_size) { + if(rar5->cstate.write_ptr >= rar5->file.unpacked_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Uncompressed data exceeds declared size"); - return rar->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; + return rar5->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; } - write_idx = rar->cstate.solid_offset + - rar->cstate.write_ptr++; + write_idx = rar5->cstate.solid_offset + + rar5->cstate.write_ptr++; - rar->cstate.window_buf[write_idx & cmask] = + rar5->cstate.window_buf[write_idx & cmask] = (uint8_t) num; continue; } else if(num >= 262) { uint16_t dist_slot; - int len = decode_code_length(a, rar, p, num - 262), + int len = decode_code_length(a, rar5, p, num - 262), dbits, dist = 1; @@ -3259,17 +3262,17 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { ARCHIVE_ERRNO_PROGRAMMER, "Failed to decode the code length"); - return rar->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; + return rar5->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; } - if(ARCHIVE_OK != decode_number(a, &rar->cstate.dd, p, + if(ARCHIVE_OK != decode_number(a, &rar5->cstate.dd, p, &dist_slot)) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Failed to decode the distance slot"); - return rar->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; + return rar5->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; } if(dist_slot < 4) { @@ -3293,28 +3296,28 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { if(dbits > 4) { if(ARCHIVE_OK != (ret = read_bits_32( - a, rar, p, &add))) { + a, rar5, p, &add))) { /* Return EOF if we * can't read more * data. */ return ret; } - skip_bits(rar, dbits - 4); + skip_bits(rar5, dbits - 4); add = (add >> ( 36 - dbits)) << 4; dist += add; } if(ARCHIVE_OK != decode_number(a, - &rar->cstate.ldd, p, &low_dist)) + &rar5->cstate.ldd, p, &low_dist)) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Failed to decode the " "distance slot"); - return rar->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; + return rar5->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; } if(dist >= INT_MAX - low_dist - 1) { @@ -3324,7 +3327,7 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { ARCHIVE_ERRNO_FILE_FORMAT, "Distance pointer " "overflow"); - return rar->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; + return rar5->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; } dist += low_dist; @@ -3332,7 +3335,7 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { /* dbits is one of [0,1,2,3] */ int add; - if(ARCHIVE_OK != (ret = read_consume_bits(a, rar, + if(ARCHIVE_OK != (ret = read_consume_bits(a, rar5, p, dbits, &add))) { /* Return EOF if we can't read * more data. */ @@ -3355,8 +3358,8 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { } } - dist_cache_push(rar, dist); - rar->cstate.last_len = len; + dist_cache_push(rar5, dist); + rar5->cstate.last_len = len; ret = copy_string(a, len, dist); if(ret != ARCHIVE_OK) @@ -3371,10 +3374,10 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { continue; } else if(num == 257) { - if(rar->cstate.last_len != 0) { + if(rar5->cstate.last_len != 0) { ret = copy_string(a, - rar->cstate.last_len, - rar->cstate.dist_cache[0]); + rar5->cstate.last_len, + rar5->cstate.dist_cache[0]); if(ret != ARCHIVE_OK) return ret; } @@ -3383,22 +3386,22 @@ static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { } else { /* num < 262 */ const int idx = num - 258; - const int dist = dist_cache_touch(rar, idx); + const int dist = dist_cache_touch(rar5, idx); uint16_t len_slot; int len; - if(ARCHIVE_OK != decode_number(a, &rar->cstate.rd, p, + if(ARCHIVE_OK != decode_number(a, &rar5->cstate.rd, p, &len_slot)) { - return rar->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; + return rar5->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; } - len = decode_code_length(a, rar, p, len_slot); + len = decode_code_length(a, rar5, p, len_slot); if (len == -1) { - return rar->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; + return rar5->main.solid ? ARCHIVE_FATAL : ARCHIVE_FAILED; } - rar->cstate.last_len = len; + rar5->cstate.last_len = len; ret = copy_string(a, len, dist); if(ret != ARCHIVE_OK) @@ -3460,7 +3463,7 @@ static int scan_for_signature(struct archive_read* a) { /* This function will switch the multivolume archive file to another file, * i.e. from part03 to part 04. */ static int advance_multivolume(struct archive_read* a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int lret; /* A small state machine that will skip unnecessary data, needed to @@ -3468,7 +3471,7 @@ static int advance_multivolume(struct archive_read* a) { * we want to be an stream-oriented (instead of file-oriented) * unpacker. * - * The state machine starts with `rar->main.endarc` == 0. It also + * The state machine starts with `rar5->main.endarc` == 0. It also * assumes that current stream pointer points to some base block * header. * @@ -3477,10 +3480,10 @@ static int advance_multivolume(struct archive_read* a) { */ while(1) { - if(rar->main.endarc == 1) { + if(rar5->main.endarc == 1) { int looping = 1; - rar->main.endarc = 0; + rar5->main.endarc = 0; while(looping) { lret = skip_base_block(a); @@ -3518,7 +3521,7 @@ static int advance_multivolume(struct archive_read* a) { /* If there was an error during skipping, or we * have just skipped a FILE base block... */ - if(rar->main.endarc == 0) { + if(rar5->main.endarc == 0) { return lret; } else { continue; @@ -3537,12 +3540,12 @@ static int advance_multivolume(struct archive_read* a) { static int merge_block(struct archive_read* a, ssize_t block_size, const uint8_t** p) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; ssize_t cur_block_size, partial_offset = 0; const uint8_t* lp; int ret; - if(rar->merge_mode) { + if(rar5->merge_mode) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Recursive merge is not allowed"); @@ -3550,27 +3553,27 @@ static int merge_block(struct archive_read* a, ssize_t block_size, } /* Set a flag that we're in the switching mode. */ - rar->cstate.switch_multivolume = 1; + rar5->cstate.switch_multivolume = 1; /* Reallocate the memory which will hold the whole block. */ - if(rar->vol.push_buf) - free((void*) rar->vol.push_buf); + if(rar5->vol.push_buf) + free((void*) rar5->vol.push_buf); /* Increasing the allocation block by 8 is due to bit reading functions, * which are using additional 2 or 4 bytes. Allocating the block size * by exact value would make bit reader perform reads from invalid * memory block when reading the last byte from the buffer. */ - rar->vol.push_buf = malloc(block_size + 8); - if(!rar->vol.push_buf) { + rar5->vol.push_buf = malloc(block_size + 8); + if(!rar5->vol.push_buf) { archive_set_error(&a->archive, ENOMEM, "Can't allocate memory for a merge block buffer"); - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; return ARCHIVE_FATAL; } /* Valgrind complains if the extension block for bit reader is not * initialized, so initialize it. */ - memset(&rar->vol.push_buf[block_size], 0, 8); + memset(&rar5->vol.push_buf[block_size], 0, 8); /* A single block can span across multiple multivolume archive files, * so we use a loop here. This loop will consume enough multivolume @@ -3579,7 +3582,7 @@ static int merge_block(struct archive_read* a, ssize_t block_size, while(1) { /* Get the size of current block chunk in this multivolume * archive file and read it. */ - cur_block_size = rar5_min(rar->file.bytes_remaining, + cur_block_size = rar5_min(rar5->file.bytes_remaining, block_size - partial_offset); if(cur_block_size < 1) { @@ -3589,12 +3592,12 @@ static int merge_block(struct archive_read* a, ssize_t block_size, archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Encountered invalid block size during block merge"); - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; return ARCHIVE_FATAL; } if(!read_ahead(a, cur_block_size, &lp)) { - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; return ARCHIVE_EOF; } @@ -3604,27 +3607,27 @@ static int merge_block(struct archive_read* a, ssize_t block_size, archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Consumed too much data when merging blocks"); - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; return ARCHIVE_FATAL; } /* Merge previous block chunk with current block chunk, * or create first block chunk if this is our first * iteration. */ - memcpy(&rar->vol.push_buf[partial_offset], lp, cur_block_size); + memcpy(&rar5->vol.push_buf[partial_offset], lp, cur_block_size); /* Advance the stream read pointer by this block chunk size. */ if(ARCHIVE_OK != consume(a, cur_block_size)) { /* Data was copied but stream pointer didn't advance; * stream position is unrecoverable. */ - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; return ARCHIVE_FATAL; } /* Update the pointers. `partial_offset` contains information * about the sum of merged block chunks. */ partial_offset += cur_block_size; - rar->file.bytes_remaining -= cur_block_size; + rar5->file.bytes_remaining -= cur_block_size; /* If `partial_offset` is the same as `block_size`, this means * we've merged all block chunks and we have a valid full @@ -3635,18 +3638,18 @@ static int merge_block(struct archive_read* a, ssize_t block_size, /* If we don't have any bytes to read, this means we should * switch to another multivolume archive file. */ - if(rar->file.bytes_remaining == 0) { - rar->merge_mode++; + if(rar5->file.bytes_remaining == 0) { + rar5->merge_mode++; ret = advance_multivolume(a); - rar->merge_mode--; + rar5->merge_mode--; if(ret != ARCHIVE_OK) { - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; return ret; } } } - *p = rar->vol.push_buf; + *p = rar5->vol.push_buf; /* If we're here, we can resume unpacking by processing the block * pointed to by the `*p` memory pointer. */ @@ -3655,19 +3658,19 @@ static int merge_block(struct archive_read* a, ssize_t block_size, } static int process_block(struct archive_read* a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; const uint8_t* p; int ret; /* If we don't have any data to be processed, this most probably means * we need to switch to the next volume. */ - if(rar->main.volume && rar->file.bytes_remaining == 0) { + if(rar5->main.volume && rar5->file.bytes_remaining == 0) { ret = advance_multivolume(a); if(ret != ARCHIVE_OK) return ret; } - if(rar->cstate.block_parsing_finished) { + if(rar5->cstate.block_parsing_finished) { ssize_t block_size; ssize_t to_skip; ssize_t cur_block_size; @@ -3687,7 +3690,7 @@ static int process_block(struct archive_read* a) { * `parse_block_header` as the second argument. */ ret = parse_block_header(a, p, &block_size, - &rar->last_block_hdr); + &rar5->last_block_hdr); if(ret != ARCHIVE_OK) { return ret; } @@ -3695,11 +3698,11 @@ static int process_block(struct archive_read* a) { /* Skip block header. Next data is huffman tables, * if present. */ to_skip = sizeof(struct compressed_block_header) + - bf_byte_count(&rar->last_block_hdr) + 1; + bf_byte_count(&rar5->last_block_hdr) + 1; /* If the block header's to_skip value exceeds the declared * remaining data, the archive is malformed. */ - if(to_skip > rar->file.bytes_remaining) { + if(to_skip > rar5->file.bytes_remaining) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Block header size exceeds remaining file data"); @@ -3709,7 +3712,7 @@ static int process_block(struct archive_read* a) { if(ARCHIVE_OK != consume(a, to_skip)) return ARCHIVE_EOF; - rar->file.bytes_remaining -= to_skip; + rar5->file.bytes_remaining -= to_skip; /* The block size gives information about the whole block size, * but the block could be stored in split form when using @@ -3718,9 +3721,9 @@ static int process_block(struct archive_read* a) { * part of the data will be in another file. */ cur_block_size = - rar5_min(rar->file.bytes_remaining, block_size); + rar5_min(rar5->file.bytes_remaining, block_size); - if(block_size > rar->file.bytes_remaining) { + if(block_size > rar5->file.bytes_remaining) { /* If current blocks' size is bigger than our data * size, this means we have a multivolume archive. * In this case, skip all base headers until the end @@ -3744,7 +3747,7 @@ static int process_block(struct archive_read* a) { * the *whole* block (merged from partial blocks * stored in multiple archives files). */ } else { - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; /* Read the whole block size into memory. This can take * up to 8 megabytes of memory in theoretical cases. @@ -3756,16 +3759,16 @@ static int process_block(struct archive_read* a) { } } - rar->cstate.block_buf = p; - rar->cstate.cur_block_size = cur_block_size; - rar->cstate.block_parsing_finished = 0; + rar5->cstate.block_buf = p; + rar5->cstate.cur_block_size = cur_block_size; + rar5->cstate.block_parsing_finished = 0; - rar->bits.in_addr = 0; - rar->bits.bit_addr = 0; + rar5->bits.in_addr = 0; + rar5->bits.bit_addr = 0; - if(bf_is_table_present(&rar->last_block_hdr)) { + if(bf_is_table_present(&rar5->last_block_hdr)) { /* Load Huffman tables. */ - ret = parse_tables(a, rar, p); + ret = parse_tables(a, rar5, p); if(ret != ARCHIVE_OK) { /* Error during decompression of Huffman * tables. */ @@ -3774,7 +3777,7 @@ static int process_block(struct archive_read* a) { } } else { /* Block parsing not finished, reuse previous memory buffer. */ - p = rar->cstate.block_buf; + p = rar5->cstate.block_buf; } /* Uncompress the block, or a part of it, depending on how many bytes @@ -3787,22 +3790,22 @@ static int process_block(struct archive_read* a) { return ret; } - if(rar->cstate.block_parsing_finished && - rar->cstate.switch_multivolume == 0 && - rar->cstate.cur_block_size > 0) + if(rar5->cstate.block_parsing_finished && + rar5->cstate.switch_multivolume == 0 && + rar5->cstate.cur_block_size > 0) { /* If we're processing a normal block, consume the whole * block. We can do this because we've already read the whole * block to memory. */ - if(ARCHIVE_OK != consume(a, rar->cstate.cur_block_size)) + if(ARCHIVE_OK != consume(a, rar5->cstate.cur_block_size)) return ARCHIVE_FATAL; - rar->file.bytes_remaining -= rar->cstate.cur_block_size; - } else if(rar->cstate.switch_multivolume) { + rar5->file.bytes_remaining -= rar5->cstate.cur_block_size; + } else if(rar5->cstate.switch_multivolume) { /* Don't consume the block if we're doing multivolume * processing. The volume switching function will consume * the proper count of bytes instead. */ - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; } return ARCHIVE_OK; @@ -3812,13 +3815,13 @@ static int process_block(struct archive_read* a) { * * Returns ARCHIVE_OK when those arguments can be used, ARCHIVE_RETRY * when there is no data on the stack. */ -static int use_data(struct rar5* rar, const void** buf, size_t* size, +static int use_data(struct rar5 *rar5, const void** buf, size_t* size, int64_t* offset) { int i; - for(i = 0; i < rar5_countof(rar->cstate.dready); i++) { - struct data_ready *d = &rar->cstate.dready[i]; + for(i = 0; i < rar5_countof(rar5->cstate.dready); i++) { + struct data_ready *d = &rar5->cstate.dready[i]; if(d->used) { if(buf) *buf = d->buf; @@ -3833,14 +3836,14 @@ static int use_data(struct rar5* rar, const void** buf, size_t* size, return ARCHIVE_RETRY; } -static void clear_data_ready_stack(struct rar5* rar) { - memset(&rar->cstate.dready, 0, sizeof(rar->cstate.dready)); +static void clear_data_ready_stack(struct rar5 *rar5) { + memset(&rar5->cstate.dready, 0, sizeof(rar5->cstate.dready)); } -/* Pushes the `buf`, `size` and `offset` arguments to the rar->cstate.dready +/* Pushes the `buf`, `size` and `offset` arguments to the rar5->cstate.dready * FIFO stack. Those values will be popped from this stack by the `use_data` * function. */ -static int push_data_ready(struct archive_read* a, struct rar5* rar, +static int push_data_ready(struct archive_read* a, struct rar5 *rar5, const uint8_t* buf, size_t size, int64_t offset) { int i; @@ -3851,18 +3854,18 @@ static int push_data_ready(struct archive_read* a, struct rar5* rar, * because we're interested only in the side effect: building up the * internal window circular buffer. This window buffer will be used * later during unpacking of requested data. */ - if(rar->skip_mode) + if(rar5->skip_mode) return ARCHIVE_OK; /* Sanity check. */ - if(offset != rar->file.last_offset + rar->file.last_size) { + if(offset != rar5->file.last_offset + rar5->file.last_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Sanity check error: output stream is not continuous"); return ARCHIVE_FATAL; } - for(i = 0; i < rar5_countof(rar->cstate.dready); i++) { - struct data_ready* d = &rar->cstate.dready[i]; + for(i = 0; i < rar5_countof(rar5->cstate.dready); i++) { + struct data_ready* d = &rar5->cstate.dready[i]; if(!d->used) { d->used = 1; d->buf = buf; @@ -3870,21 +3873,21 @@ static int push_data_ready(struct archive_read* a, struct rar5* rar, d->offset = offset; /* These fields are used only in sanity checking. */ - rar->file.last_offset = offset; - rar->file.last_size = size; + rar5->file.last_offset = offset; + rar5->file.last_size = size; /* Calculate the checksum of this new block before * submitting data to libarchive's engine. */ - update_crc(rar, d->buf, d->size); + update_crc(rar5, d->buf, d->size); return ARCHIVE_OK; } } - /* Program counter will reach this code if the `rar->cstate.data_ready` - * stack will be filled up so that no new entries will be allowed. The - * code shouldn't allow such situation to occur. So we treat this case - * as an internal error. */ + /* Program counter will reach this code if the + * `rar5->cstate.data_ready` stack will be filled up so that no new + * entries will be allowed. The code shouldn't allow such situation to + * occur. So we treat this case as an internal error. */ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Premature end of data_ready stack"); @@ -3934,23 +3937,23 @@ static int push_data_ready(struct archive_read* a, struct rar5* rar, * */ static int do_uncompress_file(struct archive_read* a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int ret; int64_t max_end_pos; - if(!rar->cstate.initialized) { + if(!rar5->cstate.initialized) { /* Don't perform full context reinitialization if we're * processing a solid archive. */ - if(!rar->main.solid || !rar->cstate.window_buf) { - if((ret = init_unpack(rar)) != ARCHIVE_OK) + if(!rar5->main.solid || !rar5->cstate.window_buf) { + if((ret = init_unpack(rar5)) != ARCHIVE_OK) return ret; } - rar->cstate.initialized = 1; + rar5->cstate.initialized = 1; } /* Don't allow extraction if window_size is invalid. */ - if(rar->cstate.window_size == 0) { + if(rar5->cstate.window_size == 0) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Invalid window size declaration in this file"); @@ -3959,7 +3962,7 @@ static int do_uncompress_file(struct archive_read* a) { return ARCHIVE_FAILED; } - if(rar->cstate.all_filters_applied == 1) { + if(rar5->cstate.all_filters_applied == 1) { /* We use while(1) here, but standard case allows for just 1 * iteration. The loop will iterate if process_block() didn't * generate any data at all. This can happen if the block @@ -3970,12 +3973,12 @@ static int do_uncompress_file(struct archive_read* a) { if(ret != ARCHIVE_OK) return ret; - if(rar->cstate.last_write_ptr == - rar->cstate.write_ptr) { + if(rar5->cstate.last_write_ptr == + rar5->cstate.write_ptr) { /* The block didn't generate any new data, * so just process a new block if this one * wasn't the last block in the file. */ - if (bf_is_last_block(&rar->last_block_hdr)) { + if (bf_is_last_block(&rar5->last_block_hdr)) { return ARCHIVE_EOF; } @@ -3997,13 +4000,13 @@ static int do_uncompress_file(struct archive_read* a) { return ret; } - if(cdeque_size(&rar->cstate.filters) > 0) { + if(cdeque_size(&rar5->cstate.filters) > 0) { /* Check if we can write something before hitting first * filter. */ struct filter_info* flt; /* Get the block_start offset from the first filter. */ - if(CDE_OK != cdeque_front(&rar->cstate.filters, + if(CDE_OK != cdeque_front(&rar5->cstate.filters, cdeque_filter_p(&flt))) { archive_set_error(&a->archive, @@ -4013,15 +4016,15 @@ static int do_uncompress_file(struct archive_read* a) { } max_end_pos = rar5_min(flt->block_start, - rar->cstate.write_ptr); + rar5->cstate.write_ptr); } else { /* There are no filters defined, or all filters were applied. * This means we can just store the data without any * postprocessing. */ - max_end_pos = rar->cstate.write_ptr; + max_end_pos = rar5->cstate.write_ptr; } - if(max_end_pos == rar->cstate.last_write_ptr) { + if(max_end_pos == rar5->cstate.last_write_ptr) { /* We can't write anything yet. The block uncompression * function did not generate enough data, and no filter can be * applied. At the same time we don't have any data that can be @@ -4038,9 +4041,9 @@ static int do_uncompress_file(struct archive_read* a) { * So let's do it. The push_window_data() function will * effectively return the selected data block to the user * application. */ - push_window_data(a, rar, rar->cstate.last_write_ptr, + push_window_data(a, rar5, rar5->cstate.last_write_ptr, max_end_pos); - rar->cstate.last_write_ptr = max_end_pos; + rar5->cstate.last_write_ptr = max_end_pos; } return ARCHIVE_OK; @@ -4061,19 +4064,19 @@ static int uncompress_file(struct archive_read* a) { static int do_unstore_file(struct archive_read* a, - struct rar5* rar, const void** buf, size_t* size, int64_t* offset) + struct rar5 *rar5, const void** buf, size_t* size, int64_t* offset) { size_t to_read; const uint8_t* p; - if(rar->file.bytes_remaining == 0 && rar->main.volume > 0 && - rar->generic.split_after > 0) + if(rar5->file.bytes_remaining == 0 && rar5->main.volume > 0 && + rar5->generic.split_after > 0) { int ret; - rar->cstate.switch_multivolume = 1; + rar5->cstate.switch_multivolume = 1; ret = advance_multivolume(a); - rar->cstate.switch_multivolume = 0; + rar5->cstate.switch_multivolume = 0; if(ret != ARCHIVE_OK) { /* Failed to advance to next multivolume archive @@ -4082,7 +4085,7 @@ static int do_unstore_file(struct archive_read* a, } } - to_read = rar5_min(rar->file.bytes_remaining, 64 * 1024); + to_read = rar5_min(rar5->file.bytes_remaining, 64 * 1024); if(to_read == 0) { return ARCHIVE_EOF; } @@ -4099,16 +4102,16 @@ static int do_unstore_file(struct archive_read* a, if(buf) *buf = p; if(size) *size = to_read; - if(offset) *offset = rar->cstate.last_unstore_ptr; + if(offset) *offset = rar5->cstate.last_unstore_ptr; - rar->file.bytes_remaining -= to_read; - rar->cstate.last_unstore_ptr += to_read; + rar5->file.bytes_remaining -= to_read; + rar5->cstate.last_unstore_ptr += to_read; - update_crc(rar, p, to_read); + update_crc(rar5, p, to_read); return ARCHIVE_OK; } -static int do_unpack(struct archive_read* a, struct rar5* rar, +static int do_unpack(struct archive_read* a, struct rar5 *rar5, const void** buf, size_t* size, int64_t* offset) { enum COMPRESSION_METHOD { @@ -4116,12 +4119,12 @@ static int do_unpack(struct archive_read* a, struct rar5* rar, BEST = 5 }; - if(rar->file.service > 0) { - return do_unstore_file(a, rar, buf, size, offset); + if(rar5->file.service > 0) { + return do_unstore_file(a, rar5, buf, size, offset); } else { - switch(rar->cstate.method) { + switch(rar5->cstate.method) { case STORE: - return do_unstore_file(a, rar, buf, size, + return do_unstore_file(a, rar5, buf, size, offset); case FASTEST: /* fallthrough */ @@ -4138,13 +4141,13 @@ static int do_unpack(struct archive_read* a, struct rar5* rar, * accordingly. At this point the decoder doesn't have any * pending uncompressed data blocks, so the current position in * the output file should be last_write_ptr. */ - if (offset) *offset = rar->cstate.last_write_ptr; + if (offset) *offset = rar5->cstate.last_write_ptr; return uncompress_file(a); default: archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Compression method not supported: 0x%x", - (unsigned int)rar->cstate.method); + (unsigned int)rar5->cstate.method); return ARCHIVE_FATAL; } @@ -4157,7 +4160,7 @@ static int do_unpack(struct archive_read* a, struct rar5* rar, } static int verify_checksums(struct archive_read* a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int verify_crc; /* Check checksums only when actually unpacking the data. There's no @@ -4165,7 +4168,7 @@ static int verify_checksums(struct archive_read* a) { * (skipping in solid archives is the same thing as unpacking compressed * data and discarding the result). */ - if(!rar->skip_mode) { + if(!rar5->skip_mode) { /* Always check checksums if we're not in skip mode */ verify_crc = 1; } else { @@ -4189,20 +4192,20 @@ static int verify_checksums(struct archive_read* a) { * process is already over and we can check if calculated * checksum (CRC32 or BLAKE2sp) is the same as what is stored * in the archive. */ - if(rar->file.stored_crc32 > 0) { + if(rar5->file.stored_crc32 > 0) { /* Check CRC32 only when the file contains a CRC32 * value for this file. */ - if(rar->file.calculated_crc32 != - rar->file.stored_crc32) { + if(rar5->file.calculated_crc32 != + rar5->file.stored_crc32) { /* Checksums do not match; the unpacked file * is corrupted. */ DEBUG_CODE { printf("Checksum error: CRC32 " "(was: %08" PRIx32 ", expected: %08" PRIx32 ")\n", - rar->file.calculated_crc32, - rar->file.stored_crc32); + rar5->file.calculated_crc32, + rar5->file.stored_crc32); } #ifndef DONT_FAIL_ON_CRC_ERROR @@ -4215,13 +4218,13 @@ static int verify_checksums(struct archive_read* a) { DEBUG_CODE { printf("Checksum OK: CRC32 " "(%08" PRIx32 "/%08" PRIx32 ")\n", - rar->file.stored_crc32, - rar->file.calculated_crc32); + rar5->file.stored_crc32, + rar5->file.calculated_crc32); } } } - if(rar->file.has_blake2 > 0) { + if(rar5->file.has_blake2 > 0) { /* BLAKE2sp is an optional checksum algorithm that is * added to RARv5 archives when using the `-htb` switch * during creation of archive. @@ -4236,9 +4239,9 @@ static int verify_checksums(struct archive_read* a) { * This is why we're explicitly ignoring it. */ uint8_t b2_buf[32]; - (void) blake2sp_final(&rar->file.b2state, b2_buf, 32); + (void) blake2sp_final(&rar5->file.b2state, b2_buf, 32); - if(memcmp(&rar->file.blake2sp, b2_buf, 32) != 0) { + if(memcmp(&rar5->file.blake2sp, b2_buf, 32) != 0) { #ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, @@ -4272,23 +4275,23 @@ static void rar5_signature(char *buf) { static int rar5_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; int ret; if (size) *size = 0; - if (rar->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { - rar->has_encrypted_entries = 0; + if (rar5->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { + rar5->has_encrypted_entries = 0; } - if (rar->headers_are_encrypted || rar->cstate.data_encrypted) { + if (rar5->headers_are_encrypted || rar5->cstate.data_encrypted) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Reading encrypted data is not currently supported"); return ARCHIVE_FAILED; } - if(rar->file.dir > 0) { + if(rar5->file.dir > 0) { /* Don't process any data if this file entry was declared * as a directory. This is needed, because entries marked as * directory doesn't have any dictionary buffer allocated, so @@ -4298,28 +4301,28 @@ static int rar5_read_data(struct archive_read *a, const void **buff, return ARCHIVE_FATAL; } - if(!rar->skip_mode && (rar->cstate.last_write_ptr > rar->file.unpacked_size)) { + if(!rar5->skip_mode && (rar5->cstate.last_write_ptr > rar5->file.unpacked_size)) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Unpacker has written too many bytes"); return ARCHIVE_FATAL; } - ret = use_data(rar, buff, size, offset); + ret = use_data(rar5, buff, size, offset); if(ret == ARCHIVE_OK) { return ret; } - if(rar->file.eof == 1) { + if(rar5->file.eof == 1) { return ARCHIVE_EOF; } - ret = do_unpack(a, rar, buff, size, offset); + ret = do_unpack(a, rar5, buff, size, offset); if(ret != ARCHIVE_OK) { return ret; } - if(rar->file.bytes_remaining == 0 && - rar->cstate.last_write_ptr == rar->file.unpacked_size) + if(rar5->file.bytes_remaining == 0 && + rar5->cstate.last_write_ptr == rar5->file.unpacked_size) { /* If all bytes of current file were processed, run * finalization. @@ -4329,7 +4332,7 @@ static int rar5_read_data(struct archive_read *a, const void **buff, * value in the last `archive_read_data` call to signal an error * to the user. */ - rar->file.eof = 1; + rar5->file.eof = 1; return verify_global_checksums(a); } @@ -4337,9 +4340,9 @@ static int rar5_read_data(struct archive_read *a, const void **buff, } static int rar5_read_data_skip(struct archive_read *a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; - if(rar->main.solid && (rar->cstate.data_encrypted == 0)) { + if(rar5->main.solid && (rar5->cstate.data_encrypted == 0)) { /* In solid archives, instead of skipping the data, we need to * extract it, and dispose the result. The side effect of this * operation will be setting up the initial window buffer state @@ -4351,7 +4354,7 @@ static int rar5_read_data_skip(struct archive_read *a) { int ret; /* Make sure to process all blocks in the compressed stream. */ - while(rar->file.bytes_remaining > 0) { + while(rar5->file.bytes_remaining > 0) { /* Setting the "skip mode" will allow us to skip * checksum checks during data skipping. Checking the * checksum of skipped data isn't really necessary and @@ -4360,14 +4363,14 @@ static int rar5_read_data_skip(struct archive_read *a) { * This is incremented instead of setting to 1 because * this data skipping function can be called * recursively. */ - rar->skip_mode++; + rar5->skip_mode++; /* We're disposing 1 block of data, so we use triple * NULLs in arguments. */ ret = rar5_read_data(a, NULL, NULL, NULL); /* Turn off "skip mode". */ - rar->skip_mode--; + rar5->skip_mode--; if(ret < 0 || ret == ARCHIVE_EOF) { /* Propagate any potential error conditions @@ -4380,11 +4383,11 @@ static int rar5_read_data_skip(struct archive_read *a) { * stream. Each file in non-solid archives starts from an empty * window buffer. */ - if(ARCHIVE_OK != consume(a, rar->file.bytes_remaining)) { + if(ARCHIVE_OK != consume(a, rar5->file.bytes_remaining)) { return ARCHIVE_FATAL; } - rar->file.bytes_remaining = 0; + rar5->file.bytes_remaining = 0; } return ARCHIVE_OK; @@ -4403,18 +4406,18 @@ static int64_t rar5_seek_data(struct archive_read *a, int64_t offset, } static int rar5_cleanup(struct archive_read *a) { - struct rar5 *rar = a->format->data; + struct rar5 *rar5 = a->format->data; - free(rar->cstate.window_buf); - free(rar->cstate.filtered_buf); - clear_data_ready_stack(rar); + free(rar5->cstate.window_buf); + free(rar5->cstate.filtered_buf); + clear_data_ready_stack(rar5); - free(rar->vol.push_buf); + free(rar5->vol.push_buf); - free_filters(rar); - rar5_deinit(rar); + free_filters(rar5); + rar5_deinit(rar5); - free(rar); + free(rar5); a->format->data = NULL; return ARCHIVE_OK; @@ -4428,9 +4431,9 @@ static int rar5_capabilities(struct archive_read * a) { static int rar5_has_encrypted_entries(struct archive_read *_a) { if (_a && _a->format) { - struct rar5 *rar = _a->format->data; - if (rar) { - return rar->has_encrypted_entries; + struct rar5 *rar5 = _a->format->data; + if (rar5) { + return rar5->has_encrypted_entries; } } @@ -4438,50 +4441,50 @@ static int rar5_has_encrypted_entries(struct archive_read *_a) { } /* Must match deallocations in rar5_deinit */ -static int rar5_init(struct rar5* rar) { - memset(rar, 0, sizeof(struct rar5)); +static int rar5_init(struct rar5 *rar5) { + memset(rar5, 0, sizeof(struct rar5)); - if(CDE_OK != cdeque_init(&rar->cstate.filters, 8192)) + if(CDE_OK != cdeque_init(&rar5->cstate.filters, 8192)) return ARCHIVE_FATAL; /* * Until enough data has been read, we cannot tell about * any encrypted entries yet. */ - rar->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; + rar5->has_encrypted_entries = ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW; return ARCHIVE_OK; } /* Must match allocations in rar5_init */ -static void rar5_deinit(struct rar5* rar) { - cdeque_free(&rar->cstate.filters); +static void rar5_deinit(struct rar5 *rar5) { + cdeque_free(&rar5->cstate.filters); } int archive_read_support_format_rar5(struct archive *_a) { struct archive_read* ar; int ret; - struct rar5* rar; + struct rar5 *rar5; if(ARCHIVE_OK != (ret = get_archive_read(_a, &ar))) return ret; - rar = malloc(sizeof(*rar)); - if(rar == NULL) { + rar5 = malloc(sizeof(*rar5)); + if(rar5 == NULL) { archive_set_error(&ar->archive, ENOMEM, "Can't allocate rar5 data"); return ARCHIVE_FATAL; } - if(ARCHIVE_OK != rar5_init(rar)) { + if(ARCHIVE_OK != rar5_init(rar5)) { archive_set_error(&ar->archive, ENOMEM, "Can't allocate rar5 filter buffer"); - free(rar); + free(rar5); return ARCHIVE_FATAL; } ret = __archive_read_register_format(ar, - rar, + rar5, "rar5", rar5_bid, rar5_options, @@ -4494,8 +4497,8 @@ int archive_read_support_format_rar5(struct archive *_a) { rar5_has_encrypted_entries); if(ret != ARCHIVE_OK) { - rar5_deinit(rar); - free(rar); + rar5_deinit(rar5); + free(rar5); } return ARCHIVE_OK; diff --git a/libarchive/archive_read_support_format_raw.c b/libarchive/archive_read_support_format_raw.c index b49c15fd8..cda3c1e49 100644 --- a/libarchive/archive_read_support_format_raw.c +++ b/libarchive/archive_read_support_format_raw.c @@ -38,7 +38,7 @@ #include "archive_private.h" #include "archive_read_private.h" -struct raw_info { +struct raw { int64_t offset; /* Current position in the file. */ int64_t unconsumed; int end_of_file; @@ -56,21 +56,21 @@ int archive_read_support_format_raw(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; - struct raw_info *info; + struct raw *raw; int r; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_format_raw"); - info = calloc(1, sizeof(*info)); - if (info == NULL) { + raw = calloc(1, sizeof(*raw)); + if (raw == NULL) { archive_set_error(&a->archive, ENOMEM, - "Can't allocate raw_info data"); + "Can't allocate raw data"); return (ARCHIVE_FATAL); } r = __archive_read_register_format(a, - info, + raw, "raw", archive_read_format_raw_bid, NULL, @@ -82,7 +82,7 @@ archive_read_support_format_raw(struct archive *_a) NULL, NULL); if (r != ARCHIVE_OK) - free(info); + free(raw); return (r); } @@ -108,9 +108,9 @@ static int archive_read_format_raw_read_header(struct archive_read *a, struct archive_entry *entry) { - struct raw_info *info = a->format->data; + struct raw *raw = a->format->data; - if (info->end_of_file) + if (raw->end_of_file) return (ARCHIVE_EOF); a->archive.archive_format = ARCHIVE_FORMAT_RAW; @@ -128,24 +128,24 @@ static int archive_read_format_raw_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct raw_info *info = a->format->data; + struct raw *raw = a->format->data; ssize_t avail; /* Consume the bytes we read last time. */ - if (info->unconsumed) { - __archive_read_consume(a, info->unconsumed); - info->unconsumed = 0; + if (raw->unconsumed) { + __archive_read_consume(a, raw->unconsumed); + raw->unconsumed = 0; } - if (info->end_of_file) + if (raw->end_of_file) return (ARCHIVE_EOF); /* Get whatever bytes are immediately available. */ *buff = __archive_read_ahead(a, 1, &avail); if (avail > 0) { /* Return the bytes we just read */ - *offset = info->offset; - if (archive_ckd_add_i64(&info->offset, info->offset, avail)) { + *offset = raw->offset; + if (archive_ckd_add_i64(&raw->offset, raw->offset, avail)) { avail = INT64_MAX - *offset; if (avail == 0) { *size = 0; @@ -153,18 +153,18 @@ archive_read_format_raw_read_data(struct archive_read *a, } } *size = avail; - info->unconsumed = avail; + raw->unconsumed = avail; return (ARCHIVE_OK); } else if (0 == avail) { /* Record and return end-of-file. */ - info->end_of_file = 1; + raw->end_of_file = 1; *size = 0; - *offset = info->offset; + *offset = raw->offset; return (ARCHIVE_EOF); } else { /* Record and return an error. */ *size = 0; - *offset = info->offset; + *offset = raw->offset; return ((int)avail); } } @@ -172,23 +172,23 @@ archive_read_format_raw_read_data(struct archive_read *a, static int archive_read_format_raw_read_data_skip(struct archive_read *a) { - struct raw_info *info = a->format->data; + struct raw *raw = a->format->data; /* Consume the bytes we read last time. */ - if (info->unconsumed) { - __archive_read_consume(a, info->unconsumed); - info->unconsumed = 0; + if (raw->unconsumed) { + __archive_read_consume(a, raw->unconsumed); + raw->unconsumed = 0; } - info->end_of_file = 1; + raw->end_of_file = 1; return (ARCHIVE_OK); } static int archive_read_format_raw_cleanup(struct archive_read *a) { - struct raw_info *info = a->format->data; + struct raw *raw = a->format->data; - free(info); + free(raw); a->format->data = NULL; return (ARCHIVE_OK); } diff --git a/libarchive/archive_read_support_format_warc.c b/libarchive/archive_read_support_format_warc.c index 50a9c3eae..d70c71832 100644 --- a/libarchive/archive_read_support_format_warc.c +++ b/libarchive/archive_read_support_format_warc.c @@ -105,7 +105,7 @@ typedef struct { char *str; } warc_strbuf_t; -struct warc_s { +struct warc { /* Content length of the current record */ int64_t cntlen; /* Bytes processed from the current record */ @@ -143,20 +143,20 @@ int archive_read_support_format_warc(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; - struct warc_s *w; + struct warc *warc; int r; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_format_warc"); - if ((w = calloc(1, sizeof(*w))) == NULL) { + if ((warc = calloc(1, sizeof(*warc))) == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate warc data"); return (ARCHIVE_FATAL); } r = __archive_read_register_format(a, - w, + warc, "warc", archive_read_format_warc_bid, NULL, @@ -169,7 +169,7 @@ archive_read_support_format_warc(struct archive *_a) NULL); if (r != ARCHIVE_OK) { - free(w); + free(warc); return (r); } return (ARCHIVE_OK); @@ -178,13 +178,13 @@ archive_read_support_format_warc(struct archive *_a) static int archive_read_format_warc_cleanup(struct archive_read *a) { - struct warc_s *w = a->format->data; + struct warc *warc = a->format->data; - if (w->pool.len > 0U) { - free(w->pool.str); + if (warc->pool.len > 0U) { + free(warc->pool.str); } - archive_string_free(&w->sver); - free(w); + archive_string_free(&warc->sver); + free(warc); a->format->data = NULL; return (ARCHIVE_OK); } @@ -220,7 +220,7 @@ archive_read_format_warc_read_header(struct archive_read *a, struct archive_entry *entry) { #define HDR_PROBE_LEN (12U) - struct warc_s *w = a->format->data; + struct warc *warc = a->format->data; unsigned int ver; const char *buf; ssize_t nrd; @@ -295,18 +295,18 @@ start_over: /* Report this archive as WARC. */ a->archive.archive_format = ARCHIVE_FORMAT_WARC; - if (ver != w->pver) { + if (ver != warc->pver) { /* Format this entry's WARC version. */ - archive_string_sprintf(&w->sver, + archive_string_sprintf(&warc->sver, "WARC/%u.%u", ver / 10000, (ver % 10000) / 100); /* Remember the version for later entries. */ - w->pver = ver; + warc->pver = ver; } /* Parse the record type. */ ftyp = warc_read_type(buf, eoh - buf); /* Save content state for subsequent read calls. */ - w->cntlen = cntlen; - w->cntoff = 0; + warc->cntlen = cntlen; + warc->cntoff = 0; mtime = 0;/* Avoid compiler warnings on some platforms. */ switch (ftyp) { @@ -324,21 +324,21 @@ start_over: } /* Copy the name into the reusable string pool to avoid a malloc/free * roundtrip for each entry. */ - if (fnam.len + 1U > w->pool.len) { - w->pool.len = ((fnam.len + 64U) / 64U) * 64U; - tmp = realloc(w->pool.str, w->pool.len); + if (fnam.len + 1U > warc->pool.len) { + warc->pool.len = ((fnam.len + 64U) / 64U) * 64U; + tmp = realloc(warc->pool.str, warc->pool.len); if (tmp == NULL) { archive_set_error( &a->archive, ENOMEM, "Out of memory"); return (ARCHIVE_FATAL); } - w->pool.str = tmp; + warc->pool.str = tmp; } - memcpy(w->pool.str, fnam.str, fnam.len); - w->pool.str[fnam.len] = '\0'; + memcpy(warc->pool.str, fnam.str, fnam.len); + warc->pool.str[fnam.len] = '\0'; /* Hide the pool implementation behind the parsed string. */ - fnam.str = w->pool.str; + fnam.str = warc->pool.str; /* Use a Last-Modified record header when present; otherwise fall back * to WARC-Date. */ @@ -399,20 +399,20 @@ static int archive_read_format_warc_read_data(struct archive_read *a, const void **buf, size_t *bsz, int64_t *off) { - struct warc_s *w = a->format->data; + struct warc *warc = a->format->data; const char *rab; ssize_t nrd; - if (w->unconsumed) { - __archive_read_consume(a, w->unconsumed); - w->unconsumed = 0; + if (warc->unconsumed) { + __archive_read_consume(a, warc->unconsumed); + warc->unconsumed = 0; } - if (w->cntoff >= w->cntlen) { + if (warc->cntoff >= warc->cntlen) { /* No data is available to return for this entry. */ *buf = NULL; *bsz = 0U; - *off = w->cntoff; + *off = warc->cntoff; return (ARCHIVE_EOF); } @@ -425,35 +425,35 @@ archive_read_format_warc_read_data(struct archive_read *a, const void **buf, archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Truncated WARC file data"); return (ARCHIVE_FATAL); - } else if ((int64_t)nrd > w->cntlen - w->cntoff) { + } else if ((int64_t)nrd > warc->cntlen - warc->cntoff) { /* Clamp reads to Content-Length. */ - nrd = w->cntlen - w->cntoff; + nrd = warc->cntlen - warc->cntoff; } - *off = w->cntoff; + *off = warc->cntoff; *bsz = nrd; *buf = rab; - w->cntoff += nrd; - w->unconsumed = nrd; + warc->cntoff += nrd; + warc->unconsumed = nrd; return (ARCHIVE_OK); } static int archive_read_format_warc_skip(struct archive_read *a) { - struct warc_s *w = a->format->data; + struct warc *warc = a->format->data; - if (w->cntoff > w->cntlen) + if (warc->cntoff > warc->cntlen) return (ARCHIVE_FATAL); - if (w->unconsumed) { - __archive_read_consume(a, w->unconsumed); - w->unconsumed = 0; + if (warc->unconsumed) { + __archive_read_consume(a, warc->unconsumed); + warc->unconsumed = 0; } - if (__archive_read_consume(a, w->cntlen - w->cntoff) < 0 || + if (__archive_read_consume(a, warc->cntlen - warc->cntoff) < 0 || __archive_read_consume(a, 4U/*\r\n\r\n separator*/) < 0) return (ARCHIVE_FATAL); - w->cntlen = 0; - w->cntoff = 0; + warc->cntlen = 0; + warc->cntoff = 0; return (ARCHIVE_OK); } diff --git a/libarchive/archive_write_set_format_ar.c b/libarchive/archive_write_set_format_ar.c index 82eff3dd1..57572ea38 100644 --- a/libarchive/archive_write_set_format_ar.c +++ b/libarchive/archive_write_set_format_ar.c @@ -44,7 +44,7 @@ #include "archive_write_private.h" #include "archive_write_set_format_private.h" -struct ar_w { +struct ar { uint64_t entry_bytes_remaining; uint64_t entry_padding; int is_strtab; @@ -120,7 +120,7 @@ archive_write_set_format_ar_svr4(struct archive *_a) static int archive_write_set_format_ar(struct archive_write *a) { - struct ar_w *ar; + struct ar *ar; /* If someone else was already registered, unregister them. */ (void)__archive_write_unregister_format(a); @@ -147,7 +147,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) int ret, append_fn; char buff[60]; char *ss; - struct ar_w *ar = a->format_data; + struct ar *ar = a->format_data; struct archive_string se; const char *pathname; const char *filename; @@ -363,7 +363,7 @@ size: static ssize_t archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) { - struct ar_w *ar = a->format_data; + struct ar *ar = a->format_data; int ret; if (s > ar->entry_bytes_remaining) @@ -398,7 +398,7 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) static int archive_write_ar_free(struct archive_write *a) { - struct ar_w *ar = a->format_data; + struct ar *ar = a->format_data; if (ar == NULL) return (ARCHIVE_OK); @@ -416,7 +416,7 @@ archive_write_ar_free(struct archive_write *a) static int archive_write_ar_close(struct archive_write *a) { - struct ar_w *ar = a->format_data; + struct ar *ar = a->format_data; int ret; /* @@ -435,7 +435,7 @@ archive_write_ar_close(struct archive_write *a) static int archive_write_ar_finish_entry(struct archive_write *a) { - struct ar_w *ar = a->format_data; + struct ar *ar = a->format_data; int ret; if (ar->entry_bytes_remaining != 0) { diff --git a/libarchive/archive_write_set_format_mtree.c b/libarchive/archive_write_set_format_mtree.c index 1d94fbbb6..b3433507e 100644 --- a/libarchive/archive_write_set_format_mtree.c +++ b/libarchive/archive_write_set_format_mtree.c @@ -117,7 +117,7 @@ struct mtree_entry { int64_t ino; }; -struct mtree_writer { +struct mtree { struct mtree_entry *mtree_entry; struct mtree_entry *root; struct mtree_entry *cur_dirent; @@ -220,10 +220,10 @@ static int attr_counter_inc(struct attr_counter **, struct attr_counter *, struct attr_counter *, struct mtree_entry *); static struct attr_counter * attr_counter_new(struct mtree_entry *, struct attr_counter *); -static int attr_counter_set_collect(struct mtree_writer *, +static int attr_counter_set_collect(struct mtree *, struct mtree_entry *); -static void attr_counter_set_free(struct mtree_writer *); -static int get_global_set_keys(struct mtree_writer *, struct mtree_entry *); +static void attr_counter_set_free(struct mtree *); +static int get_global_set_keys(struct mtree *, struct mtree_entry *); static int mtree_entry_add_child_tail(struct mtree_entry *, struct mtree_entry *); static int mtree_entry_create_virtual_dir(struct archive_write *, const char *, @@ -236,14 +236,14 @@ static int mtree_entry_exchange_same_entry(struct archive_write *, static void mtree_entry_free(struct mtree_entry *); static int mtree_entry_new(struct archive_write *, struct archive_entry *, struct mtree_entry **); -static void mtree_entry_register_free(struct mtree_writer *); -static void mtree_entry_register_init(struct mtree_writer *); +static void mtree_entry_register_free(struct mtree *); +static void mtree_entry_register_init(struct mtree *); static int mtree_entry_setup_filenames(struct archive_write *, struct mtree_entry *, struct archive_entry *); static int mtree_entry_tree_add(struct archive_write *, struct mtree_entry **); -static void sum_init(struct mtree_writer *); -static void sum_update(struct mtree_writer *, const void *, size_t); -static void sum_final(struct mtree_writer *, struct reg_info *); +static void sum_init(struct mtree *); +static void sum_update(struct mtree *, const void *, size_t); +static void sum_final(struct mtree *, struct reg_info *); static void sum_write(struct archive_string *, struct reg_info *); static int write_mtree_entry(struct archive_write *, struct mtree_entry *); static int write_dot_dot_entry(struct archive_write *, struct mtree_entry *); @@ -358,7 +358,7 @@ mtree_quote(struct archive_string *s, const char *str) * Indent a line as the mtree utility does so it is readable for people. */ static void -mtree_indent(struct mtree_writer *mtree) +mtree_indent(struct mtree *mtree) { int i, fn, nd, pd; const char *r, *s, *x; @@ -434,7 +434,7 @@ mtree_indent(struct mtree_writer *mtree) * collected by the attr_counter_set_collect() function. */ static void -write_global(struct mtree_writer *mtree) +write_global(struct mtree *mtree) { struct archive_string setstr; struct archive_string unsetstr; @@ -636,7 +636,7 @@ attr_counter_inc(struct attr_counter **top, struct attr_counter *ac, * Tabulate uid, gid, mode and fflags of a entry in order to be used for /set. */ static int -attr_counter_set_collect(struct mtree_writer *mtree, struct mtree_entry *me) +attr_counter_set_collect(struct mtree *mtree, struct mtree_entry *me) { struct attr_counter *ac, *last; struct attr_counter_set *acs = &mtree->acs; @@ -713,7 +713,7 @@ attr_counter_set_collect(struct mtree_writer *mtree, struct mtree_entry *me) } static void -attr_counter_set_free(struct mtree_writer *mtree) +attr_counter_set_free(struct mtree *mtree) { struct attr_counter_set *acs = &mtree->acs; @@ -724,7 +724,7 @@ attr_counter_set_free(struct mtree_writer *mtree) } static int -get_global_set_keys(struct mtree_writer *mtree, struct mtree_entry *me) +get_global_set_keys(struct mtree *mtree, struct mtree_entry *me) { int keys; @@ -913,7 +913,7 @@ static int archive_write_mtree_header(struct archive_write *a, struct archive_entry *entry) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; struct mtree_entry *mtree_entry; int r, r2; @@ -956,7 +956,7 @@ archive_write_mtree_header(struct archive_write *a, static int write_mtree_entry(struct archive_write *a, struct mtree_entry *me) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; struct archive_string *str; int keys, ret; @@ -1107,7 +1107,7 @@ write_mtree_entry(struct archive_write *a, struct mtree_entry *me) static int write_dot_dot_entry(struct archive_write *a, struct mtree_entry *n) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; int ret; if (n->parentdir.s) { @@ -1142,7 +1142,7 @@ write_dot_dot_entry(struct archive_write *a, struct mtree_entry *n) static int write_mtree_entry_tree(struct archive_write *a) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; struct mtree_entry *np = mtree->root; struct archive_rb_node *n; int ret; @@ -1245,7 +1245,7 @@ write_mtree_entry_tree(struct archive_write *a) static int archive_write_mtree_finish_entry(struct archive_write *a) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; struct mtree_entry *me; if ((me = mtree->mtree_entry) == NULL) @@ -1261,7 +1261,7 @@ archive_write_mtree_finish_entry(struct archive_write *a) static int archive_write_mtree_close(struct archive_write *a) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; int ret; if (mtree->root != NULL) { @@ -1278,7 +1278,7 @@ archive_write_mtree_close(struct archive_write *a) static ssize_t archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; if (n > mtree->entry_bytes_remaining) n = (size_t)mtree->entry_bytes_remaining; @@ -1297,7 +1297,7 @@ archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) static int archive_write_mtree_free(struct archive_write *a) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; if (mtree == NULL) return (ARCHIVE_OK); @@ -1317,7 +1317,7 @@ static int archive_write_mtree_options(struct archive_write *a, const char *key, const char *value) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; int keybit = 0; switch (key[0]) { @@ -1429,7 +1429,7 @@ static int archive_write_set_format_mtree_default(struct archive *_a, const char *fn) { struct archive_write *a = (struct archive_write *)_a; - struct mtree_writer *mtree; + struct mtree *mtree; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, fn); @@ -1480,7 +1480,7 @@ archive_write_set_format_mtree_classic(struct archive *_a) "archive_write_set_format_mtree_classic"); if (r == ARCHIVE_OK) { struct archive_write *a = (struct archive_write *)_a; - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; /* Set to output a mtree archive in classic format. */ mtree->classic = 1; @@ -1492,7 +1492,7 @@ archive_write_set_format_mtree_classic(struct archive *_a) } static void -sum_init(struct mtree_writer *mtree) +sum_init(struct mtree *mtree) { mtree->compute_sum = 0; @@ -1553,7 +1553,7 @@ sum_init(struct mtree_writer *mtree) } static void -sum_update(struct mtree_writer *mtree, const void *buff, size_t n) +sum_update(struct mtree *mtree, const void *buff, size_t n) { if (mtree->compute_sum & F_CKSUM) { /* @@ -1611,7 +1611,7 @@ sum_update(struct mtree_writer *mtree, const void *buff, size_t n) } static void -sum_final(struct mtree_writer *mtree, struct reg_info *reg) +sum_final(struct mtree *mtree, struct reg_info *reg) { struct ae_digest digest; @@ -1992,7 +1992,7 @@ mtree_entry_create_virtual_dir(struct archive_write *a, const char *pathname, } static void -mtree_entry_register_add(struct mtree_writer *mtree, struct mtree_entry *file) +mtree_entry_register_add(struct mtree *mtree, struct mtree_entry *file) { file->next = NULL; *mtree->file_list.last = file; @@ -2000,14 +2000,14 @@ mtree_entry_register_add(struct mtree_writer *mtree, struct mtree_entry *file) } static void -mtree_entry_register_init(struct mtree_writer *mtree) +mtree_entry_register_init(struct mtree *mtree) { mtree->file_list.first = NULL; mtree->file_list.last = &(mtree->file_list.first); } static void -mtree_entry_register_free(struct mtree_writer *mtree) +mtree_entry_register_free(struct mtree *mtree) { struct mtree_entry *file, *file_next; @@ -2070,7 +2070,7 @@ get_path_component(char *name, size_t n, const char *fn) static int mtree_entry_tree_add(struct archive_write *a, struct mtree_entry **filep) { - struct mtree_writer *mtree = a->format_data; + struct mtree *mtree = a->format_data; #if defined(_WIN32) && !defined(__CYGWIN__) char name[_MAX_FNAME];/* Included null terminator size. */ #elif defined(NAME_MAX) && NAME_MAX >= 255 diff --git a/libarchive/archive_write_set_format_warc.c b/libarchive/archive_write_set_format_warc.c index 3c32b074a..27e4886e7 100644 --- a/libarchive/archive_write_set_format_warc.c +++ b/libarchive/archive_write_set_format_warc.c @@ -59,7 +59,7 @@ * Content-Length header. */ -struct warc_s { +struct warc { unsigned int omit_warcinfo:1; time_t now; @@ -127,7 +127,7 @@ int archive_write_set_format_warc(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; - struct warc_s *w; + struct warc *warc; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_set_format_warc"); @@ -135,20 +135,20 @@ archive_write_set_format_warc(struct archive *_a) /* If another format was already registered, unregister it. */ (void)__archive_write_unregister_format(a); - w = malloc(sizeof(*w)); - if (w == NULL) { + warc = malloc(sizeof(*warc)); + if (warc == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate warc data"); return (ARCHIVE_FATAL); } /* Emit a warcinfo record by default. */ - w->omit_warcinfo = 0U; + warc->omit_warcinfo = 0U; /* Use the current time for WARC-Date values. */ - w->now = time(NULL); + warc->now = time(NULL); /* Reset file type information. */ - w->typ = 0; + warc->typ = 0; - a->format_data = w; + a->format_data = warc; a->format_name = "WARC/1.0"; a->format_options = _warc_options; a->format_write_header = _warc_header; @@ -166,12 +166,12 @@ archive_write_set_format_warc(struct archive *_a) static int _warc_options(struct archive_write *a, const char *key, const char *val) { - struct warc_s *w = a->format_data; + struct warc *warc = a->format_data; if (strcmp(key, "omit-warcinfo") == 0) { if (val == NULL || strcmp(val, "true") == 0) { /* Option accepted. */ - w->omit_warcinfo = 1U; + warc->omit_warcinfo = 1U; return (ARCHIVE_OK); } } @@ -184,12 +184,12 @@ _warc_options(struct archive_write *a, const char *key, const char *val) static int _warc_header(struct archive_write *a, struct archive_entry *entry) { - struct warc_s *w = a->format_data; + struct warc *warc = a->format_data; struct archive_string hdr; #define MAX_HDR_SIZE 512 /* Emit the warcinfo record if needed. */ - if (!w->omit_warcinfo) { + if (!warc->omit_warcinfo) { ssize_t r; int rc; warc_essential_hdr_t wi = { @@ -201,8 +201,8 @@ _warc_header(struct archive_write *a, struct archive_entry *entry) /* Content type */"application/warc-fields", /* Content length */sizeof(warcinfo) - 1U, }; - wi.rtime = w->now; - wi.mtime = w->now; + wi.rtime = warc->now; + wi.mtime = warc->now; archive_string_init(&hdr); r = _popul_ehdr(&hdr, MAX_HDR_SIZE, wi); @@ -228,7 +228,7 @@ _warc_header(struct archive_write *a, struct archive_entry *entry) } /* Mark the file header as written. */ - w->omit_warcinfo = 1U; + warc->omit_warcinfo = 1U; archive_string_free(&hdr); } @@ -238,9 +238,9 @@ _warc_header(struct archive_write *a, struct archive_entry *entry) return (ARCHIVE_WARN); } - w->typ = archive_entry_filetype(entry); - w->entry_bytes_remaining = 0U; - if (w->typ == AE_IFREG) { + warc->typ = archive_entry_filetype(entry); + warc->entry_bytes_remaining = 0U; + if (warc->typ == AE_IFREG) { warc_essential_hdr_t rh = { WT_RSRC, /* URI */NULL, @@ -254,7 +254,7 @@ _warc_header(struct archive_write *a, struct archive_entry *entry) int rc; int64_t size; rh.tgturi = archive_entry_pathname(entry); - rh.rtime = w->now; + rh.rtime = warc->now; rh.mtime = archive_entry_mtime(entry); if (!archive_entry_size_is_set(entry)) { archive_set_error(&a->archive, -1, @@ -287,7 +287,7 @@ _warc_header(struct archive_write *a, struct archive_entry *entry) return (rc); } /* Save the remaining size for subsequent _data() calls. */ - w->entry_bytes_remaining = rh.cntlen; + warc->entry_bytes_remaining = rh.cntlen; archive_string_free(&hdr); return (ARCHIVE_OK); } @@ -300,14 +300,14 @@ _warc_header(struct archive_write *a, struct archive_entry *entry) static ssize_t _warc_data(struct archive_write *a, const void *buf, size_t len) { - struct warc_s *w = a->format_data; + struct warc *warc = a->format_data; - if (w->typ == AE_IFREG) { + if (warc->typ == AE_IFREG) { int rc; /* Never write more bytes than announced. */ - if ((uint64_t)len > w->entry_bytes_remaining) { - len = (size_t)w->entry_bytes_remaining; + if ((uint64_t)len > warc->entry_bytes_remaining) { + len = (size_t)warc->entry_bytes_remaining; } /* Write the entry data. */ @@ -315,7 +315,7 @@ _warc_data(struct archive_write *a, const void *buf, size_t len) if (rc != ARCHIVE_OK) { return rc; } - w->entry_bytes_remaining -= len; + warc->entry_bytes_remaining -= len; } return len; } @@ -324,12 +324,12 @@ static int _warc_finish_entry(struct archive_write *a) { static const char _eor[] = "\r\n\r\n"; - struct warc_s *w = a->format_data; + struct warc *warc = a->format_data; - if (w->typ == AE_IFREG) { + if (warc->typ == AE_IFREG) { int rc; - if (w->entry_bytes_remaining != 0U) { + if (warc->entry_bytes_remaining != 0U) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "WARC entry is shorter than Content-Length"); return (ARCHIVE_FATAL); @@ -341,7 +341,7 @@ _warc_finish_entry(struct archive_write *a) } } /* reset type info */ - w->typ = 0; + warc->typ = 0; return (ARCHIVE_OK); } @@ -355,9 +355,9 @@ _warc_close(struct archive_write *a) static int _warc_free(struct archive_write *a) { - struct warc_s *w = a->format_data; + struct warc *warc = a->format_data; - free(w); + free(warc); a->format_data = NULL; return (ARCHIVE_OK); }