From: Roy Franz roy.franz@linaro.org
The shared efi-stub-helper.c functions require additional string helper functions compared to the base zImage. This patch adds strstr() and strncmp() implementations to the string.c file for the decompressor, with the implementation copied from lib/string.c.
Signed-off-by: Roy Franz roy.franz@linaro.org [Added strncmp, commit message update.] Signed-off-by: Leif Lindholm leif.lindholm@linaro.org Signed-off-by: Ard Biesheuvel ard.biesheuvel@linaro.org --- arch/arm/boot/compressed/string.c | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
diff --git a/arch/arm/boot/compressed/string.c b/arch/arm/boot/compressed/string.c index 36e53ef9200f..11392787086c 100644 --- a/arch/arm/boot/compressed/string.c +++ b/arch/arm/boot/compressed/string.c @@ -93,6 +93,28 @@ int strcmp(const char *cs, const char *ct) return res; }
+/** + * strncmp - Compare two length-limited strings + * @cs: One string + * @ct: Another string + * @count: The maximum number of bytes to compare + */ +int strncmp(const char *cs, const char *ct, size_t count) +{ + unsigned char c1, c2; + + while (count) { + c1 = *cs++; + c2 = *ct++; + if (c1 != c2) + return c1 < c2 ? -1 : 1; + if (!c1) + break; + count--; + } + return 0; +} + void *memchr(const void *s, int c, size_t count) { const unsigned char *p = s; @@ -111,6 +133,27 @@ char *strchr(const char *s, int c) return (char *)s; }
+/** + * strstr - Find the first substring in a %NUL terminated string + * @s1: The string to be searched + * @s2: The string to search for + */ +char *strstr(const char *s1, const char *s2) +{ + size_t l1, l2; + + l2 = strlen(s2); + if (!l2) + return (char *)s1; + l1 = strlen(s1); + while (l1 >= l2) { + l1--; + if (!memcmp(s1, s2, l2)) + return (char *)s1; + s1++; + } + return NULL; +} #undef memset
void *memset(void *s, int c, size_t count)