1[zlib] Fix zlib sources for compilation with FreeType 2 3We must ensure that they do not issue compiler errors or warnings when they 4are compiled as part of `src/gzip/ftgzip.c`. 5 6* src/gzip/gzguts.h (COPY): Rename to... 7(COPY__): ... this since `COPY` and `COPY_` conflict with enum values, 8which have the same name in `zlib.h`. 9 10* src/gzip/inflate.c, src/gzip/adler32.c, src/gzip/crc32.c, 11src/gzip/zutil.c: Omit unused function declarations and definitions when 12`Z_FREETYPE` is defined. 13 14* src/gzip/inffast.h (inflate_fast): Declare as static. 15 16* src/gzip/inftrees.c (inflate_copyright): Declare as static. 17 18* src/gzip/zlib.h: Include `ftzconf.h` instead of `zconf.h` to avoid 19conflicts with system-installed headers. 20Omit unused function declarations when `Z_FREETYPE` is defined. 21(inflateInit2)[Z_FREETYPE]: Provide proper declaration. 22 23* src/gzip/zutil.h: Use `ft_memxxx` functions instead of `memxxx`. 24Omit unused function declarations when `Z_FREETYPE` is defined. 25 26* src/gzip/inflate.h, src/gzip/inftrees.h: Add header guard macros to 27prevent compiler errors. 28 29* src/gzip/inftrees.h: Add header guard macros to prevent compiler errors. 30(inflate_table): Declare as static. 31 32diff --git b/src/gzip/adler32.c a/src/gzip/adler32.c 33index be5e8a247..aa032e1dd 100644 34--- b/src/gzip/adler32.c 35+++ a/src/gzip/adler32.c 36@@ -7,7 +7,9 @@ 37 38 #include "zutil.h" 39 40+#ifndef Z_FREETYPE 41 local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 42+#endif 43 44 #define BASE 65521U /* largest prime smaller than 65536 */ 45 #define NMAX 5552 46@@ -139,6 +141,8 @@ uLong ZEXPORT adler32( 47 return adler32_z(adler, buf, len); 48 } 49 50+#ifndef Z_FREETYPE 51+ 52 /* ========================================================================= */ 53 local uLong adler32_combine_( 54 uLong adler1, 55@@ -184,3 +188,5 @@ uLong ZEXPORT adler32_combine64( 56 { 57 return adler32_combine_(adler1, adler2, len2); 58 } 59+ 60+#endif /* !Z_FREETYPE */ 61diff --git b/src/gzip/crc32.c a/src/gzip/crc32.c 62index 3a52aa89d..6cd1b09d5 100644 63--- b/src/gzip/crc32.c 64+++ a/src/gzip/crc32.c 65@@ -103,9 +103,11 @@ 66 # define ARMCRC32 67 #endif 68 69+#ifndef Z_FREETYPE 70 /* Local functions. */ 71 local z_crc_t multmodp OF((z_crc_t a, z_crc_t b)); 72 local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); 73+#endif /* Z_FREETYPE */ 74 75 #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) 76 local z_word_t byte_swap OF((z_word_t word)); 77@@ -544,6 +546,8 @@ local void braid(ltl, big, n, w) 78 * generation above. 79 */ 80 81+#ifndef Z_FREETYPE 82+ 83 /* 84 Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, 85 reflected. For speed, this requires that a not be zero. 86@@ -600,6 +604,8 @@ const z_crc_t FAR * ZEXPORT get_crc_table() 87 return (const z_crc_t FAR *)crc_table; 88 } 89 90+#endif /* Z_FREETYPE */ 91+ 92 /* ========================================================================= 93 * Use ARM machine instructions if available. This will compute the CRC about 94 * ten times faster than the braided calculation. This code does not check for 95@@ -1077,6 +1083,8 @@ unsigned long ZEXPORT crc32( 96 return crc32_z(crc, buf, len); 97 } 98 99+#ifndef Z_FREETYPE 100+ 101 /* ========================================================================= */ 102 uLong ZEXPORT crc32_combine64( 103 uLong crc1, 104@@ -1123,3 +1131,5 @@ uLong ZEXPORT crc32_combine_op( 105 { 106 return multmodp(op, crc1) ^ (crc2 & 0xffffffff); 107 } 108+ 109+#endif /* Z_FREETYPE */ 110diff --git b/src/gzip/gzguts.h a/src/gzip/gzguts.h 111index 57faf3716..4f09a52a7 100644 112--- b/src/gzip/gzguts.h 113+++ a/src/gzip/gzguts.h 114@@ -163,7 +163,7 @@ 115 116 /* values for gz_state how */ 117 #define LOOK 0 /* look for a gzip header */ 118-#define COPY 1 /* copy input directly */ 119+#define COPY__ 1 /* copy input directly */ 120 #define GZIP 2 /* decompress a gzip stream */ 121 122 /* internal gzip file state data structure */ 123diff --git b/src/gzip/inffast.h a/src/gzip/inffast.h 124index e5c1aa4ca..684ae878c 100644 125--- b/src/gzip/inffast.h 126+++ a/src/gzip/inffast.h 127@@ -8,4 +8,4 @@ 128 subject to change. Applications should only use zlib.h. 129 */ 130 131-void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 132+static void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 133diff --git b/src/gzip/inflate.c a/src/gzip/inflate.c 134index c9e566b03..5117e2e26 100644 135--- b/src/gzip/inflate.c 136+++ a/src/gzip/inflate.c 137@@ -99,8 +99,10 @@ local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, 138 #ifdef BUILDFIXED 139 void makefixed OF((void)); 140 #endif 141+#ifndef Z_FREETYPE 142 local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, 143 unsigned len)); 144+#endif 145 146 local int inflateStateCheck( 147 z_streamp strm) 148@@ -239,6 +241,8 @@ int ZEXPORT inflateInit2_( 149 return ret; 150 } 151 152+#ifndef Z_FREETYPE 153+ 154 int ZEXPORT inflateInit_( 155 z_streamp strm, 156 const char *version, 157@@ -268,6 +272,8 @@ int ZEXPORT inflatePrime( 158 return Z_OK; 159 } 160 161+#endif /* !Z_FREETYPE */ 162+ 163 /* 164 Return state with length and distance decoding tables and index sizes set to 165 fixed code decoding. Normally this returns fixed tables from inffixed.h. 166@@ -1315,6 +1321,8 @@ int ZEXPORT inflateEnd( 167 return Z_OK; 168 } 169 170+#ifndef Z_FREETYPE 171+ 172 int ZEXPORT inflateGetDictionary( 173 z_streamp strm, 174 Bytef *dictionary, 175@@ -1593,3 +1601,5 @@ unsigned long ZEXPORT inflateCodesUsed( 176 state = (struct inflate_state FAR *)strm->state; 177 return (unsigned long)(state->next - state->codes); 178 } 179+ 180+#endif /* !Z_FREETYPE */ 181diff --git b/src/gzip/inflate.h a/src/gzip/inflate.h 182index f127b6b1f..c6f5a52e1 100644 183--- b/src/gzip/inflate.h 184+++ a/src/gzip/inflate.h 185@@ -3,6 +3,9 @@ 186 * For conditions of distribution and use, see copyright notice in zlib.h 187 */ 188 189+#ifndef INFLATE_H 190+#define INFLATE_H 191+ 192 /* WARNING: this file should *not* be used by applications. It is 193 part of the implementation of the compression library and is 194 subject to change. Applications should only use zlib.h. 195@@ -124,3 +127,5 @@ struct inflate_state { 196 int back; /* bits back of last unprocessed length/lit */ 197 unsigned was; /* initial length of match */ 198 }; 199+ 200+#endif /* INFLATE_H */ 201diff --git b/src/gzip/inftrees.c a/src/gzip/inftrees.c 202index d8405a24c..dd4965e9a 100644 203--- b/src/gzip/inftrees.c 204+++ a/src/gzip/inftrees.c 205@@ -8,7 +8,7 @@ 206 207 #define MAXBITS 15 208 209-const char inflate_copyright[] = 210+static const char inflate_copyright[] = 211 " inflate 1.2.13 Copyright 1995-2022 Mark Adler "; 212 /* 213 If you use the zlib library in a product, an acknowledgment is welcome 214diff --git b/src/gzip/inftrees.h a/src/gzip/inftrees.h 215index f53665311..a2207efb1 100644 216--- b/src/gzip/inftrees.h 217+++ a/src/gzip/inftrees.h 218@@ -3,6 +3,9 @@ 219 * For conditions of distribution and use, see copyright notice in zlib.h 220 */ 221 222+#ifndef INFTREES_H 223+#define INFTREES_H 224+ 225 /* WARNING: this file should *not* be used by applications. It is 226 part of the implementation of the compression library and is 227 subject to change. Applications should only use zlib.h. 228@@ -57,6 +60,8 @@ typedef enum { 229 DISTS 230 } codetype; 231 232-int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 233+static int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 234 unsigned codes, code FAR * FAR *table, 235 unsigned FAR *bits, unsigned short FAR *work)); 236+ 237+#endif /* INFTREES_H_ */ 238diff --git b/src/gzip/zlib.h a/src/gzip/zlib.h 239index 953cb5012..3f2f76e3c 100644 240--- b/src/gzip/zlib.h 241+++ a/src/gzip/zlib.h 242@@ -31,7 +31,7 @@ 243 #ifndef ZLIB_H 244 #define ZLIB_H 245 246-#include "zconf.h" 247+#include "ftzconf.h" 248 249 #ifdef __cplusplus 250 extern "C" { 251@@ -211,6 +211,8 @@ typedef gz_header FAR *gz_headerp; 252 253 #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 254 255+#ifndef Z_FREETYPE 256+ 257 #define zlib_version zlibVersion() 258 /* for compatibility with versions < 1.0.2 */ 259 260@@ -373,6 +375,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 261 deallocated). 262 */ 263 264+#endif /* !Z_FREETYPE */ 265 266 /* 267 ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 268@@ -534,6 +537,8 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 269 The following functions are needed only in some special applications. 270 */ 271 272+#ifndef Z_FREETYPE 273+ 274 /* 275 ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 276 int level, 277@@ -956,6 +961,8 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 278 destination. 279 */ 280 281+#endif /* !Z_FREETYPE */ 282+ 283 ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 284 /* 285 This function is equivalent to inflateEnd followed by inflateInit, 286@@ -980,6 +987,8 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, 287 the windowBits parameter is invalid. 288 */ 289 290+#ifndef Z_FREETYPE 291+ 292 ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, 293 int bits, 294 int value)); 295@@ -1069,6 +1078,8 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 296 stream state was inconsistent. 297 */ 298 299+#endif /* !Z_FREETYPE */ 300+ 301 /* 302 ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 303 unsigned char FAR *window)); 304@@ -1095,6 +1106,8 @@ typedef unsigned (*in_func) OF((void FAR *, 305 z_const unsigned char FAR * FAR *)); 306 typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 307 308+#ifndef Z_FREETYPE 309+ 310 ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 311 in_func in, void FAR *in_desc, 312 out_func out, void FAR *out_desc)); 313@@ -1214,6 +1227,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 314 27-31: 0 (reserved) 315 */ 316 317+#endif /* !Z_FREETYPE */ 318+ 319 #ifndef Z_SOLO 320 321 /* utility functions */ 322@@ -1765,6 +1780,8 @@ ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); 323 crc32_combine_op(). 324 */ 325 326+#ifndef Z_FREETYPE 327+ 328 ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); 329 /* 330 Give the same result as crc32_combine(), using op in place of len2. op is 331@@ -1822,6 +1839,19 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 332 ZLIB_VERSION, (int)sizeof(z_stream)) 333 #endif 334 335+#else /* Z_FREETYPE */ 336+ 337+ 338+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 339+ const char *version, int stream_size)); 340+ 341+# define inflateInit2(strm, windowBits) \ 342+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ 343+ (int)sizeof(z_stream)) 344+ 345+#endif /* Z_FREETYPE */ 346+ 347+ 348 #ifndef Z_SOLO 349 350 /* gzgetc() macro and its supporting function and exposed data structure. Note 351@@ -1901,20 +1931,25 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ 352 353 #else /* Z_SOLO */ 354 355+#ifndef Z_FREETYPE 356 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 357 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 358 ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); 359+#endif 360 361 #endif /* !Z_SOLO */ 362 363 /* undocumented functions */ 364+#ifndef Z_FREETYPE 365 ZEXTERN const char * ZEXPORT zError OF((int)); 366 ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); 367 ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); 368 ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); 369 ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); 370 ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF((z_streamp)); 371+#endif /* !Z_FREETYPE */ 372 ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); 373+#ifndef Z_FREETYPE 374 ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); 375 #if defined(_WIN32) && !defined(Z_SOLO) 376 ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, 377@@ -1927,6 +1962,7 @@ ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, 378 va_list va)); 379 # endif 380 #endif 381+#endif /* !Z_FREETYPE */ 382 383 #ifdef __cplusplus 384 } 385diff --git b/src/gzip/zutil.c a/src/gzip/zutil.c 386index ef174ca64..542706ca0 100644 387--- b/src/gzip/zutil.c 388+++ a/src/gzip/zutil.c 389@@ -10,6 +10,8 @@ 390 # include "gzguts.h" 391 #endif 392 393+#ifndef Z_FREETYPE 394+ 395 z_const char * const z_errmsg[10] = { 396 (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */ 397 (z_const char *)"stream end", /* Z_STREAM_END 1 */ 398@@ -138,6 +140,8 @@ const char * ZEXPORT zError( 399 return ERR_MSG(err); 400 } 401 402+#endif /* !Z_FREETYPE */ 403+ 404 #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800 405 /* The older Microsoft C Run-Time Library for Windows CE doesn't have 406 * errno. We define it as a global variable to simplify porting. 407@@ -159,6 +163,8 @@ void ZLIB_INTERNAL zmemcpy( 408 } while (--len != 0); 409 } 410 411+#ifndef Z_FREETYPE 412+ 413 int ZLIB_INTERNAL zmemcmp( 414 const Bytef* s1, 415 const Bytef* s2, 416@@ -181,6 +187,7 @@ void ZLIB_INTERNAL zmemzero( 417 *dest++ = 0; /* ??? to be unrolled */ 418 } while (--len != 0); 419 } 420+#endif /* !Z_FREETYPE */ 421 #endif 422 423 #ifndef Z_SOLO 424diff --git b/src/gzip/zutil.h a/src/gzip/zutil.h 425index 0bc7f4ecd..055ba8b62 100644 426--- b/src/gzip/zutil.h 427+++ a/src/gzip/zutil.h 428@@ -53,8 +53,10 @@ typedef unsigned long ulg; 429 # endif 430 #endif 431 432+#ifndef Z_FREETYPE 433 extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 434 /* (size given to avoid silly warnings with Visual C++) */ 435+#endif /* !Z_FREETYPE */ 436 437 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 438 439@@ -188,6 +190,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 440 #pragma warn -8066 441 #endif 442 443+#ifndef Z_FREETYPE 444+ 445 /* provide prototypes for these when building zlib without LFS */ 446 #if !defined(_WIN32) && \ 447 (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 448@@ -196,6 +200,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 449 ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); 450 #endif 451 452+#endif /* !Z_FREETYPE */ 453+ 454 /* common defaults */ 455 456 #ifndef OS_CODE 457@@ -227,9 +233,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 458 # define zmemcmp _fmemcmp 459 # define zmemzero(dest, len) _fmemset(dest, 0, len) 460 # else 461-# define zmemcpy memcpy 462-# define zmemcmp memcmp 463-# define zmemzero(dest, len) memset(dest, 0, len) 464+# define zmemcpy ft_memcpy 465+# define zmemcmp ft_memcmp 466+# define zmemzero(dest, len) ft_memset(dest, 0, len) 467 # endif 468 #else 469 void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 470