]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add back gz_intmax for zlib compatibility when linking statically
authorNathan Moinvaziri <nathan@nathanm.com>
Sun, 4 Feb 2024 22:18:56 +0000 (14:18 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 7 Feb 2024 18:15:56 +0000 (19:15 +0100)
gzguts.h
gzlib.c
zlib.map

index dc0ebeb2a253bc4bf356bee3e3d4c53b0674d8fc..d501525316432336d8b5e5f970a7bd3d8809c273 100644 (file)
--- a/gzguts.h
+++ b/gzguts.h
@@ -135,11 +135,12 @@ typedef gz_state *gz_statep;
 
 /* shared functions */
 void Z_INTERNAL gz_error(gz_state *, int, const char *);
-
+#ifdef ZLIB_COMPAT
+unsigned Z_INTERNAL gz_intmax(void);
+#endif
 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
    value -- needed when comparing unsigned to z_off64_t, which is signed
    (possible z_off64_t types off_t, off64_t, and long are all signed) */
-unsigned Z_INTERNAL gz_intmax(void);
 #define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
 
 #endif /* GZGUTS_H_ */
diff --git a/gzlib.c b/gzlib.c
index 8c7a1dc0b5caf55114f81c954b5ed952df6274d0..c8bca4d5e1e10d4984b96f36bb3d4df57c8b1c3b 100644 (file)
--- a/gzlib.c
+++ b/gzlib.c
@@ -524,20 +524,8 @@ void Z_INTERNAL gz_error(gz_state *state, int err, const char *msg) {
     (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, "%s%s%s", state->path, ": ", msg);
 }
 
-/* portably return maximum value for an int (when limits.h presumed not
-   available) -- we need to do this to cover cases where 2's complement not
-   used, since C standard permits 1's complement and sign-bit representations,
-   otherwise we could just use ((unsigned)-1) >> 1 */
+#ifdef ZLIB_COMPAT
 unsigned Z_INTERNAL gz_intmax(void) {
-#ifdef INT_MAX
     return INT_MAX;
-#else
-    unsigned p = 1, q;
-    do {
-        q = p;
-        p <<= 1;
-        p++;
-    } while (p > q);
-    return q >> 1;
-#endif
 }
+#endif
index ebca10d351ed0bd6363bcbaa7c02f567f83cbcaa..293e803729d81714bad4bab089c4304050b4b1d1 100644 (file)
--- a/zlib.map
+++ b/zlib.map
@@ -13,6 +13,7 @@ ZLIB_1.2.0 {
     zcfree;
     z_errmsg;
     gz_error;
+    gz_intmax;
     _*;
 };