| 1 |
/* gzip.h -- common declarations for all gzip modules |
| 2 |
|
| 3 |
Copyright (C) 1997, 1998, 1999, 2001, 2006, 2007 Free Software |
| 4 |
Foundation, Inc. |
| 5 |
Copyright (C) 1992-1993 Jean-loup Gailly. |
| 6 |
Copyright (C) 2008 Josh Triplett |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 2, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program; if not, write to the Free Software Foundation, |
| 20 |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
| 21 |
|
| 22 |
#define BITS 16 |
| 23 |
|
| 24 |
#ifndef __attribute__ |
| 25 |
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ |
| 26 |
# define __attribute__(x) |
| 27 |
# endif |
| 28 |
#endif |
| 29 |
|
| 30 |
#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) |
| 31 |
|
| 32 |
/* I don't like nested includes, but the following headers are used |
| 33 |
* too often |
| 34 |
*/ |
| 35 |
#include <stdio.h> |
| 36 |
#include <sys/types.h> /* for off_t */ |
| 37 |
#include <time.h> |
| 38 |
#include <string.h> |
| 39 |
#define memzero(s, n) memset ((s), 0, (n)) |
| 40 |
|
| 41 |
typedef unsigned char uch; |
| 42 |
typedef unsigned short ush; |
| 43 |
typedef unsigned long ulg; |
| 44 |
|
| 45 |
/* Return codes from gzip */ |
| 46 |
#define OK 0 |
| 47 |
#define ERROR 1 |
| 48 |
|
| 49 |
/* Compression methods */ |
| 50 |
#define DEFLATED 8 |
| 51 |
|
| 52 |
#define INBUFSIZ 0x8000 /* input buffer size */ |
| 53 |
#define OUTBUFSIZ 16384 /* output buffer size */ |
| 54 |
#define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */ |
| 55 |
|
| 56 |
extern uch outbuf[]; /* output buffer */ |
| 57 |
|
| 58 |
extern unsigned outcnt; /* bytes in output buffer */ |
| 59 |
|
| 60 |
#define NO_FILE (-1) /* in memory compression */ |
| 61 |
|
| 62 |
|
| 63 |
#define GZIP_MAGIC "\037\213" /* Magic header for gzip files, 1F 8B */ |
| 64 |
#define OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */ |
| 65 |
#define PKZIP_MAGIC "\120\113\003\004" /* Magic header for pkzip files */ |
| 66 |
|
| 67 |
/* gzip flag byte */ |
| 68 |
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ |
| 69 |
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ |
| 70 |
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ |
| 71 |
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ |
| 72 |
#define COMMENT 0x10 /* bit 4 set: file comment present */ |
| 73 |
#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ |
| 74 |
#define RESERVED 0xC0 /* bit 6,7: reserved */ |
| 75 |
|
| 76 |
/* internal file attribute */ |
| 77 |
#define UNKNOWN 0xffff |
| 78 |
#define BINARY 0 |
| 79 |
#define ASCII 1 |
| 80 |
|
| 81 |
#define WSIZE 0x8000 /* window size--must be a power of two, and */ |
| 82 |
/* at least 32K for zip's deflate method */ |
| 83 |
|
| 84 |
#define MIN_MATCH 3 |
| 85 |
#define MAX_MATCH 258 |
| 86 |
/* The minimum and maximum match lengths */ |
| 87 |
|
| 88 |
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) |
| 89 |
/* Minimum amount of lookahead, except at the end of the input file. |
| 90 |
* See deflate.c for comments about the MIN_MATCH+1. |
| 91 |
*/ |
| 92 |
|
| 93 |
#define MAX_DIST (WSIZE-MIN_LOOKAHEAD) |
| 94 |
/* In order to simplify the code, particularly on 16 bit machines, match |
| 95 |
* distances are limited to MAX_DIST instead of WSIZE. |
| 96 |
*/ |
| 97 |
|
| 98 |
/* put_byte is used for the compressed output. */ |
| 99 |
#define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\ |
| 100 |
flush_outbuf();} |
| 101 |
|
| 102 |
/* Output a 16 bit value, lsb first */ |
| 103 |
#define put_short(w) \ |
| 104 |
{ if (outcnt < OUTBUFSIZ-2) { \ |
| 105 |
outbuf[outcnt++] = (uch) ((w) & 0xff); \ |
| 106 |
outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \ |
| 107 |
} else { \ |
| 108 |
put_byte((uch)((w) & 0xff)); \ |
| 109 |
put_byte((uch)((ush)(w) >> 8)); \ |
| 110 |
} \ |
| 111 |
} |
| 112 |
|
| 113 |
/* Output a 32 bit value to the bit stream, lsb first */ |
| 114 |
#define put_long(n) { \ |
| 115 |
put_short((n) & 0xffff); \ |
| 116 |
put_short(((ulg)(n)) >> 16); \ |
| 117 |
} |
| 118 |
|
| 119 |
/* Diagnostic functions */ |
| 120 |
#define Assert(cond,msg) |
| 121 |
#define Trace(x) |
| 122 |
#define Tracev(x) |
| 123 |
#define Tracevv(x) |
| 124 |
#define Tracec(c,x) |
| 125 |
#define Tracecv(c,x) |
| 126 |
|
| 127 |
/* in zip.c: */ |
| 128 |
extern int file_read(char *buf, unsigned size); |
| 129 |
|
| 130 |
/* in deflate.c */ |
| 131 |
void lm_init(int pack_level, ush *flags); |
| 132 |
void gnu_deflate(int pack_level, int rsync, int rsync14, int rsync16); |
| 133 |
|
| 134 |
/* in trees.c */ |
| 135 |
void ct_init(void); |
| 136 |
int ct_tally(int pack_level, int dist, int lc); |
| 137 |
void flush_block(char *buf, ulg stored_len, int pad, int eof); |
| 138 |
|
| 139 |
/* in bits.c */ |
| 140 |
void bi_init(int zipfile); |
| 141 |
void send_bits(int value, int length); |
| 142 |
unsigned bi_reverse(unsigned value, int length); |
| 143 |
void bi_windup(void); |
| 144 |
void copy_block(char *buf, unsigned len, int header); |
| 145 |
extern int (*read_buf)(char *buf, unsigned size); |
| 146 |
|
| 147 |
/* in util.c: */ |
| 148 |
extern ulg updcrc(uch *s, unsigned n); |
| 149 |
extern void flush_outbuf(void); |
| 150 |
extern void write_buf(int fd, void *buf, unsigned cnt); |
| 151 |
extern int read_buffer(int fd, void *buf, unsigned int cnt); |
| 152 |
extern void gzip_error(char *m); |
| 153 |
extern void read_error(void); |
| 154 |
extern void write_error(void); |