[U-Boot-Users] [PATCH 1/2] Add memmem() library function

From: Grant Likely grant.likely@secretlab.ca
Signed-off-by: Grant Likely grant.likely@secretlab.ca ---
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

Gah! Ignore this patch; it's incorrect.
I'll send the correct one shortly.
g.
On 8/30/07, Grant Likely grant.likely@secretlab.ca wrote:
From: Grant Likely grant.likely@secretlab.ca
Signed-off-by: Grant Likely grant.likely@secretlab.ca
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
participants (1)
-
Grant Likely