mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] lib: string: remove duplicated function
@ 2023-03-16  7:36 Denis Orlov
  2023-03-16  8:41 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Orlov @ 2023-03-16  7:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Denis Orlov

We have two functions that are doing the same thing: 'strncasecmp' and
'strnicmp'. The only difference between them is that the latter is
correctly handling the len argument of 0. So rename it into the former
one ('strncasecmp', as it is the POSIX name for this function), deleting
the other implementation. As no one is actually using 'strnicmp', no
other code requires any fixes.

This change is effectively forwarded from the Linux commits
'lib/string.c: remove duplicated function'
(hash cd514e727b18ff4d189b8e268db13729a4175091) and
'lib/string.c: remove strnicmp()'
(hash af3cd13501eb04ca61d017ff4406f1cbffafdc04).

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 include/linux/string.h |  3 ---
 lib/string.c           | 48 +++++++++++++++---------------------------
 2 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/include/linux/string.h b/include/linux/string.h
index 0c79d3e5cf..cd81ab1396 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -58,9 +58,6 @@ extern int strcmp(const char *,const char *);
 #ifndef __HAVE_ARCH_STRNCMP
 extern int strncmp(const char *,const char *,__kernel_size_t);
 #endif
-#ifndef __HAVE_ARCH_STRNICMP
-extern int strnicmp(const char *, const char *, __kernel_size_t);
-#endif
 #ifndef __HAVE_ARCH_STRCASECMP
 extern int strcasecmp(const char *s1, const char *s2);
 #endif
diff --git a/lib/string.c b/lib/string.c
index 005f4532bb..8ea68044cc 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -24,14 +24,28 @@
 #include <linux/ctype.h>
 #include <malloc.h>
 
-#ifndef __HAVE_ARCH_STRNICMP
+#ifndef __HAVE_ARCH_STRCASECMP
+int strcasecmp(const char *s1, const char *s2)
+{
+	int c1, c2;
+
+	do {
+		c1 = tolower(*s1++);
+		c2 = tolower(*s2++);
+	} while (c1 == c2 && c1 != 0);
+	return c1 - c2;
+}
+EXPORT_SYMBOL(strcasecmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRNCASECMP
 /**
- * strnicmp - Case insensitive, length-limited string comparison
+ * strncasecmp - Case insensitive, length-limited string comparison
  * @s1: One string
  * @s2: The other string
  * @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 */
 	unsigned char c1, c2;
@@ -53,34 +67,6 @@ int strnicmp(const char *s1, const char *s2, size_t len)
 	} while (--len);
 	return (int)c1 - (int)c2;
 }
-EXPORT_SYMBOL(strnicmp);
-#endif
-
-#ifndef __HAVE_ARCH_STRCASECMP
-int strcasecmp(const char *s1, const char *s2)
-{
-	int c1, c2;
-
-	do {
-		c1 = tolower(*s1++);
-		c2 = tolower(*s2++);
-	} while (c1 == c2 && c1 != 0);
-	return c1 - c2;
-}
-EXPORT_SYMBOL(strcasecmp);
-#endif
-
-#ifndef __HAVE_ARCH_STRNCASECMP
-int strncasecmp(const char *s1, const char *s2, size_t n)
-{
-	int c1, c2;
-
-	do {
-		c1 = tolower(*s1++);
-		c2 = tolower(*s2++);
-	} while ((--n > 0) && c1 == c2 && c1 != 0);
-	return c1 - c2;
-}
 EXPORT_SYMBOL(strncasecmp);
 #endif
 
-- 
2.30.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib: string: remove duplicated function
  2023-03-16  7:36 [PATCH] lib: string: remove duplicated function Denis Orlov
@ 2023-03-16  8:41 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-03-16  8:41 UTC (permalink / raw)
  To: Denis Orlov; +Cc: barebox, Ahmad Fatoum

