diff options
Diffstat (limited to 'lib/string.c')
-rw-r--r-- | lib/string.c | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/lib/string.c b/lib/string.c index 9f75b4ec50b8..f71bead1be3e 100644 --- a/lib/string.c +++ b/lib/string.c | |||
@@ -36,25 +36,21 @@ int strnicmp(const char *s1, const char *s2, size_t len) | |||
36 | /* Yes, Virginia, it had better be unsigned */ | 36 | /* Yes, Virginia, it had better be unsigned */ |
37 | unsigned char c1, c2; | 37 | unsigned char c1, c2; |
38 | 38 | ||
39 | c1 = c2 = 0; | 39 | if (!len) |
40 | if (len) { | 40 | return 0; |
41 | do { | 41 | |
42 | c1 = *s1; | 42 | do { |
43 | c2 = *s2; | 43 | c1 = *s1++; |
44 | s1++; | 44 | c2 = *s2++; |
45 | s2++; | 45 | if (!c1 || !c2) |
46 | if (!c1) | 46 | break; |
47 | break; | 47 | if (c1 == c2) |
48 | if (!c2) | 48 | continue; |
49 | break; | 49 | c1 = tolower(c1); |
50 | if (c1 == c2) | 50 | c2 = tolower(c2); |
51 | continue; | 51 | if (c1 != c2) |
52 | c1 = tolower(c1); | 52 | break; |
53 | c2 = tolower(c2); | 53 | } while (--len); |
54 | if (c1 != c2) | ||
55 | break; | ||
56 | } while (--len); | ||
57 | } | ||
58 | return (int)c1 - (int)c2; | 54 | return (int)c1 - (int)c2; |
59 | } | 55 | } |
60 | EXPORT_SYMBOL(strnicmp); | 56 | EXPORT_SYMBOL(strnicmp); |
@@ -667,7 +663,7 @@ EXPORT_SYMBOL(memscan); | |||
667 | */ | 663 | */ |
668 | char *strstr(const char *s1, const char *s2) | 664 | char *strstr(const char *s1, const char *s2) |
669 | { | 665 | { |
670 | int l1, l2; | 666 | size_t l1, l2; |
671 | 667 | ||
672 | l2 = strlen(s2); | 668 | l2 = strlen(s2); |
673 | if (!l2) | 669 | if (!l2) |
@@ -684,6 +680,31 @@ char *strstr(const char *s1, const char *s2) | |||
684 | EXPORT_SYMBOL(strstr); | 680 | EXPORT_SYMBOL(strstr); |
685 | #endif | 681 | #endif |
686 | 682 | ||
683 | #ifndef __HAVE_ARCH_STRNSTR | ||
684 | /** | ||
685 | * strnstr - Find the first substring in a length-limited string | ||
686 | * @s1: The string to be searched | ||
687 | * @s2: The string to search for | ||
688 | * @len: the maximum number of characters to search | ||
689 | */ | ||
690 | char *strnstr(const char *s1, const char *s2, size_t len) | ||
691 | { | ||
692 | size_t l2; | ||
693 | |||
694 | l2 = strlen(s2); | ||
695 | if (!l2) | ||
696 | return (char *)s1; | ||
697 | while (len >= l2) { | ||
698 | len--; | ||
699 | if (!memcmp(s1, s2, l2)) | ||
700 | return (char *)s1; | ||
701 | s1++; | ||
702 | } | ||
703 | return NULL; | ||
704 | } | ||
705 | EXPORT_SYMBOL(strnstr); | ||
706 | #endif | ||
707 | |||
687 | #ifndef __HAVE_ARCH_MEMCHR | 708 | #ifndef __HAVE_ARCH_MEMCHR |
688 | /** | 709 | /** |
689 | * memchr - Find a character in an area of memory. | 710 | * memchr - Find a character in an area of memory. |