"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 2 | /* |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 6 | #include "libbb.h" |
| 7 | #include "unarchive.h" |
| 8 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 9 | char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle) |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 10 | { |
Denis Vlasenko | 211f7f8 | 2007-09-05 11:48:32 +0000 | [diff] [blame] | 11 | #if BB_MMU |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 12 | unsigned char magic[2]; |
Denis Vlasenko | 211f7f8 | 2007-09-05 11:48:32 +0000 | [diff] [blame] | 13 | #endif |
Glenn L McGrath | e356883 | 2002-11-13 00:24:20 +0000 | [diff] [blame] | 14 | |
Denis Vlasenko | e1a0d48 | 2006-10-20 13:28:22 +0000 | [diff] [blame] | 15 | /* Can't lseek over pipes */ |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 16 | archive_handle->seek = seek_by_read; |
Glenn L McGrath | 5699b85 | 2003-11-15 23:19:05 +0000 | [diff] [blame] | 17 | |
Denis Vlasenko | 211f7f8 | 2007-09-05 11:48:32 +0000 | [diff] [blame] | 18 | /* 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 Landley | 5343747 | 2006-07-16 08:14:35 +0000 | [diff] [blame] | 22 | xread(archive_handle->src_fd, &magic, 2); |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 23 | /* Can skip this check, but error message will be less clear */ |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 24 | if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 25 | bb_error_msg_and_die("invalid gzip magic"); |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 26 | } |
Denis Vlasenko | 211f7f8 | 2007-09-05 11:48:32 +0000 | [diff] [blame] | 27 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 28 | |
Denis Vlasenko | b605272 | 2008-07-10 17:43:01 +0000 | [diff] [blame] | 29 | open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip"); |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 30 | archive_handle->offset = 0; |
Denis Vlasenko | 476b070 | 2007-09-09 14:11:11 +0000 | [diff] [blame] | 31 | while (get_header_tar(archive_handle) == EXIT_SUCCESS) |
| 32 | continue; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 33 | |
Glenn L McGrath | 5699b85 | 2003-11-15 23:19:05 +0000 | [diff] [blame] | 34 | /* Can only do one file at a time */ |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 35 | return EXIT_FAILURE; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 36 | } |