diff options
author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2014-10-13 18:54:25 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-13 20:18:23 -0400 |
commit | cd514e727b18ff4d189b8e268db13729a4175091 (patch) | |
tree | fd860bbdc5e6e7d884196bccabbfd4d42240e116 /lib/string.c | |
parent | e48510f45107613bf14060eeabd658c49a044242 (diff) |
lib/string.c: remove duplicated function
lib/string.c contains two functions, strnicmp and strncasecmp, which do
roughly the same thing, namely compare two strings case-insensitively up
to a given bound. They have slightly different implementations, but the
only important difference is that strncasecmp doesn't handle len==0
appropriately; it effectively becomes strcasecmp in that case. strnicmp
correctly says that two strings are always equal in their first 0
characters.
strncasecmp is the POSIX name for this functionality. So rename the
non-broken function to the standard name. To minimize the impact on the
rest of the kernel (and since both are exported to modules), make strnicmp
a wrapper for strncasecmp.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "H. Peter Anvin" <hpa@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/string.c')
-rw-r--r-- | lib/string.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/string.c b/lib/string.c index f3c6ff596414..3181e267a033 100644 --- a/lib/string.c +++ b/lib/string.c | |||
@@ -27,14 +27,14 @@ | |||
27 | #include <linux/bug.h> | 27 | #include <linux/bug.h> |
28 | #include <linux/errno.h> | 28 | #include <linux/errno.h> |
29 | 29 | ||
30 | #ifndef __HAVE_ARCH_STRNICMP | 30 | #ifndef __HAVE_ARCH_STRNCASECMP |
31 | /** | 31 | /** |
32 | * strnicmp - Case insensitive, length-limited string comparison | 32 | * strncasecmp - Case insensitive, length-limited string comparison |
33 | * @s1: One string | 33 | * @s1: One string |
34 | * @s2: The other string | 34 | * @s2: The other string |
35 | * @len: the maximum number of characters to compare | 35 | * @len: the maximum number of characters to compare |
36 | */ | 36 | */ |
37 | int strnicmp(const char *s1, const char *s2, size_t len) | 37 | int strncasecmp(const char *s1, const char *s2, size_t len) |
38 | { | 38 | { |
39 | /* Yes, Virginia, it had better be unsigned */ | 39 | /* Yes, Virginia, it had better be unsigned */ |
40 | unsigned char c1, c2; | 40 | unsigned char c1, c2; |
@@ -56,6 +56,13 @@ int strnicmp(const char *s1, const char *s2, size_t len) | |||
56 | } while (--len); | 56 | } while (--len); |
57 | return (int)c1 - (int)c2; | 57 | return (int)c1 - (int)c2; |
58 | } | 58 | } |
59 | EXPORT_SYMBOL(strncasecmp); | ||
60 | #endif | ||
61 | #ifndef __HAVE_ARCH_STRNICMP | ||
62 | int strnicmp(const char *s1, const char *s2, size_t len) | ||
63 | { | ||
64 | return strncasecmp(s1, s2, len); | ||
65 | } | ||
59 | EXPORT_SYMBOL(strnicmp); | 66 | EXPORT_SYMBOL(strnicmp); |
60 | #endif | 67 | #endif |
61 | 68 | ||
@@ -73,20 +80,6 @@ int strcasecmp(const char *s1, const char *s2) | |||
73 | EXPORT_SYMBOL(strcasecmp); | 80 | EXPORT_SYMBOL(strcasecmp); |
74 | #endif | 81 | #endif |
75 | 82 | ||
76 | #ifndef __HAVE_ARCH_STRNCASECMP | ||
77 | int strncasecmp(const char *s1, const char *s2, size_t n) | ||
78 | { | ||
79 | int c1, c2; | ||
80 | |||
81 | do { | ||
82 | c1 = tolower(*s1++); | ||
83 | c2 = tolower(*s2++); | ||
84 | } while ((--n > 0) && c1 == c2 && c1 != 0); | ||
85 | return c1 - c2; | ||
86 | } | ||
87 | EXPORT_SYMBOL(strncasecmp); | ||
88 | #endif | ||
89 | |||
90 | #ifndef __HAVE_ARCH_STRCPY | 83 | #ifndef __HAVE_ARCH_STRCPY |
91 | /** | 84 | /** |
92 | * strcpy - Copy a %NUL terminated string | 85 | * strcpy - Copy a %NUL terminated string |