Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <unistd.h> |
| 3 | #include "libbb.h" |
| 4 | |
| 5 | extern void check_header_gzip(int src_fd) |
| 6 | { |
| 7 | union { |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 8 | unsigned char raw[8]; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 9 | struct { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 10 | unsigned char method; |
| 11 | unsigned char flags; |
| 12 | unsigned int mtime; |
| 13 | unsigned char xtra_flags; |
| 14 | unsigned char os_flags; |
| 15 | } formated; |
| 16 | } header; |
| 17 | |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 18 | xread_all(src_fd, header.raw, 8); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 19 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 20 | /* Check the compression method */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 21 | if (header.formated.method != 8) { |
| 22 | error_msg_and_die("Unknown compression method %d", |
| 23 | header.formated.method); |
| 24 | } |
| 25 | |
| 26 | if (header.formated.flags & 0x04) { |
| 27 | /* bit 2 set: extra field present */ |
| 28 | unsigned char extra_short; |
| 29 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 30 | extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 31 | while (extra_short > 0) { |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 32 | /* Ignore extra field */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 33 | xread_char(src_fd); |
| 34 | extra_short--; |
| 35 | } |
| 36 | } |
| 37 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 38 | /* Discard original name if any */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 39 | if (header.formated.flags & 0x08) { |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 40 | /* bit 3 set: original file name present */ |
| 41 | while(xread_char(src_fd) != 0); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 44 | /* Discard file comment if any */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 45 | if (header.formated.flags & 0x10) { |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 46 | /* bit 4 set: file comment present */ |
| 47 | while(xread_char(src_fd) != 0); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 50 | /* Read the header checksum */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 51 | if (header.formated.flags & 0x02) { |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 52 | xread_char(src_fd); |
| 53 | xread_char(src_fd); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | return; |
| 57 | } |