zlib 1.2.3.5
[third_party/zlib] / gzguts.h
1 /* gzguts.h -- zlib internal header definitions for gz* operations
2  * Copyright (C) 2004, 2005, 2010 Mark Adler
3  * For conditions of distribution and use, see copyright notice in zlib.h
4  */
5
6 #ifdef _LARGEFILE64_SOURCE
7 #  ifndef _LARGEFILE_SOURCE
8 #    define _LARGEFILE_SOURCE
9 #  endif
10 #  ifdef _FILE_OFFSET_BITS
11 #    undef _FILE_OFFSET_BITS
12 #  endif
13 #endif
14
15 #define ZLIB_INTERNAL
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <fcntl.h>
21 #include "zlib.h"
22
23 #ifdef NO_DEFLATE       /* for compatibility with old definition */
24 #  define NO_GZCOMPRESS
25 #endif
26
27 #ifdef WIN32
28 #  include <io.h>
29 #  define vsnprintf _vsnprintf
30 #endif
31
32 #ifndef local
33 #  define local static
34 #endif
35 /* compile with -Dlocal if your debugger can't find static symbols */
36
37 /* gz* functions always use library allocation functions */
38 #ifndef STDC
39   extern voidp  malloc OF((uInt size));
40   extern void   free   OF((voidpf ptr));
41 #endif
42
43 /* get errno and strerror definition */
44 #if defined UNDER_CE && defined NO_ERRNO_H
45 #  define zstrerror(errnum) strwinerror((DWORD)errnum)
46 #else
47 #  ifdef STDC
48 #    include <errno.h>
49 #    define zstrerror() strerror(errno)
50 #  else
51 #    define zstrerror() "stdio error (consult errno)"
52 #  endif
53 #endif
54
55 /* MVS fdopen() */
56 #ifdef __MVS__
57 #  pragma map (fdopen , "\174\174FDOPEN")
58    FILE *fdopen(int, const char *);
59 #endif
60
61 #ifdef _LARGEFILE64_SOURCE
62 #  define z_off64_t off64_t
63 #else
64 #  define z_off64_t z_off_t
65 #endif
66
67 /* default i/o buffer size -- double this for output when reading */
68 #define GZBUFSIZE 8192
69
70 /* gzip modes, also provide a little integrity check on the passed structure */
71 #define GZ_NONE 0
72 #define GZ_READ 7247
73 #define GZ_WRITE 31153
74 #define GZ_APPEND 1     /* mode set to GZ_WRITE after the file is opened */
75
76 /* internal gzip file state data structure */
77 typedef struct {
78         /* used for both reading and writing */
79     int mode;               /* see gzip modes above */
80     int fd;                 /* file descriptor */
81     char *path;             /* path or fd for error messages */
82     z_off64_t pos;          /* current position in uncompressed data */
83     unsigned size;          /* buffer size, zero if not allocated yet */
84     unsigned want;          /* requested buffer size, default is GZBUFSIZE */
85     unsigned char *in;      /* input buffer */
86     unsigned char *out;     /* output buffer (double-sized when reading) */
87     unsigned char *next;    /* next output data to deliver or write */
88         /* just for reading */
89     int how;                /* 0: get header, 1: copy, 2: decompress */
90     unsigned have;          /* amount of output data unused */
91     z_off64_t start;        /* where the gzip data started, for rewinding */
92     z_off64_t raw;          /* where the raw data started, for seeking */
93     int eof;                /* true if end of input file reached */
94         /* just for writing */
95     int level;              /* compression level */
96     int strategy;           /* compression strategy */
97         /* seek request */
98     int seek;               /* true if seek request pending */
99     z_off64_t skip;         /* amount to skip (already rewound if backwards) */
100         /* error information */
101     int err;                /* error code */
102     char *msg;              /* error message */
103         /* zlib inflate or deflate stream */
104     z_stream strm;          /* stream structure in-place (not a pointer) */
105 } gz_state;
106 typedef gz_state FAR *gz_statep;
107
108 /* shared functions */
109 ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, char *));