~ubuntu-branches/ubuntu/quantal/gzip/quantal

« back to all changes in this revision

Viewing changes to .pc/zeroify-buffers.diff/gzip.h

  • Committer: Steve Langasek
  • Date: 2012-05-02 21:43:58 UTC
  • mfrom: (4.1.7 sid)
  • Revision ID: steve.langasek@canonical.com-20120502214358-rqnb1qrcqh7l42og
Merge version 1.4-5 from Debian unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* gzip.h -- common declarations for all gzip modules
2
 
 
3
 
   Copyright (C) 1997-1999, 2001, 2006-2007, 2009-2010 Free Software
4
 
   Foundation, Inc.
5
 
 
6
 
   Copyright (C) 1992-1993 Jean-loup Gailly.
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 3, 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
 
#if defined(__STDC__) || defined(PROTO)
23
 
#  define OF(args)  args
24
 
#else
25
 
#  define OF(args)  ()
26
 
#endif
27
 
 
28
 
#ifdef __STDC__
29
 
   typedef void *voidp;
30
 
#else
31
 
   typedef char *voidp;
32
 
#endif
33
 
 
34
 
#ifndef __attribute__
35
 
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
36
 
#  define __attribute__(x)
37
 
# endif
38
 
#endif
39
 
 
40
 
#ifndef ATTRIBUTE_NORETURN
41
 
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
42
 
#endif
43
 
 
44
 
/* I don't like nested includes, but the following headers are used
45
 
 * too often
46
 
 */
47
 
#include <stdio.h>
48
 
#include <sys/types.h> /* for off_t */
49
 
#include <time.h>
50
 
#include <string.h>
51
 
#define memzero(s, n) memset ((voidp)(s), 0, (n))
52
 
 
53
 
#ifndef RETSIGTYPE
54
 
#  define RETSIGTYPE void
55
 
#endif
56
 
 
57
 
#define local static
58
 
 
59
 
typedef unsigned char  uch;
60
 
typedef unsigned short ush;
61
 
typedef unsigned long  ulg;
62
 
 
63
 
/* Return codes from gzip */
64
 
#define OK      0
65
 
#define ERROR   1
66
 
#define WARNING 2
67
 
 
68
 
/* Compression methods (see algorithm.doc) */
69
 
#define STORED      0
70
 
#define COMPRESSED  1
71
 
#define PACKED      2
72
 
#define LZHED       3
73
 
/* methods 4 to 7 reserved */
74
 
#define DEFLATED    8
75
 
#define MAX_METHODS 9
76
 
extern int method;         /* compression method */
77
 
 
78
 
/* To save memory for 16 bit systems, some arrays are overlaid between
79
 
 * the various modules:
80
 
 * deflate:  prev+head   window      d_buf  l_buf  outbuf
81
 
 * unlzw:    tab_prefix  tab_suffix  stack  inbuf  outbuf
82
 
 * inflate:              window             inbuf
83
 
 * unpack:               window             inbuf  prefix_len
84
 
 * unlzh:    left+right  window      c_table inbuf c_len
85
 
 * For compression, input is done in window[]. For decompression, output
86
 
 * is done in window except for unlzw.
87
 
 */
88
 
 
89
 
#ifndef INBUFSIZ
90
 
#  ifdef SMALL_MEM
91
 
#    define INBUFSIZ  0x2000  /* input buffer size */
92
 
#  else
93
 
#    define INBUFSIZ  0x8000  /* input buffer size */
94
 
#  endif
95
 
#endif
96
 
#define INBUF_EXTRA  64     /* required by unlzw() */
97
 
 
98
 
#ifndef OUTBUFSIZ
99
 
#  ifdef SMALL_MEM
100
 
#    define OUTBUFSIZ   8192  /* output buffer size */
101
 
#  else
102
 
#    define OUTBUFSIZ  16384  /* output buffer size */
103
 
#  endif
104
 
#endif
105
 
#define OUTBUF_EXTRA 2048   /* required by unlzw() */
106
 
 
107
 
#ifndef DIST_BUFSIZE
108
 
#  ifdef SMALL_MEM
109
 
#    define DIST_BUFSIZE 0x2000 /* buffer for distances, see trees.c */
110
 
#  else
111
 
#    define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */
112
 
#  endif
113
 
#endif
114
 
 
115
 
#ifdef DYN_ALLOC
116
 
#  define EXTERN(type, array)  extern type * near array
117
 
#  define DECLARE(type, array, size)  type * near array
118
 
#  define ALLOC(type, array, size) { \
119
 
      array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
120
 
      if (!array) xalloc_die (); \
121
 
   }
122
 
#  define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
123
 
#else
124
 
#  define EXTERN(type, array)  extern type array[]
125
 
#  define DECLARE(type, array, size)  type array[size]
126
 
#  define ALLOC(type, array, size)
127
 
#  define FREE(array)
128
 
#endif
129
 
 
130
 
