static int _archive_write_finish_entry(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; int ret = ARCHIVE_OK; archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, "archive_write_finish_entry"); if (a->archive.state & ARCHIVE_STATE_DATA) ret = (a->format_finish_entry)(a); a->archive.state = ARCHIVE_STATE_HEADER; return (ret); }
/* * Note that the compressor is responsible for blocking. */ static ssize_t _archive_write_data(struct archive *_a, const void *buff, size_t s) { struct archive_write *a = (struct archive_write *)_a; const size_t max_write = INT_MAX; archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_DATA, "archive_write_data"); /* In particular, this catches attempts to pass negative values. */ if (s > max_write) s = max_write; archive_clear_error(&a->archive); return ((a->format_write_data)(a, buff, s)); }
/* * Release memory and other resources. */ static int _archive_read_free(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; int i, n; int slots; int r = ARCHIVE_OK; if (_a == NULL) return (ARCHIVE_OK); archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_free"); if (a->archive.state != ARCHIVE_STATE_CLOSED && a->archive.state != ARCHIVE_STATE_FATAL) r = archive_read_close(&a->archive); /* Call cleanup functions registered by optional components. */ if (a->cleanup_archive_extract != NULL) r = (a->cleanup_archive_extract)(a); /* Cleanup format-specific data. */ slots = sizeof(a->formats) / sizeof(a->formats[0]); for (i = 0; i < slots; i++) { a->format = &(a->formats[i]); if (a->formats[i].cleanup) (a->formats[i].cleanup)(a); } /* Free the filters */ __archive_read_free_filters(a); /* Release the bidder objects. */ n = sizeof(a->bidders)/sizeof(a->bidders[0]); for (i = 0; i < n; i++) { if (a->bidders[i].free != NULL) { int r1 = (a->bidders[i].free)(&a->bidders[i]); if (r1 < r) r = r1; } } archive_string_free(&a->archive.error_string); if (a->entry) archive_entry_free(a->entry); a->archive.magic = 0; __archive_clean(&a->archive); free(a->client.dataset); free(a); return (r); }
int archive_write_set_format_ar_bsd(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; int r; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_set_format_ar_bsd"); r = archive_write_set_format_ar(a); if (r == ARCHIVE_OK) { a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; a->archive.archive_format_name = "ar (BSD)"; } return (r); }
/* * Write the appropriate header. */ static int _archive_write_header(struct archive *_a, struct archive_entry *entry) { struct archive_write *a = (struct archive_write *)_a; int ret, r2; archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_DATA | ARCHIVE_STATE_HEADER, "archive_write_header"); archive_clear_error(&a->archive); if (a->format_write_header == NULL) { archive_set_error(&(a->archive), -1, "Format must be set before you can write to an archive."); a->archive.state = ARCHIVE_STATE_FATAL; return (ARCHIVE_FATAL); } /* In particular, "retry" and "fatal" get returned immediately. */ ret = archive_write_finish_entry(&a->archive); if (ret == ARCHIVE_FATAL) { a->archive.state = ARCHIVE_STATE_FATAL; return (ARCHIVE_FATAL); } if (ret < ARCHIVE_OK && ret != ARCHIVE_WARN) return (ret); if (a->skip_file_set && archive_entry_dev_is_set(entry) && archive_entry_ino_is_set(entry) && archive_entry_dev(entry) == (dev_t)a->skip_file_dev && archive_entry_ino64(entry) == a->skip_file_ino) { archive_set_error(&a->archive, 0, "Can't add archive to itself"); return (ARCHIVE_FAILED); } /* Format and write header. */ r2 = ((a->format_write_header)(a, entry)); if (r2 == ARCHIVE_FATAL) { a->archive.state = ARCHIVE_STATE_FATAL; return (ARCHIVE_FATAL); } if (r2 < ret) ret = r2; a->archive.state = ARCHIVE_STATE_DATA; return (ret); }
int archive_write_set_format_zip(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; struct zip *zip; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_set_format_zip"); /* If another format was already registered, unregister it. */ if (a->format_free != NULL) (a->format_free)(a); zip = (struct zip *) calloc(1, sizeof(*zip)); if (zip == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate zip data"); return (ARCHIVE_FATAL); } /* "Unspecified" lets us choose the appropriate compression. */ zip->requested_compression = COMPRESSION_UNSPECIFIED; zip->crc32func = real_crc32; #ifdef HAVE_ZLIB_H zip->len_buf = 65536; zip->buf = malloc(zip->len_buf); if (zip->buf == NULL) { free(zip); archive_set_error(&a->archive, ENOMEM, "Can't allocate compression buffer"); return (ARCHIVE_FATAL); } #endif a->format_data = zip; a->format_name = "zip"; a->format_options = archive_write_zip_options; a->format_write_header = archive_write_zip_header; a->format_write_data = archive_write_zip_data; a->format_finish_entry = archive_write_zip_finish_entry; a->format_close = archive_write_zip_close; a->format_free = archive_write_zip_free; a->archive.archive_format = ARCHIVE_FORMAT_ZIP; a->archive.archive_format_name = "ZIP"; return (ARCHIVE_OK); }
int64_t archive_seek_data(struct archive *_a, int64_t offset, int whence) { struct archive_read *a = (struct archive_read *)_a; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, "archive_seek_data_block"); if (a->format->seek_data == NULL) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Internal error: " "No format_seek_data_block function registered"); return (ARCHIVE_FATAL); } return (a->format->seek_data)(a, offset, whence); }
int archive_write_add_filter_lzip(struct archive *_a) { struct archive_write_filter *f; int r; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_add_filter_lzip"); f = __archive_write_allocate_filter(_a); r = common_setup(f); if (r == ARCHIVE_OK) { f->code = ARCHIVE_FILTER_LZIP; f->name = "lzip"; } return (r); }
int archive_match_path_unmatched_inclusions_next_w(struct archive *_a, const wchar_t **_p) { struct archive_match *a; const void *v; int r; archive_check_magic(_a, ARCHIVE_MATCH_MAGIC, ARCHIVE_STATE_NEW, "archive_match_unmatched_inclusions_next_w"); a = (struct archive_match *)_a; r = match_list_unmatched_inclusions_next(a, &(a->inclusions), 0, &v); *_p = (const wchar_t *)v; return (r); }
/* * Read the next block of entry data from the archive. * This is a zero-copy interface; the client receives a pointer, * size, and file offset of the next available block of data. * * Returns ARCHIVE_OK if the operation is successful, ARCHIVE_EOF if * the end of entry is encountered. */ static int _archive_read_data_block(struct archive *_a, const void **buff, size_t *size, int64_t *offset) { struct archive_read *a = (struct archive_read *)_a; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, "archive_read_data_block"); if (a->format->read_data == NULL) { archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, "Internal error: " "No format_read_data_block function registered"); return (ARCHIVE_FATAL); } return (a->format->read_data)(a, buff, size, offset); }
int archive_read_support_filter_all(struct archive *a) { archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_filter_all"); /* Bzip falls back to "bunzip2" command-line */ archive_read_support_filter_bzip2(a); /* The decompress code doesn't use an outside library. */ archive_read_support_filter_compress(a); /* Gzip decompress falls back to "gzip -d" command-line. */ archive_read_support_filter_gzip(a); /* Lzip falls back to "unlzip" command-line program. */ archive_read_support_filter_lzip(a); /* The LZMA file format has a very weak signature, so it * may not be feasible to keep this here, but we'll try. * This will come back out if there are problems. */ /* Lzma falls back to "unlzma" command-line program. */ archive_read_support_filter_lzma(a); /* Xz falls back to "unxz" command-line program. */ archive_read_support_filter_xz(a); /* The decode code doesn't use an outside library. */ archive_read_support_filter_uu(a); /* The decode code doesn't use an outside library. */ archive_read_support_filter_rpm(a); /* The decode code always uses "lrzip -q -d" command-line. */ archive_read_support_filter_lrzip(a); /* Lzop decompress falls back to "lzop -d" command-line. */ archive_read_support_filter_lzop(a); /* The decode code always uses "grzip -d" command-line. */ archive_read_support_filter_grzip(a); /* Lz4 falls back to "lz4 -d" command-line program. */ archive_read_support_filter_lz4(a); /* Zstd falls back to "zstd -d" command-line program. */ archive_read_support_filter_zstd(a); /* Note: We always return ARCHIVE_OK here, even if some of the * above return ARCHIVE_WARN. The intent here is to enable * "as much as possible." Clients who need specific * compression should enable those individually so they can * verify the level of support. */ /* Clear any warning messages set by the above functions. */ archive_clear_error(a); return (ARCHIVE_OK); }
/* * Used internally by read format handlers to register their bid and * initialization functions. */ int __archive_read_register_format(struct archive_read *a, void *format_data, const char *name, int (*bid)(struct archive_read *, int), int (*options)(struct archive_read *, const char *, const char *), int (*read_header)(struct archive_read *, struct archive_entry *), int (*read_data)(struct archive_read *, const void **, size_t *, int64_t *), int (*read_data_skip)(struct archive_read *), int64_t (*seek_data)(struct archive_read *, int64_t, int), int (*cleanup)(struct archive_read *), int (*format_capabilities)(struct archive_read *), int (*has_encrypted_entries)(struct archive_read *)) { int i, number_slots; archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "__archive_read_register_format"); number_slots = sizeof(a->formats) / sizeof(a->formats[0]); for (i = 0; i < number_slots; i++) { if (a->formats[i].bid == bid) return (ARCHIVE_WARN); /* We've already installed */ if (a->formats[i].bid == NULL) { a->formats[i].bid = bid; a->formats[i].options = options; a->formats[i].read_header = read_header; a->formats[i].read_data = read_data; a->formats[i].read_data_skip = read_data_skip; a->formats[i].seek_data = seek_data; a->formats[i].cleanup = cleanup; a->formats[i].data = format_data; a->formats[i].name = name; a->formats[i].format_capabilties = format_capabilities; a->formats[i].has_encrypted_entries = has_encrypted_entries; return (ARCHIVE_OK); } } archive_set_error(&a->archive, ENOMEM, "Not enough slots for format registration"); return (ARCHIVE_FATAL); }
int archive_match_include_pattern_w(struct archive *_a, const wchar_t *pattern) { struct archive_match *a; int r; archive_check_magic(_a, ARCHIVE_MATCH_MAGIC, ARCHIVE_STATE_NEW, "archive_match_include_pattern_w"); a = (struct archive_match *)_a; if (pattern == NULL || *pattern == L'\0') { archive_set_error(&(a->archive), EINVAL, "pattern is empty"); return (ARCHIVE_FAILED); } if ((r = add_pattern_wcs(a, &(a->inclusions), pattern)) != ARCHIVE_OK) return (r); return (ARCHIVE_OK); }
int archive_read_support_format_by_code(struct archive *a, int format_code) { archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_format_by_code"); switch (format_code & ARCHIVE_FORMAT_BASE_MASK) { case ARCHIVE_FORMAT_7ZIP: return archive_read_support_format_7zip(a); break; case ARCHIVE_FORMAT_AR: return archive_read_support_format_ar(a); break; case ARCHIVE_FORMAT_CAB: return archive_read_support_format_cab(a); break; case ARCHIVE_FORMAT_CPIO: return archive_read_support_format_cpio(a); break; case ARCHIVE_FORMAT_ISO9660: return archive_read_support_format_iso9660(a); break; case ARCHIVE_FORMAT_LHA: return archive_read_support_format_lha(a); break; case ARCHIVE_FORMAT_MTREE: return archive_read_support_format_mtree(a); break; case ARCHIVE_FORMAT_RAR: return archive_read_support_format_rar(a); break; case ARCHIVE_FORMAT_TAR: return archive_read_support_format_tar(a); break; case ARCHIVE_FORMAT_XAR: return archive_read_support_format_xar(a); break; case ARCHIVE_FORMAT_ZIP: return archive_read_support_format_zip(a); break; } return (ARCHIVE_FATAL); }
int archive_read_support_filter_compress(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; struct archive_read_filter_bidder *bidder; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_filter_compress"); if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) return (ARCHIVE_FATAL); bidder->data = NULL; bidder->bid = compress_bidder_bid; bidder->init = compress_bidder_init; bidder->options = NULL; bidder->free = compress_bidder_free; return (ARCHIVE_OK); }
/* * Add a filter to this write handle that passes all data through an * external program. */ int archive_write_add_filter_program(struct archive *_a, const char *cmd) { struct archive_write_filter *f = __archive_write_allocate_filter(_a); struct private_data *data; static const char *prefix = "Program: "; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_add_filter_program"); f->data = calloc(1, sizeof(*data)); if (f->data == NULL) goto memerr; data = (struct private_data *)f->data; data->cmd = strdup(cmd); if (data->cmd == NULL) goto memerr; data->pdata = __archive_write_program_allocate(); if (data->pdata == NULL) goto memerr; /* Make up a description string. */ if (archive_string_ensure(&data->description, strlen(prefix) + strlen(cmd) + 1) == NULL) goto memerr; archive_strcpy(&data->description, prefix); archive_strcat(&data->description, cmd); f->name = data->description.s; f->code = ARCHIVE_FILTER_PROGRAM; f->open = archive_compressor_program_open; f->write = archive_compressor_program_write; f->close = archive_compressor_program_close; f->free = archive_compressor_program_free; return (ARCHIVE_OK); memerr: archive_compressor_program_free(f); archive_set_error(_a, ENOMEM, "Can't allocate memory for filter program"); return (ARCHIVE_FATAL); }
int archive_read_support_filter_uu(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; struct archive_read_filter_bidder *bidder; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_filter_uu"); if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) return (ARCHIVE_FATAL); bidder->data = NULL; bidder->name = "uu"; bidder->bid = uudecode_bidder_bid; bidder->init = uudecode_bidder_init; bidder->options = NULL; bidder->free = NULL; return (ARCHIVE_OK); }
/* * Free an ARCHIVE_MATCH object. */ int archive_match_free(struct archive *_a) { struct archive_match *a; if (_a == NULL) return (ARCHIVE_OK); archive_check_magic(_a, ARCHIVE_MATCH_MAGIC, ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_match_free"); a = (struct archive_match *)_a; match_list_free(&(a->inclusions)); match_list_free(&(a->exclusions)); entry_list_free(&(a->exclusion_entry_list)); free(a->inclusion_uids.ids); free(a->inclusion_gids.ids); match_list_free(&(a->inclusion_unames)); match_list_free(&(a->inclusion_gnames)); free(a); return (ARCHIVE_OK); }
int archive_match_exclude_entry(struct archive *_a, int flag, struct archive_entry *entry) { struct archive_match *a; int r; archive_check_magic(_a, ARCHIVE_MATCH_MAGIC, ARCHIVE_STATE_NEW, "archive_match_time_include_entry"); a = (struct archive_match *)_a; if (entry == NULL) { archive_set_error(&(a->archive), EINVAL, "entry is NULL"); return (ARCHIVE_FAILED); } r = validate_time_flag(_a, flag, "archive_match_exclude_entry"); if (r != ARCHIVE_OK) return (r); return (add_entry(a, flag, entry)); }
int _archive_set_option(struct archive *a, const char *m, const char *o, const char *v, int magic, const char *fn, option_handler use_option) { const char *mp, *op, *vp; archive_check_magic(a, magic, ARCHIVE_STATE_NEW, fn); mp = m != NULL && m[0] == '\0' ? NULL : m; op = o != NULL && o[0] == '\0' ? NULL : o; vp = v != NULL && v[0] == '\0' ? NULL : v; if (op == NULL && vp == NULL) return (ARCHIVE_OK); if (op == NULL) return (ARCHIVE_FAILED); return use_option(a, mp, op, vp); }
/* * Set output format to ISO 28500 (aka WARC) format. */ int archive_write_set_format_warc(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; struct warc_s *w; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_set_format_warc"); /* If another format was already registered, unregister it. */ if (a->format_free != NULL) { (a->format_free)(a); } w = malloc(sizeof(*w)); if (w == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate warc data"); return (ARCHIVE_FATAL); } /* by default we're emitting a file wide header */ w->omit_warcinfo = 0U; /* obtain current time for date fields */ w->now = time(NULL); /* reset file type info */ w->typ = 0; /* also initialise our rng */ w->rng = (unsigned int)w->now; a->format_data = w; a->format_name = "WARC/1.0"; a->format_options = _warc_options; a->format_write_header = _warc_header; a->format_write_data = _warc_data; a->format_close = _warc_close; a->format_free = _warc_free; a->format_finish_entry = _warc_finish_entry; a->archive.archive_format = ARCHIVE_FORMAT_WARC; a->archive.archive_format_name = "WARC/1.0"; return (ARCHIVE_OK); }
int archive_write_zip_set_compression_store(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; struct zip *zip = a->format_data; int ret = ARCHIVE_FAILED; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW | ARCHIVE_STATE_HEADER, "archive_write_zip_set_compression_deflate"); if (a->archive.archive_format != ARCHIVE_FORMAT_ZIP) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Can only use archive_write_zip_set_compression_store" " with zip format"); ret = ARCHIVE_FATAL; } else { zip->compression = COMPRESSION_STORE; ret = ARCHIVE_OK; } return (ret); }
/* * Test function for owner(uid, gid, uname, gname). * * Returns 1 if archive entry is excluded. * Returns 0 if archive entry is not excluded. * Returns <0 if something error happened. */ int archive_match_owner_excluded(struct archive *_a, struct archive_entry *entry) { struct archive_match *a; archive_check_magic(_a, ARCHIVE_MATCH_MAGIC, ARCHIVE_STATE_NEW, "archive_match_id_excluded_ae"); a = (struct archive_match *)_a; if (entry == NULL) { archive_set_error(&(a->archive), EINVAL, "entry is NULL"); return (ARCHIVE_FAILED); } /* If we don't have inclusion id set at all, the entry is always * not excluded. */ if ((a->setflag & ID_IS_SET) == 0) return (0); return (owner_excluded(a, entry)); }
int archive_read_support_format_empty(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; int r; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_format_empty"); r = __archive_read_register_format(a, NULL, NULL, archive_read_format_empty_bid, NULL, archive_read_format_empty_read_header, archive_read_format_empty_read_data, NULL, NULL); return (r); }
/* * Set output format to 'v7tar' format. */ int archive_write_set_format_v7tar(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; struct v7tar *v7tar; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_set_format_v7tar"); /* If someone else was already registered, unregister them. */ if (a->format_free != NULL) (a->format_free)(a); /* Basic internal sanity test. */ if (sizeof(template_header) != 512) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %zu should be 512", sizeof(template_header)); return (ARCHIVE_FATAL); } v7tar = (struct v7tar *)malloc(sizeof(*v7tar)); if (v7tar == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate v7tar data"); return (ARCHIVE_FATAL); } memset(v7tar, 0, sizeof(*v7tar)); a->format_data = v7tar; a->format_name = "tar (non-POSIX)"; a->format_options = archive_write_v7tar_options; a->format_write_header = archive_write_v7tar_header; a->format_write_data = archive_write_v7tar_data; a->format_close = archive_write_v7tar_close; a->format_free = archive_write_v7tar_free; a->format_finish_entry = archive_write_v7tar_finish_entry; a->archive.archive_format = ARCHIVE_FORMAT_TAR; a->archive.archive_format_name = "tar (non-POSIX)"; return (ARCHIVE_OK); }
/* * Add a bzip2 compression filter to this write handle. */ int archive_write_add_filter_bzip2(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; struct archive_write_filter *f = __archive_write_allocate_filter(_a); struct private_data *data; archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_add_filter_bzip2"); data = calloc(1, sizeof(*data)); if (data == NULL) { archive_set_error(&a->archive, ENOMEM, "Out of memory"); return (ARCHIVE_FATAL); } data->compression_level = 9; /* default */ f->data = data; f->options = &archive_compressor_bzip2_options; f->close = &archive_compressor_bzip2_close; f->free = &archive_compressor_bzip2_free; f->open = &archive_compressor_bzip2_open; f->code = ARCHIVE_FILTER_BZIP2; f->name = "bzip2"; #if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) return (ARCHIVE_OK); #else data->pdata = __archive_write_program_allocate("bzip2"); if (data->pdata == NULL) { free(data); archive_set_error(&a->archive, ENOMEM, "Out of memory"); return (ARCHIVE_FATAL); } data->compression_level = 0; archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Using external bzip2 program"); return (ARCHIVE_WARN); #endif }
/* * Close the file and all I/O. */ static int _archive_read_close(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; int r = ARCHIVE_OK, r1 = ARCHIVE_OK; archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_close"); if (a->archive.state == ARCHIVE_STATE_CLOSED) return (ARCHIVE_OK); archive_clear_error(&a->archive); a->archive.state = ARCHIVE_STATE_CLOSED; /* TODO: Clean up the formatters. */ /* Release the filter objects. */ r1 = close_filters(a); if (r1 < r) r = r1; return (r); }
int archive_read_add_passphrase(struct archive *_a, const char *passphrase) { struct archive_read *a = (struct archive_read *)_a; struct archive_read_passphrase *p; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_add_passphrase"); if (passphrase == NULL || passphrase[0] == '\0') { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Empty passphrase is unacceptable"); return (ARCHIVE_FAILED); } p = new_read_passphrase(a, passphrase); if (p == NULL) return (ARCHIVE_FATAL); add_passphrase_to_tail(a, p); return (ARCHIVE_OK); }
int archive_read_support_format_ar(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; struct ar *ar; int r; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_format_ar"); ar = (struct ar *)malloc(sizeof(*ar)); if (ar == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data"); return (ARCHIVE_FATAL); } memset(ar, 0, sizeof(*ar)); ar->strtab = NULL; r = __archive_read_register_format(a, ar, "ar", archive_read_format_ar_bid, NULL, archive_read_format_ar_read_header, archive_read_format_ar_read_data, archive_read_format_ar_skip, NULL, archive_read_format_ar_cleanup, NULL, NULL); if (r != ARCHIVE_OK) { free(ar); return (r); } return (ARCHIVE_OK); }
int archive_read_support_filter_lrzip(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; struct archive_read_filter_bidder *reader; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_filter_lrzip"); if (__archive_read_get_bidder(a, &reader) != ARCHIVE_OK) return (ARCHIVE_FATAL); reader->data = NULL; reader->name = "lrzip"; reader->bid = lrzip_bidder_bid; reader->init = lrzip_bidder_init; reader->options = NULL; reader->free = lrzip_reader_free; /* This filter always uses an external program. */ archive_set_error(_a, ARCHIVE_ERRNO_MISC, "Using external lrzip program for lrzip decompression"); return (ARCHIVE_WARN); }