FGx  1
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
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 /* ------------------------------------------------------
7  gzguts.h -- full import of the zlib-1.2.5.tar.gz source
8  Here version bumped to 1.2.5.1
9  2011-07-01 - Geoff R. McLane
10  link-in to the FGx application, providing zlib compression
11  and decompression services
12  ------------------------------------------------------ */
13 #define FGX_GZGUTS_H
14 #ifdef _MSC_VER
15 #pragma warning ( disable : 4996 ) /* remove MS specific 'use ISO C++ conformant name' and other warnings */
16 #endif
17 #ifdef _LARGEFILE64_SOURCE
18 # ifndef _LARGEFILE_SOURCE
19 # define _LARGEFILE_SOURCE 1
20 # endif
21 # ifdef _FILE_OFFSET_BITS
22 # undef _FILE_OFFSET_BITS
23 # endif
24 #endif
25 
26 #if defined(FGX_GZGUTS_H)
27 # define ZLIB_INTERNAL /* FGx - special case - make this nothing */
28 #else
29 #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
30 # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
31 #else
32 # define ZLIB_INTERNAL
33 #endif
34 #endif /* FGX_GZGUTS_H y/n */
35 
36 #include <stdio.h>
37 #include "fgx_zlib.h"
38 #ifdef STDC
39 # include <string.h>
40 # include <stdlib.h>
41 # include <limits.h>
42 #endif
43 #include <fcntl.h>
44 
45 #ifdef NO_DEFLATE /* for compatibility with old definition */
46 # define NO_GZCOMPRESS
47 #endif
48 
49 #ifdef _MSC_VER
50 # include <io.h>
51 # define vsnprintf _vsnprintf
52 #else
53 #include <unistd.h>
54 #endif
55 
56 #ifndef local
57 # define local static
58 #endif
59 /* compile with -Dlocal if your debugger can't find static symbols */
60 
61 /* gz* functions always use library allocation functions */
62 #ifndef STDC
63  extern voidp malloc OF((uInt size));
64  extern void free OF((voidpf ptr));
65 #endif
66 
67 /* get errno and strerror definition */
68 #if defined UNDER_CE
69 # include <windows.h>
70 # define zstrerror() gz_strwinerror((DWORD)GetLastError())
71 #else
72 # ifdef STDC
73 # include <errno.h>
74 # define zstrerror() strerror(errno)
75 # else
76 # define zstrerror() "stdio error (consult errno)"
77 # endif
78 #endif
79 
80 /* provide prototypes for these when building zlib without LFS */
81 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
82  ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
83  ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
84  ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
85  ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
86 #endif
87 
88 /* default i/o buffer size -- double this for output when reading */
89 #define GZBUFSIZE 8192
90 
91 /* gzip modes, also provide a little integrity check on the passed structure */
92 #define GZ_NONE 0
93 #define GZ_READ 7247
94 #define GZ_WRITE 31153
95 #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
96 
97 /* values for gz_state how */
98 #define LOOK 0 /* look for a gzip header */
99 #define COPY 1 /* copy input directly */
100 #define GZIP 2 /* decompress a gzip stream */
101 
102 /* internal gzip file state data structure */
103 typedef struct {
104  /* used for both reading and writing */
105  int mode; /* see gzip modes above */
106  int fd; /* file descriptor */
107  char *path; /* path or fd for error messages */
108  z_off64_t pos; /* current position in uncompressed data */
109  unsigned size; /* buffer size, zero if not allocated yet */
110  unsigned want; /* requested buffer size, default is GZBUFSIZE */
111  unsigned char *in; /* input buffer */
112  unsigned char *out; /* output buffer (double-sized when reading) */
113  unsigned char *next; /* next output data to deliver or write */
114  /* just for reading */
115  unsigned have; /* amount of output data unused at next */
116  int eof; /* true if end of input file reached */
117  z_off64_t start; /* where the gzip data started, for rewinding */
118  z_off64_t raw; /* where the raw data started, for seeking */
119  int how; /* 0: get header, 1: copy, 2: decompress */
120  int direct; /* true if last read direct, false if gzip */
121  /* just for writing */
122  int level; /* compression level */
123  int strategy; /* compression strategy */
124  /* seek request */
125  z_off64_t skip; /* amount to skip (already rewound if backwards) */
126  int seek; /* true if seek request pending */
127  /* error information */
128  int err; /* error code */
129  char *msg; /* error message */
130  /* zlib inflate or deflate stream */
131  z_stream strm; /* stream structure in-place (not a pointer) */
132 } gz_state;
133 typedef gz_state FAR *gz_statep;
134 
135 /* shared functions */
136 void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
137 #if defined UNDER_CE
138 char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
139 #endif
140 
141 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
142  value -- needed when comparing unsigned to z_off64_t, which is signed
143  (possible z_off64_t types off_t, off64_t, and long are all signed) */
144 #ifdef INT_MAX
145 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
146 #else
147 unsigned ZLIB_INTERNAL gz_intmax OF((void));
148 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
149 #endif