From: Grant Likely Date: Thu, 30 Aug 2007 08:00:57 -0600 Subject: [U-Boot-Users] [PATCH 1/2] Add memmem() library function In-Reply-To: <20070830135621.13233.26467.stgit@trillian.cg.shawcable.net> References: <20070830135621.13233.26467.stgit@trillian.cg.shawcable.net> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Gah! Ignore this patch; it's incorrect. I'll send the correct one shortly. g. On 8/30/07, Grant Likely wrote: > From: Grant Likely > > Signed-off-by: Grant Likely > --- > > include/linux/string.h | 3 +++ > lib_generic/string.c | 34 ++++++++++++++++++++++++++++++++++ > 2 files changed, 37 insertions(+), 0 deletions(-) > > diff --git a/include/linux/string.h b/include/linux/string.h > index 6239039..e18bcbf 100644 > --- a/include/linux/string.h > +++ b/include/linux/string.h > @@ -81,6 +81,9 @@ extern int memcmp(const void *,const void *,__kernel_size_t); > #ifndef __HAVE_ARCH_MEMCHR > extern void * memchr(const void *,int,__kernel_size_t); > #endif > +#ifndef __HAVE_ARCH_MEMMEM > +extern void * memmem(const void *,__kernel_size_t,const void *,__kernel_size_t); > +#endif > > #ifdef __cplusplus > } > diff --git a/lib_generic/string.c b/lib_generic/string.c > index e0b793a..8c699d9 100644 > --- a/lib_generic/string.c > +++ b/lib_generic/string.c > @@ -574,5 +574,39 @@ void *memchr(const void *s, int c, size_t n) > } > return NULL; > } > +#endif > + > +#ifndef __HAVE_ARCH_MEMMEM > +/** > + * memmem - Find a sequence in an area of memory > + * @a: The memory area > + * @len1: Size of the memory area > + * @b: The sequence to search for > + * @len2: Size of the sequence > + * > + * returns the address of the first occurrence of @b, or %NULL > + * if @b is not found > + */ > +static void *memmem (const void *m, size_t ml, const void *s, size_t sl) > +{ > + char * start = m; > + char * end = m + ml; > > + if (sl > ml) > + return NULL; > + > + while (start < end) > + { > + size_t len = sl; > + char * ptr1 = start; > + char * ptr2 = (char *)s; > + while (len > 0 && *ptr1++ == *ptr2++) > + len--; > + if (len == 0) > + return start; > + start++; > + } > + > + return NULL; > +} > #endif > > -- Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. grant.likely at secretlab.ca (403) 399-0195