EXTERN(uch, inbuf);          /* input buffer */
131
 
EXTERN(uch, outbuf);         /* output buffer */
132
 
EXTERN(ush, d_buf);          /* buffer for distances, see trees.c */
133
 
EXTERN(uch, window);         /* Sliding window and suffix table (unlzw) */
134
 
#define tab_suffix window
135
 
#ifndef MAXSEG_64K
136
 
#  define tab_prefix prev    /* hash link (see deflate.c) */
137
 
#  define head (prev+WSIZE)  /* hash head (see deflate.c) */
138
 
   EXTERN(ush, tab_prefix);  /* prefix code (see unlzw.c) */
139
 
#else
140
 
#  define tab_prefix0 prev
141
 
#  define head tab_prefix1
142
 
   EXTERN(ush, tab_prefix0); /* prefix for even codes */
143
 
   EXTERN(ush, tab_prefix1); /* prefix for odd  codes */
144
 
#endif
145
 
 
146
 
extern unsigned insize; /* valid bytes in inbuf */
147
 
extern unsigned inptr;  /* index of next byte to be processed in inbuf */
148
 
extern unsigned outcnt; /* bytes in output buffer */
149
 
extern int rsync;  /* deflate into rsyncable chunks */
150
 
 
151
 
extern off_t bytes_in;   /* number of input bytes */
152
 
extern off_t bytes_out;  /* number of output bytes */
153
 
extern off_t header_bytes;/* number of bytes in gzip header */
154
 
 
155
 
extern int  ifd;        /* input file descriptor */
156
 
extern int  ofd;        /* output file descriptor */
157
 
extern char ifname[];   /* input file name or "stdin" */
158
 
extern char ofname[];   /* output file name or "stdout" */
159
 
extern char *program_name;  /* program name */
160
 
 
161
 
extern struct timespec time_stamp; /* original time stamp (modification time) */
162
 
extern off_t ifile_size; /* input file size, -1 for devices (debug only) */
163
 
 
164
 
typedef int file_t;     /* Do not use stdio */
165
 
#define NO_FILE  (-1)   /* in memory compression */
166
 
 
167
 
 
168
 
#define PACK_MAGIC     "\037\036" /* Magic header for packed files */
169
 
#define GZIP_MAGIC     "\037\213" /* Magic header for gzip files, 1F 8B */
170
 
#define OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */
171
 
#define LZH_MAGIC      "\037\240" /* Magic header for SCO LZH Compress files*/
172
 
#define PKZIP_MAGIC    "\120\113\003\004" /* Magic header for pkzip files */
173
 
 
174
 
/* gzip flag byte */
175
 
#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
176
 
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
177
 
#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
178
 
#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
179
 
#define COMMENT      0x10 /* bit 4 set: file comment present */
180
 
#define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
181
 
#define RESERVED     0xC0 /* bit 6,7:   reserved */
182
 
 
183
 
/* internal file attribute */
184
 
#define UNKNOWN 0xffff
185
 
#define BINARY  0
186
 
#define ASCII   1
187
 
 
188
 
#ifndef WSIZE
189
 
#  define WSIZE 0x8000     /* window size--must be a power of two, and */
190
 
#endif                     /*  at least 32K for zip's deflate method */
191
 
 
192
 
#define MIN_MATCH  3
193
 
#define MAX_MATCH  258
194
 
/* The minimum and maximum match lengths */
195
 
 
196
 
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
197
 
/* Minimum amount of lookahead, except at the end of the input file.
198
 
 * See deflate.c for comments about the MIN_MATCH+1.
199
 
 */
200
 
 
201
 
#define MAX_DIST  (WSIZE-MIN_LOOKAHEAD)
202
 
/* In order to simplify the code, particularly on 16 bit machines, match
203
 
 * distances are limited to MAX_DIST instead of WSIZE.
204
 
 */
205
 
 
206
 
extern int decrypt;        /* flag to turn on decryption */
207
 
extern int exit_code;      /* program exit code */
208
 
extern int verbose;        /* be verbose (-v) */
209
 
extern int quiet;          /* be quiet (-q) */
210
 
extern int level;          /* compression level */
211
 
extern int test;           /* check .z file integrity */
212
 
extern int to_stdout;      /* output to stdout (-c) */
213
 
extern int save_orig_name; /* set if original name must be saved */
214
 
 
215
 
#define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
216
 
#define try_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
217
 
 
218
 
/* put_byte is used for the compressed output, put_ubyte for the
219
 
 * uncompressed output. However unlzw() uses window for its
220
 
 * suffix table instead of its output buffer, so it does not use put_ubyte
221
 
 * (to be cleaned up).
222
 
 */
223
 
#define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
224
 
   flush_outbuf();}
225
 
#define put_ubyte(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
226
 
   flush_window();}
227
 
 
228
 
/* Output a 16 bit value, lsb first */
229
 
#define put_short(w) \
230
 
