blob: e88b720a8ec8e3f3bd15283b3413080350565235 [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
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +00009char FAST_FUNC 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);
Denis Vlasenko0381d422008-07-10 23:06:00 +000023 /* Can skip this check, but error message will be less clear */
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000024 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
Denis Vlasenko97a8dd32006-10-01 15:55:11 +000025 bb_error_msg_and_die("invalid gzip magic");
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000026 }
Denis Vlasenko211f7f82007-09-05 11:48:32 +000027#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000028
Denis Vlasenkob6052722008-07-10 17:43:01 +000029 open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000030 archive_handle->offset = 0;
Denis Vlasenko476b0702007-09-09 14:11:11 +000031 while (get_header_tar(archive_handle) == EXIT_SUCCESS)
32 continue;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000033
Glenn L McGrath5699b852003-11-15 23:19:05 +000034 /* Can only do one file at a time */
Denis Vlasenko13858992006-10-08 12:49:22 +000035 return EXIT_FAILURE;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000036}