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>
master
Simon Glass 12 years ago committed by Tom Rini
parent ec7381fbf6
commit b1f17bf5ff
  1. 2
      arch/m68k/include/asm/string.h
  2. 2
      arch/powerpc/include/asm/string.h
  3. 2
      arch/sparc/include/asm/string.h
  4. 7
      include/linux/string.h
  5. 16
      lib/string.c

@ -16,7 +16,7 @@
#endif #endif
extern int strcasecmp(const char *, const char *); extern int strcasecmp(const char *, const char *);
extern int strncasecmp(const char *, const char *, int); extern int strncasecmp(const char *, const char *, __kernel_size_t);
extern char * strcpy(char *,const char *); extern char * strcpy(char *,const char *);
extern char * strncpy(char *,const char *, __kernel_size_t); extern char * strncpy(char *,const char *, __kernel_size_t);
extern __kernel_size_t strlen(const char *); extern __kernel_size_t strlen(const char *);

@ -14,7 +14,7 @@
#define __HAVE_ARCH_MEMCHR #define __HAVE_ARCH_MEMCHR
extern int strcasecmp(const char *, const char *); extern int strcasecmp(const char *, const char *);
extern int strncasecmp(const char *, const char *, int); extern int strncasecmp(const char *, const char *, __kernel_size_t);
extern char * strcpy(char *,const char *); extern char * strcpy(char *,const char *);
extern char * strncpy(char *,const char *, __kernel_size_t); extern char * strncpy(char *,const char *, __kernel_size_t);
extern __kernel_size_t strlen(const char *); extern __kernel_size_t strlen(const char *);

@ -40,7 +40,7 @@
*/ */
extern int strcasecmp(const char *, const char *); extern int strcasecmp(const char *, const char *);
extern int strncasecmp(const char *, const char *, int); extern int strncasecmp(const char *, const char *, __kernel_size_t);
extern char *strcpy(char *, const char *); extern char *strcpy(char *, const char *);
extern char *strncpy(char *, const char *, __kernel_size_t); extern char *strncpy(char *, const char *, __kernel_size_t);
extern __kernel_size_t strlen(const char *); extern __kernel_size_t strlen(const char *);

@ -38,8 +38,11 @@ extern int strcmp(const char *,const char *);
#ifndef __HAVE_ARCH_STRNCMP #ifndef __HAVE_ARCH_STRNCMP
extern int strncmp(const char *,const char *,__kernel_size_t); extern int strncmp(const char *,const char *,__kernel_size_t);
#endif #endif
#if 0 /* not used - was: #ifndef __HAVE_ARCH_STRNICMP */ #ifndef __HAVE_ARCH_STRCASECMP
extern int strnicmp(const char *, const char *, __kernel_size_t); int strcasecmp(const char *s1, const char *s2);
#endif
#ifndef __HAVE_ARCH_STRNCASECMP
extern int strncasecmp(const char *s1, const char *s2, __kernel_size_t len);
#endif #endif
#ifndef __HAVE_ARCH_STRCHR #ifndef __HAVE_ARCH_STRCHR
extern char * strchr(const char *,int); extern char * strchr(const char *,int);

@ -21,14 +21,13 @@
#include <malloc.h> #include <malloc.h>
#if 0 /* not used - was: #ifndef __HAVE_ARCH_STRNICMP */
/** /**
* strnicmp - Case insensitive, length-limited string comparison * strncasecmp - Case insensitive, length-limited string comparison
* @s1: One string * @s1: One string
* @s2: The other string * @s2: The other string
* @len: the maximum number of characters to compare * @len: the maximum number of characters to compare
*/ */
int strnicmp(const char *s1, const char *s2, size_t len) int strncasecmp(const char *s1, const char *s2, size_t len)
{ {
/* Yes, Virginia, it had better be unsigned */ /* Yes, Virginia, it had better be unsigned */
unsigned char c1, c2; unsigned char c1, c2;
@ -52,7 +51,16 @@ int strnicmp(const char *s1, const char *s2, size_t len)
} }
return (int)c1 - (int)c2; return (int)c1 - (int)c2;
} }
#endif
/**
* strcasecmp - Case insensitive string comparison
* @s1: One string
* @s2: The other string
*/
int strcasecmp(const char *s1, const char *s2)
{
return strncasecmp(s1, s2, -1U);
}
char * ___strtok; char * ___strtok;

Loading…
Cancel
Save