{ if (outcnt < OUTBUFSIZ-2) { \
231
 
    outbuf[outcnt++] = (uch) ((w) & 0xff); \
232
 
    outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \
233
 
  } else { \
234
 
    put_byte((uch)((w) & 0xff)); \
235
 
    put_byte((uch)((ush)(w) >> 8)); \
236
 
  } \
237
 
}
238
 
 
239
 
/* Output a 32 bit value to the bit stream, lsb first */
240
 
#define put_long(n) { \
241
 
    put_short((n) & 0xffff); \
242
 
    put_short(((ulg)(n)) >> 16); \
243
 
}
244
 
 
245
 
#define seekable()    0  /* force sequential output */
246
 
#define translate_eol 0  /* no option -a yet */
247
 
 
248
 
#define tolow(c)  (isupper (c) ? tolower (c) : (c))  /* force to lower case */
249
 
 
250
 
/* Macros for getting two-byte and four-byte header values */
251
 
#define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
252
 
#define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
253
 
 
254
 
/* Diagnostic functions */
255
 
#ifdef DEBUG
256
 
#  define Assert(cond,msg) {if (!(cond)) gzip_error (msg);}
257
 
#  define Trace(x) fprintf x
258
 
#  define Tracev(x) {if (verbose) fprintf x ;}
259
 
#  define Tracevv(x) {if (verbose>1) fprintf x ;}
260
 
#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
261
 
#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
262
 
#else
263
 
#  define Assert(cond,msg)
264
 
#  define Trace(x)
265
 
#  define Tracev(x)
266
 
#  define Tracevv(x)
267
 
#  define Tracec(c,x)
268
 
#  define Tracecv(c,x)
269
 
#endif
270
 
 
271
 
#define WARN(msg) {if (!quiet) fprintf msg ; \
272
 
                   if (exit_code == OK) exit_code = WARNING;}
273
 
 
274
 
        /* in zip.c: */
275
 
extern int zip        OF((int in, int out));
276
 
extern int file_read  OF((char *buf,  unsigned size));
277
 
 
278
 
        /* in unzip.c */
279
 
extern int unzip      OF((int in, int out));
280
 
extern int check_zipfile OF((int in));
281
 
 
282
 
        /* in unpack.c */
283
 
extern int unpack     OF((int in, int out));
284
 
 
285
 
        /* in unlzh.c */
286
 
extern int unlzh      OF((int in, int out));
287
 
 
288
 
        /* in gzip.c */
289
 
void abort_gzip OF((void)) ATTRIBUTE_NORETURN;
290
 
 
291
 
        /* in deflate.c */
292
 
void lm_init OF((int pack_level, ush *flags));
293
 
off_t deflate OF((void));
294
 
 
295
 
        /* in trees.c */
296
 
void ct_init     OF((ush *attr, int *method));
297
 
int  ct_tally    OF((int dist, int lc));
298
 
off_t flush_block OF((char *buf, ulg stored_len, int eof));
299
 
 
300
 
        /* in bits.c */
301
 
void     bi_init    OF((file_t zipfile));
302
 
void     send_bits  OF((int value, int length));
303
 
unsigned bi_reverse OF((unsigned value, int length));
304
 
void     bi_windup  OF((void));
305
 
void     copy_block OF((char *buf, unsigned len, int header));
306
 
extern   int (*read_buf) OF((char *buf, unsigned size));
307
 
 
308
 
        /* in util.c: */
309
 
extern int copy           OF((int in, int out));
310
 
extern ulg  updcrc        OF((uch *s, unsigned n));
311
 
extern void clear_bufs    OF((void));
312
 
extern int  fill_inbuf    OF((int eof_ok));
313
 
extern void flush_outbuf  OF((void));
314
 
extern void flush_window  OF((void));
315
 
extern void write_buf     OF((int fd, voidp buf, unsigned cnt));
316
 
extern int read_buffer    OF((int fd, voidp buf, unsigned int cnt));
317
 
extern char *strlwr       OF((char *s));
318
 
extern char *gzip_base_name OF((char *fname));
319
 
extern int xunlink        OF((char *fname));
320
 
extern void make_simple_name OF((char *name));
321
 
extern char *add_envopt   OF((int *argcp, char ***argvp, char const *env));
322
 
extern void gzip_error    OF((char const *m)) ATTRIBUTE_NORETURN;
323
 
extern void xalloc_die    OF((void)) ATTRIBUTE_NORETURN;
324
 
extern void warning       OF((char const *m));
325
 
extern void read_error    OF((void)) ATTRIBUTE_NORETURN;
326
 
extern void write_error   OF((void)) ATTRIBUTE_NORETURN;
327
 
extern void display_ratio OF((off_t num, off_t den, FILE *file));
328
 
extern void fprint_off    OF((FILE *, off_t, int));
329
 
 
330
 
        /* in inflate.c */
331
 
extern int inflate OF((void));
332
 
 
333
 
        /* in yesno.c */
334
 
extern int yesno OF((void));