blob: 69126e0ba2bf81772dd877cb7509aaf024852550 [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{
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000011 unsigned char magic[2];
Glenn L McGrathe3568832002-11-13 00:24:20 +000012
Denis Vlasenkoe1a0d482006-10-20 13:28:22 +000013 /* Can't lseek over pipes */
Denis Vlasenko13858992006-10-08 12:49:22 +000014 archive_handle->seek = seek_by_read;
Glenn L McGrath5699b852003-11-15 23:19:05 +000015
Rob Landley53437472006-07-16 08:14:35 +000016 xread(archive_handle->src_fd, &magic, 2);
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000017 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
Denis Vlasenko97a8dd32006-10-01 15:55:11 +000018 bb_error_msg_and_die("invalid gzip magic");
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000019 }
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000020
Denis Vlasenkoab9eef22007-03-07 22:02:23 +000021 check_header_gzip_or_die(archive_handle->src_fd);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000022
Glenn L McGrath5699b852003-11-15 23:19:05 +000023 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000024 archive_handle->offset = 0;
Denis Vlasenko13858992006-10-08 12:49:22 +000025 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000026
Glenn L McGrath5699b852003-11-15 23:19:05 +000027 /* Can only do one file at a time */
Denis Vlasenko13858992006-10-08 12:49:22 +000028 return EXIT_FAILURE;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000029}