*
*/
-/* For reference to format see http://www.pkware.com/support/appnote.html */
+/* For reference see
+ * http://www.pkware.com/products/enterprise/white_papers/appnote.txt
+ * http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip
+ */
/* TODO Endian issues, exclude, should we accept input from stdin ? */
break;
#endif
default:
- show_usage();
+ bb_show_usage();
}
}
if (argc == optind) {
- show_usage();
+ bb_show_usage();
}
printf("Archive: %s\n", argv[optind]);
}
if (*argv[optind] == '-') {
- archive_handle->src_fd = fileno(stdin);
- } else {
- archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
- }
+ archive_handle->src_fd = STDIN_FILENO;
+ archive_handle->seek = seek_by_char;
+ } else {
+ archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
+ }
if ((base_dir) && (chdir(base_dir))) {
- perror_msg_and_die("Couldnt chdir");
- }
+ bb_perror_msg_and_die("Couldnt chdir");
+ }
while (optind < argc) {
archive_handle->filter = filter_accept_list;
- archive_handle->accept = add_to_list(archive_handle->accept, argv[optind]);
+ archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
optind++;
}
int dst_fd;
/* TODO Endian issues */
- xread_all(archive_handle->src_fd, &magic, 4);
+ archive_xread_all(archive_handle, &magic, 4);
archive_handle->offset += 4;
if (magic == ZIP_CDS_MAGIC) {
break;
}
else if (magic != ZIP_FILEHEADER_MAGIC) {
- error_msg_and_die("Invlaide zip magic");
+ bb_error_msg_and_die("Invlaide zip magic");
}
/* Read the file header */
- xread_all(archive_handle->src_fd, zip_header.raw, 26);
+ archive_xread_all(archive_handle, zip_header.raw, 26);
archive_handle->offset += 26;
archive_handle->file_header->mode = S_IFREG | 0777;
if (zip_header.formated.method != 8) {
- error_msg_and_die("Unsupported compression method %d\n", zip_header.formated.method);
+ bb_error_msg_and_die("Unsupported compression method %d\n", zip_header.formated.method);
}
/* Read filename */
archive_handle->file_header->name = xmalloc(zip_header.formated.filename_len + 1);
- xread_all(archive_handle->src_fd, archive_handle->file_header->name, zip_header.formated.filename_len);
+ archive_xread_all(archive_handle, archive_handle->file_header->name, zip_header.formated.filename_len);
archive_handle->offset += zip_header.formated.filename_len;
archive_handle->file_header->name[zip_header.formated.filename_len] = '\0';
if (archive_handle->action_data) {
archive_handle->action_data(archive_handle);
} else {
- dst_fd = xopen(archive_handle->file_header->name, O_WRONLY | O_CREAT);
- inflate(archive_handle->src_fd, dst_fd);
+ dst_fd = bb_xopen(archive_handle->file_header->name, O_WRONLY | O_CREAT);
+ inflate_init(zip_header.formated.cmpsize);
+ inflate_unzip(archive_handle->src_fd, dst_fd);
close(dst_fd);
chmod(archive_handle->file_header->name, archive_handle->file_header->mode);
/* Validate decompression - crc */
if (zip_header.formated.crc32 != (gunzip_crc ^ 0xffffffffL)) {
- error_msg("Invalid compressed data--crc error");
+ bb_error_msg("Invalid compressed data--crc error");
}
/* Validate decompression - size */
if (gunzip_bytes_out != zip_header.formated.ucmpsize) {
- error_msg("Invalid compressed data--length error");
+ bb_error_msg("Invalid compressed data--length error");
}
}
/* Data descriptor section */
if (zip_header.formated.flags & 4) {
/* skip over duplicate crc, compressed size and uncompressed size */
- unsigned short i;
- for (i = 0; i != 12; i++) {
- xread_char(archive_handle->src_fd);
- }
+ unsigned char data_description[12];
+ archive_xread_all(archive_handle, data_description, 12);
archive_handle->offset += 12;
}
}