blob: dd655f557c1c1a1515a2bcc8d8edb82792604dbb [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00002/*
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00003 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00004 */
5
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00006#include "libbb.h"
7#include "unarchive.h"
8
Rob Landleydfba7412006-03-06 20:47:33 +00009char get_header_tar_gz(archive_handle_t *archive_handle)
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000010{
Denis Vlasenko211f7f82007-09-05 11:48:32 +000011#if BB_MMU
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000012 unsigned char magic[2];
Denis Vlasenko211f7f82007-09-05 11:48:32 +000013#endif
Glenn L McGrathe3568832002-11-13 00:24:20 +000014
Denis Vlasenkoe1a0d482006-10-20 13:28:22 +000015 /* Can't lseek over pipes */
Denis Vlasenko13858992006-10-08 12:49:22 +000016 archive_handle->seek = seek_by_read;
Glenn L McGrath5699b852003-11-15 23:19:05 +000017
Denis Vlasenko211f7f82007-09-05 11:48:32 +000018 /* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
19 * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
20 * need the header. */
21#if BB_MMU
Rob Landley53437472006-07-16 08:14:35 +000022 xread(archive_handle->src_fd, &magic, 2);
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000023 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
Denis Vlasenko97a8dd32006-10-01 15:55:11 +000024 bb_error_msg_and_die("invalid gzip magic");
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000025 }
Denis Vlasenko211f7f82007-09-05 11:48:32 +000026#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000027
Denis Vlasenko211f7f82007-09-05 11:48:32 +000028 archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip", "gunzip", "-cf", "-", NULL);
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000029 archive_handle->offset = 0;
Denis Vlasenko476b0702007-09-09 14:11:11 +000030 while (get_header_tar(archive_handle) == EXIT_SUCCESS)
31 continue;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000032
Glenn L McGrath5699b852003-11-15 23:19:05 +000033 /* Can only do one file at a time */
Denis Vlasenko13858992006-10-08 12:49:22 +000034 return EXIT_FAILURE;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000035}