diff mbox series

[v3,05/10] compat/zlib: provide `deflateBound()` shim centrally

Message ID 20250116-b4-pks-compat-drop-uncompress2-v3-5-f2af1f5c4a06@pks.im (mailing list archive)
State New
Headers show
Series compat/zlib: allow use of zlib-ng as backend | expand

Commit Message

Patrick Steinhardt Jan. 16, 2025, 9:17 a.m. UTC
The `deflateBound()` function has only been introduced with zlib 1.2.0.
When linking against a zlib version older than that we thus provide our
own compatibility shim. Move this shim into "compat/zlib.h" so that we
can adapt it based on whether or not we use zlib-ng in a subsequent
commit.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 compat/zlib-compat.h | 4 ++++
 git-zlib.c           | 4 ----
 2 files changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/compat/zlib-compat.h b/compat/zlib-compat.h
index bc20b884ef..96a08811a9 100644
--- a/compat/zlib-compat.h
+++ b/compat/zlib-compat.h
@@ -3,4 +3,8 @@ 
 
 #include <zlib.h>
 
+#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
+# define deflateBound(c,s)  ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
+#endif
+
 #endif /* COMPAT_ZLIB_H */
diff --git a/git-zlib.c b/git-zlib.c
index d43bbeb6da..2e973320c2 100644
--- a/git-zlib.c
+++ b/git-zlib.c
@@ -147,10 +147,6 @@  int git_inflate(git_zstream *strm, int flush)
 	return status;
 }
 
-#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
-#define deflateBound(c,s)  ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
-#endif
-
 unsigned long git_deflate_bound(git_zstream *strm, unsigned long size)
 {
 	return deflateBound(&strm->z, size);