1 /* 2 * Copyright (C) 2002 Manuel Novoa III 3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org> 4 * 5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 6 */ 7 8 #include "_string.h" 9 10 #ifdef __USE_GNU memmem(const void * haystack,size_t haystacklen,const void * needle,size_t needlelen)11void *memmem(const void *haystack, size_t haystacklen, 12 const void *needle, size_t needlelen) 13 { 14 register const char *ph; 15 register const char *pn; 16 const char *plast; 17 size_t n; 18 19 if (needlelen == 0) { 20 return (void *) haystack; 21 } 22 23 if (haystacklen >= needlelen) { 24 ph = (const char *) haystack; 25 pn = (const char *) needle; 26 plast = ph + (haystacklen - needlelen); 27 28 do { 29 n = 0; 30 while (ph[n] == pn[n]) { 31 if (++n == needlelen) { 32 return (void *) ph; 33 } 34 } 35 } while (++ph <= plast); 36 } 37 38 return NULL; 39 } 40 #endif 41