From 33e71060aa657e80e87b8d73e9e5cc3dd9be4e8b Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Mon, 16 Feb 2026 18:26:35 -0800 Subject: Align the backup zmem* functions with their library counterparts. --- zutil.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'zutil.c') diff --git a/zutil.c b/zutil.c index 6e8a3697..860faddc 100644 --- a/zutil.c +++ b/zutil.c @@ -150,28 +150,34 @@ const char * ZEXPORT zError(int err) { #ifndef HAVE_MEMCPY -void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) { - if (len == 0) return; - do { - *dest++ = *source++; /* ??? to be unrolled */ - } while (--len != 0); +void ZLIB_INTERNAL zmemcpy(void FAR *dst, const void FAR *src, z_size_t n) { + uchf *p = dst; + const uchf *q = src; + while (n) { + *p++ = *q++; + n--; + } } -int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) { - uInt j; - - for (j = 0; j < len; j++) { - if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; +int ZLIB_INTERNAL zmemcmp(const void FAR *s1, const void FAR *s2, z_size_t n) { + const uchf *p = s1, *q = s2; + while (n) { + if (*p++ != *q++) + return (int)p[-1] - (int)q[-1]; + n--; } return 0; } -void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) { +void ZLIB_INTERNAL zmemzero(void FAR *b, z_size_t len) { + uchf *p = b; if (len == 0) return; - do { - *dest++ = 0; /* ??? to be unrolled */ - } while (--len != 0); + while (len) { + *p++ = 0; + len--; + } } + #endif #ifndef Z_SOLO -- cgit v1.2.3-55-g6feb