From: Paul Floyd Date: Fri, 26 Dec 2025 09:19:53 +0000 (+0100) Subject: Darwin redir: add a replacement for memmem X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db47a91c49ce711679399da080fc901615aad791;p=thirdparty%2Fvalgrind.git Darwin redir: add a replacement for memmem Of course, a bit different from the existing one. --- diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c index aed02d151..a944bda44 100644 --- a/shared/vg_replace_strmem.c +++ b/shared/vg_replace_strmem.c @@ -1856,10 +1856,44 @@ static inline void my_exit ( int x ) return NULL; \ } +#define MEMMEM_DARWIN(soname, fnname) \ + void* VG_REPLACE_FUNCTION_EZU(20460,soname,fnname) \ + (const void* big, SizeT big_len, const void* little, SizeT little_len); \ + void* VG_REPLACE_FUNCTION_EZU(20460,soname,fnname) \ + (const void* big, SizeT big_len, const void* little, SizeT little_len) \ + { \ + const HChar* h = big; \ + const HChar* n = little; \ + \ + if (big_len < little_len) return NULL; \ + if (little_len == 0) return NULL; \ + \ + HChar n0 = n[0]; \ + \ + for (; big_len >= little_len; big_len--, h++) { \ + if (h[0] != n0) continue; \ + \ + UWord i; \ + for (i = 1; i < little_len; i++) { \ + if (n[i] != h[i]) \ + break; \ + } \ + if (i == little_len) \ + return CONST_CAST(HChar *,h); \ + \ + } \ + return NULL; \ + } + + #if defined(VGP_s390x_linux) MEMMEM(VG_Z_LIBC_SONAME, memmem) #endif +#if defined(VGO_darwin) + MEMMEM_DARWIN(VG_Z_LIBSYSTEM_C_SONAME, memmem) +#endif + /*---------------------- strpbrk ----------------------*/