Patchwork [U-Boot,v2,09/23] Add stricmp() and strnicmp()

login
register
mail settings
Submitter Simon Glass
Date Nov. 22, 2012, 7:12 p.m.
Message ID <1353611587-18186-10-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/201139/
State Superseded, archived
Headers show

Comments

Simon Glass - Nov. 22, 2012, 7:12 p.m.
strnicmp() is present but disabled. Make it available and define stricmp()
also. There is a only a small performance penalty to having stricmp()
call strnicmp(), so do this instead of a standalone function, to save code
space.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v2:
- Add stricmp() patch again since it is used in this series

 include/linux/string.h |    4 ++++
 lib/string.c           |   12 ++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
Scott Wood - Nov. 27, 2012, 10:12 p.m.
On 11/22/2012 01:12:53 PM, Simon Glass wrote:
> strnicmp() is present but disabled. Make it available and define  
> stricmp()
> also. There is a only a small performance penalty to having stricmp()
> call strnicmp(), so do this instead of a standalone function, to save  
> code
> space.

Both POSIX and the Linux kernel call this strcasecmp() rather than  
stricmp()...

-Scott
Simon Glass - Dec. 1, 2012, 3:38 p.m.
Hi Scott,

On Tue, Nov 27, 2012 at 2:12 PM, Scott Wood <scottwood@freescale.com> wrote:
> On 11/22/2012 01:12:53 PM, Simon Glass wrote:
>>
>> strnicmp() is present but disabled. Make it available and define stricmp()
>> also. There is a only a small performance penalty to having stricmp()
>> call strnicmp(), so do this instead of a standalone function, to save code
>> space.
>
>
> Both POSIX and the Linux kernel call this strcasecmp() rather than
> stricmp()...
>

Yes, I will fix this. I will also need to tidy up a few prototypes in
other archs.

Regards,
Simon

> -Scott

Patch

diff --git a/include/linux/string.h b/include/linux/string.h
index 9a8cbc2..77fd1e9 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -20,6 +20,10 @@  extern __kernel_size_t strspn(const char *,const char *);
  */
 #include <asm/string.h>
 
+int strnicmp(const char *s1, const char *s2, size_t len);
+
+int stricmp(const char *s1, const char *s2);
+
 #ifndef __HAVE_ARCH_STRCPY
 extern char * strcpy(char *,const char *);
 #endif
diff --git a/lib/string.c b/lib/string.c
index c3ad055..f73df3f 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -21,7 +21,6 @@ 
 #include <malloc.h>
 
 
-#if 0 /* not used - was: #ifndef __HAVE_ARCH_STRNICMP */
 /**
  * strnicmp - Case insensitive, length-limited string comparison
  * @s1: One string
@@ -52,7 +51,16 @@  int strnicmp(const char *s1, const char *s2, size_t len)
 	}
 	return (int)c1 - (int)c2;
 }
-#endif
+
+/**
+ * stricmp - Case insensitive string comparison
+ * @s1: One string
+ * @s2: The other string
+ */
+int stricmp(const char *s1, const char *s2)
+{
+	return strnicmp(s1, s2, -1U);
+}
 
 char * ___strtok;