blob: 889fed0d9aa9eaa434653adb794a0cf29ad78d64 [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/*
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00004 */
5
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00006#include "libbb.h"
Denys Vlasenko833d4e72010-11-03 02:38:31 +01007#include "archive.h"
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00008
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
Denys Vlasenkoaef441c2011-02-06 20:01:11 +010012 uint16_t magic;
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 */
Denys Vlasenkoaef441c2011-02-06 20:01:11 +010024 if (magic != GZIP_MAGIC) {
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}