Skip to content

Commit

Permalink
Add back gz_intmax for zlib compatibility when linking statically
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz authored and Dead2 committed Feb 7, 2024
1 parent 0d2984d commit efae767
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
5 changes: 3 additions & 2 deletions gzguts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
16 changes: 2 additions & 14 deletions gzlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions zlib.map
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ZLIB_1.2.0 {
zcfree;
z_errmsg;
gz_error;
gz_intmax;
_*;
};

Expand Down

0 comments on commit efae767

Please sign in to comment.