blob: d661df7ccdfadce004f291faacbb3b0a2bfe8a74 [file] [log] [blame]
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00001#include <stdlib.h>
2#include <unistd.h>
3#include "libbb.h"
4
5extern void check_header_gzip(int src_fd)
6{
7 union {
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +00008 unsigned char raw[8];
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00009 struct {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000010 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 McGrath2e41d0c2002-09-27 06:46:02 +000018 xread_all(src_fd, header.raw, 8);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000019
Glenn L McGrath9c60b292002-11-03 10:57:25 +000020 /* Check the compression method */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000021 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 McGrath9c60b292002-11-03 10:57:25 +000030 extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000031 while (extra_short > 0) {
Glenn L McGrath9c60b292002-11-03 10:57:25 +000032 /* Ignore extra field */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000033 xread_char(src_fd);
34 extra_short--;
35 }
36 }
37
Glenn L McGrath9c60b292002-11-03 10:57:25 +000038 /* Discard original name if any */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000039 if (header.formated.flags & 0x08) {
Glenn L McGrath9c60b292002-11-03 10:57:25 +000040 /* bit 3 set: original file name present */
41 while(xread_char(src_fd) != 0);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000042 }
43
Glenn L McGrath9c60b292002-11-03 10:57:25 +000044 /* Discard file comment if any */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000045 if (header.formated.flags & 0x10) {
Glenn L McGrath9c60b292002-11-03 10:57:25 +000046 /* bit 4 set: file comment present */
47 while(xread_char(src_fd) != 0);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000048 }
49
Glenn L McGrath9c60b292002-11-03 10:57:25 +000050 /* Read the header checksum */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000051 if (header.formated.flags & 0x02) {
Glenn L McGrath9c60b292002-11-03 10:57:25 +000052 xread_char(src_fd);
53 xread_char(src_fd);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000054 }
55
56 return;
57}