blob: 1f07e4e6488aaa3defe3d0f54de8496884263816 [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 <stdlib.h>
Glenn L McGratha0d395e2002-11-19 08:22:03 +00007
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00008#include "libbb.h"
9#include "unarchive.h"
10
Rob Landleydfba7412006-03-06 20:47:33 +000011char get_header_tar_gz(archive_handle_t *archive_handle)
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000012{
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000013 unsigned char magic[2];
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
Rob Landley53437472006-07-16 08:14:35 +000018 xread(archive_handle->src_fd, &magic, 2);
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000019 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
Denis Vlasenko97a8dd32006-10-01 15:55:11 +000020 bb_error_msg_and_die("invalid gzip magic");
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000021 }
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000022
Denis Vlasenkoab9eef22007-03-07 22:02:23 +000023 check_header_gzip_or_die(archive_handle->src_fd);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000024
Glenn L McGrath5699b852003-11-15 23:19:05 +000025 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000026 archive_handle->offset = 0;
Denis Vlasenko13858992006-10-08 12:49:22 +000027 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000028
Glenn L McGrath5699b852003-11-15 23:19:05 +000029 /* Can only do one file at a time */
Denis Vlasenko13858992006-10-08 12:49:22 +000030 return EXIT_FAILURE;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000031}