Rev | Line | |
---|
[1765] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
[821] | 6 | #include "libbb.h"
|
---|
[1765] | 7 | #include "unarchive.h" /* for external decl of check_header_gzip_or_die */
|
---|
[821] | 8 |
|
---|
[1765] | 9 | void check_header_gzip_or_die(int src_fd)
|
---|
[821] | 10 | {
|
---|
| 11 | union {
|
---|
| 12 | unsigned char raw[8];
|
---|
| 13 | struct {
|
---|
| 14 | unsigned char method;
|
---|
| 15 | unsigned char flags;
|
---|
| 16 | unsigned int mtime;
|
---|
| 17 | unsigned char xtra_flags;
|
---|
| 18 | unsigned char os_flags;
|
---|
[1765] | 19 | } formatted;
|
---|
[821] | 20 | } header;
|
---|
| 21 |
|
---|
[1765] | 22 | xread(src_fd, header.raw, 8);
|
---|
[821] | 23 |
|
---|
| 24 | /* Check the compression method */
|
---|
[1765] | 25 | if (header.formatted.method != 8) {
|
---|
| 26 | bb_error_msg_and_die("unknown compression method %d",
|
---|
| 27 | header.formatted.method);
|
---|
[821] | 28 | }
|
---|
| 29 |
|
---|
[1765] | 30 | if (header.formatted.flags & 0x04) {
|
---|
[821] | 31 | /* bit 2 set: extra field present */
|
---|
[1765] | 32 | unsigned extra_short;
|
---|
[821] | 33 |
|
---|
[1765] | 34 | extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
|
---|
[821] | 35 | while (extra_short > 0) {
|
---|
| 36 | /* Ignore extra field */
|
---|
[1765] | 37 | xread_char(src_fd);
|
---|
[821] | 38 | extra_short--;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | /* Discard original name if any */
|
---|
[1765] | 43 | if (header.formatted.flags & 0x08) {
|
---|
[821] | 44 | /* bit 3 set: original file name present */
|
---|
[1765] | 45 | while (xread_char(src_fd) != 0);
|
---|
[821] | 46 | }
|
---|
| 47 |
|
---|
| 48 | /* Discard file comment if any */
|
---|
[1765] | 49 | if (header.formatted.flags & 0x10) {
|
---|
[821] | 50 | /* bit 4 set: file comment present */
|
---|
[1765] | 51 | while (xread_char(src_fd) != 0);
|
---|
[821] | 52 | }
|
---|
| 53 |
|
---|
| 54 | /* Read the header checksum */
|
---|
[1765] | 55 | if (header.formatted.flags & 0x02) {
|
---|
| 56 | xread_char(src_fd);
|
---|
| 57 | xread_char(src_fd);
|
---|
[821] | 58 | }
|
---|
| 59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.