Commit b1f17bf5ff63a7e22e0299dd576c3b6cd38ae665
Committed by
Tom Rini
1 parent
ec7381fbf6
Exists in
master
and in
54 other branches
Add strcasecmp() and strncasecmp()
strncasecmp() is present as strnicmp() but disabled. Make it available and define strcasecmp() also. There is a only a small performance penalty to having strcasecmp() call strncasecmp(), so do this instead of a standalone function, to save code space. Update the prototype in arch-specific headers as needed to avoid warnings. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 5 changed files with 20 additions and 9 deletions Side-by-side Diff
arch/m68k/include/asm/string.h
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | #endif |
17 | 17 | |
18 | 18 | extern int strcasecmp(const char *, const char *); |
19 | -extern int strncasecmp(const char *, const char *, int); | |
19 | +extern int strncasecmp(const char *, const char *, __kernel_size_t); | |
20 | 20 | extern char * strcpy(char *,const char *); |
21 | 21 | extern char * strncpy(char *,const char *, __kernel_size_t); |
22 | 22 | extern __kernel_size_t strlen(const char *); |
arch/powerpc/include/asm/string.h
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | #define __HAVE_ARCH_MEMCHR |
15 | 15 | |
16 | 16 | extern int strcasecmp(const char *, const char *); |
17 | -extern int strncasecmp(const char *, const char *, int); | |
17 | +extern int strncasecmp(const char *, const char *, __kernel_size_t); | |
18 | 18 | extern char * strcpy(char *,const char *); |
19 | 19 | extern char * strncpy(char *,const char *, __kernel_size_t); |
20 | 20 | extern __kernel_size_t strlen(const char *); |
arch/sparc/include/asm/string.h
... | ... | @@ -40,7 +40,7 @@ |
40 | 40 | */ |
41 | 41 | |
42 | 42 | extern int strcasecmp(const char *, const char *); |
43 | -extern int strncasecmp(const char *, const char *, int); | |
43 | +extern int strncasecmp(const char *, const char *, __kernel_size_t); | |
44 | 44 | extern char *strcpy(char *, const char *); |
45 | 45 | extern char *strncpy(char *, const char *, __kernel_size_t); |
46 | 46 | extern __kernel_size_t strlen(const char *); |
include/linux/string.h
... | ... | @@ -38,8 +38,11 @@ |
38 | 38 | #ifndef __HAVE_ARCH_STRNCMP |
39 | 39 | extern int strncmp(const char *,const char *,__kernel_size_t); |
40 | 40 | #endif |
41 | -#if 0 /* not used - was: #ifndef __HAVE_ARCH_STRNICMP */ | |
42 | -extern int strnicmp(const char *, const char *, __kernel_size_t); | |
41 | +#ifndef __HAVE_ARCH_STRCASECMP | |
42 | +int strcasecmp(const char *s1, const char *s2); | |
43 | +#endif | |
44 | +#ifndef __HAVE_ARCH_STRNCASECMP | |
45 | +extern int strncasecmp(const char *s1, const char *s2, __kernel_size_t len); | |
43 | 46 | #endif |
44 | 47 | #ifndef __HAVE_ARCH_STRCHR |
45 | 48 | extern char * strchr(const char *,int); |
lib/string.c
... | ... | @@ -21,14 +21,13 @@ |
21 | 21 | #include <malloc.h> |
22 | 22 | |
23 | 23 | |
24 | -#if 0 /* not used - was: #ifndef __HAVE_ARCH_STRNICMP */ | |
25 | 24 | /** |
26 | - * strnicmp - Case insensitive, length-limited string comparison | |
25 | + * strncasecmp - Case insensitive, length-limited string comparison | |
27 | 26 | * @s1: One string |
28 | 27 | * @s2: The other string |
29 | 28 | * @len: the maximum number of characters to compare |
30 | 29 | */ |
31 | -int strnicmp(const char *s1, const char *s2, size_t len) | |
30 | +int strncasecmp(const char *s1, const char *s2, size_t len) | |
32 | 31 | { |
33 | 32 | /* Yes, Virginia, it had better be unsigned */ |
34 | 33 | unsigned char c1, c2; |
... | ... | @@ -52,7 +51,16 @@ |
52 | 51 | } |
53 | 52 | return (int)c1 - (int)c2; |
54 | 53 | } |
55 | -#endif | |
54 | + | |
55 | +/** | |
56 | + * strcasecmp - Case insensitive string comparison | |
57 | + * @s1: One string | |
58 | + * @s2: The other string | |
59 | + */ | |
60 | +int strcasecmp(const char *s1, const char *s2) | |
61 | +{ | |
62 | + return strncasecmp(s1, s2, -1U); | |
63 | +} | |
56 | 64 | |
57 | 65 | char * ___strtok; |
58 | 66 |