xref: /aosp_15_r20/external/zlib/patches/0000-build.patch (revision 86ee64e75fa5f8bce2c8c356138035642429cd05)
1diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c
2index 782d32469ae5d..a38881dca90a2 100644
3--- a/contrib/minizip/ioapi.c
4+++ b/contrib/minizip/ioapi.c
5@@ -14,7 +14,7 @@
6         #define _CRT_SECURE_NO_WARNINGS
7 #endif
8
9-#if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
10+#if defined(__APPLE__) || defined(__Fuchsia__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
11 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
12 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
13 #define FTELLO_FUNC(stream) ftello(stream)
14diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c
15index 08536e94b8a28..bbd7773e67146 100644
16--- a/contrib/minizip/iowin32.c
17+++ b/contrib/minizip/iowin32.c
18@@ -25,7 +25,12 @@
19 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
20 #endif
21
22+#ifdef _WIN32_WINNT
23+#undef _WIN32_WINNT
24+#define _WIN32_WINNT 0x601
25+#endif
26
27+#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
28 // see Include/shared/winapifamily.h in the Windows Kit
29 #if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
30
31@@ -37,6 +42,7 @@
32 #define IOWIN32_USING_WINRT_API 1
33 #endif
34 #endif
35+#endif
36
37 typedef struct
38 {
39diff --git a/gzread.c b/gzread.c
40index 956b91ea7d9e..832d3ef98c59 100644
41--- a/gzread.c
42+++ b/gzread.c
43@@ -443,7 +443,11 @@ z_size_t ZEXPORT gzfread(buf, size, nitems, file)
44 #  undef z_gzgetc
45 #else
46 #  undef gzgetc
47+#  ifdef Z_CR_PREFIX_SET
48+#    define gzgetc Cr_z_gzgetc
49+#  endif
50 #endif
51+
52 int ZEXPORT gzgetc(file)
53     gzFile file;
54 {
55diff --git a/zconf.h b/zconf.h
56index 5e1d68a004e9..a7a815f575a7 100644
57--- a/zconf.h
58+++ b/zconf.h
59@@ -8,6 +8,10 @@
60 #ifndef ZCONF_H
61 #define ZCONF_H
62
63+/*
64+ * This library is also built as a part of AOSP, which does not need to include
65+ * chromeconf.h. This config does not want chromeconf.h, so it can set this
66+ * macro to opt out. While this works today, there's no guarantee that building
67+ * zlib outside of Chromium keeps working in the future.
68+ */
69+#if !defined(CHROMIUM_ZLIB_NO_CHROMECONF)
70+/* This include does prefixing as below, but with an updated set of names.  Also
71+ * sets up export macros in component builds. */
72+#include "chromeconf.h"
73+#endif
74+
75 /*
76  * If you *really* need a unique prefix for all types and library functions,
77  * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
78@@ -431,7 +434,7 @@ typedef uLong FAR uLongf;
79    typedef unsigned long z_crc_t;
80 #endif
81
82-#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by ./configure */
83+#if !defined(_WIN32)
84 #  define Z_HAVE_UNISTD_H
85 #endif
86
87diff --git a/zlib.h b/zlib.h
88index f09cdaf1e054..99fd467f6b1a 100644
89--- a/zlib.h
90+++ b/zlib.h
91@@ -1824,6 +1824,11 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file));  /* backward compatibility */
92 #  undef z_gzgetc
93 #  define z_gzgetc(g) \
94           ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
95+#elif defined(Z_CR_PREFIX_SET)
96+#    undef gzgetc
97+#    define gzgetc(g) \
98+          ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) \
99+                     : (Cr_z_gzgetc)(g))
100 #else
101 #  define gzgetc(g) \
102           ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
103@@ -1853,11 +1858,29 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file));  /* backward compatibility */
104 #    define z_adler32_combine z_adler32_combine64
105 #    define z_crc32_combine z_crc32_combine64
106 #  else
107+#    ifdef gzopen
108+#      undef gzopen
109+#    endif
110 #    define gzopen gzopen64
111+#    ifdef gzseek
112+#      undef gzseek
113+#    endif
114 #    define gzseek gzseek64
115+#    ifdef gztell
116+#      undef gztell
117+#    endif
118 #    define gztell gztell64
119+#    ifdef gzoffset
120+#      undef gzoffset
121+#    endif
122 #    define gzoffset gzoffset64
123+#    ifdef adler32_combine
124+#      undef adler32_combine
125+#    endif
126 #    define adler32_combine adler32_combine64
127+#    ifdef crc32_combine
128+#      undef crc32_combine
129+#    endif
130 #    define crc32_combine crc32_combine64
131 #  endif
132 #  ifndef Z_LARGE64
133diff --git a/zutil.h b/zutil.h
134index b079ea6a80f5..80375b8b6109 100644
135--- a/zutil.h
136+++ b/zutil.h
137@@ -28,6 +28,21 @@
138 #  include <string.h>
139 #  include <stdlib.h>
140 #endif
141+#ifdef NO_ERRNO_H
142+#   ifdef _WIN32_WCE
143+      /* The Microsoft C Run-Time Library for Windows CE doesn't have
144+       * errno.  We define it as a global variable to simplify porting.
145+       * Its value is always 0 and should not be used.  We rename it to
146+       * avoid conflict with other libraries that use the same workaround.
147+       */
148+#     define errno z_errno
149+#   endif
150+    extern int errno;
151+#else
152+#  ifndef _WIN32_WCE
153+#    include <errno.h>
154+#  endif
155+#endif
156
157 #ifdef Z_SOLO
158    typedef long ptrdiff_t;  /* guess -- will be caught if guess is wrong */
159