On Thu, Mar 16, 2023 at 10:36:50AM +0300, Denis Orlov wrote:
> We have two functions that are doing the same thing: 'strncasecmp' and
> 'strnicmp'. The only difference between them is that the latter is
> correctly handling the len argument of 0. So rename it into the former
> one ('strncasecmp', as it is the POSIX name for this function), deleting
> the other implementation. As no one is actually using 'strnicmp', no
> other code requires any fixes.
> 
> This change is effectively forwarded from the Linux commits
> 'lib/string.c: remove duplicated function'
> (hash cd514e727b18ff4d189b8e268db13729a4175091) and
> 'lib/string.c: remove strnicmp()'
> (hash af3cd13501eb04ca61d017ff4406f1cbffafdc04).
> 
> Signed-off-by: Denis Orlov <denorl2009@gmail.com>
> ---
>  include/linux/string.h |  3 ---
>  lib/string.c           | 48 +++++++++++++++---------------------------
>  2 files changed, 17 insertions(+), 34 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 0c79d3e5cf..cd81ab1396 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -58,9 +58,6 @@ extern int strcmp(const char *,const char *);
>  #ifndef __HAVE_ARCH_STRNCMP
>  extern int strncmp(const char *,const char *,__kernel_size_t);
>  #endif
> -#ifndef __HAVE_ARCH_STRNICMP
> -extern int strnicmp(const char *, const char *, __kernel_size_t);
> -#endif
>  #ifndef __HAVE_ARCH_STRCASECMP
>  extern int strcasecmp(const char *s1, const char *s2);
>  #endif
> diff --git a/lib/string.c b/lib/string.c
> index 005f4532bb..8ea68044cc 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -24,14 +24,28 @@
>  #include <linux/ctype.h>
>  #include <malloc.h>
>  
> -#ifndef __HAVE_ARCH_STRNICMP
> +#ifndef __HAVE_ARCH_STRCASECMP
> +int strcasecmp(const char *s1, const char *s2)
> +{
> +	int c1, c2;
> +
> +	do {
> +		c1 = tolower(*s1++);
> +		c2 = tolower(*s2++);
> +	} while (c1 == c2 && c1 != 0);
> +	return c1 - c2;
> +}
> +EXPORT_SYMBOL(strcasecmp);
> +#endif
> +
> +#ifndef __HAVE_ARCH_STRNCASECMP
>  /**
> - * strnicmp - Case insensitive, length-limited string comparison
> + * strncasecmp - Case insensitive, length-limited string comparison
>   * @s1: One string
>   * @s2: The other string
>   * @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 */
>  	unsigned char c1, c2;
> @@ -53,34 +67,6 @@ int strnicmp(const char *s1, const char *s2, size_t len)
>  	} while (--len);
>  	return (int)c1 - (int)c2;
>  }
> -EXPORT_SYMBOL(strnicmp);
> -#endif
> -
> -#ifndef __HAVE_ARCH_STRCASECMP
> -int strcasecmp(const char *s1, const char *s2)
> -{
> -	int c1, c2;
> -
> -	do {
> -		c1 = tolower(*s1++);
> -		c2 = tolower(*s2++);
> -	} while (c1 == c2 && c1 != 0);
> -	return c1 - c2;
> -}
> -EXPORT_SYMBOL(strcasecmp);
> -#endif
> -
> -#ifndef __HAVE_ARCH_STRNCASECMP
> -int strncasecmp(const char *s1, const char *s2, size_t n)
> -{
> -	int c1, c2;
> -
> -	do {
> -		c1 = tolower(*s1++);
> -		c2 = tolower(*s2++);
> -	} while ((--n > 0) && c1 == c2 && c1 != 0);
> -	return c1 - c2;
> -}
>  EXPORT_SYMBOL(strncasecmp);
>  #endif
>  
> -- 
> 2.30.2
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-16  8:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16  7:36 [PATCH] lib: string: remove duplicated function Denis Orlov
2023-03-16  8:41 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox