From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
Ian Jackson <iwj@xenproject.org>, Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>
Subject: [PATCH v2 17/20] lib: move/rename strnicmp() to strncasecmp()
Date: Wed, 21 Apr 2021 16:25:46 +0200 [thread overview]
Message-ID: <1fab1400-9bb5-f9e8-0f7f-3213afc0ad92@suse.com> (raw)
In-Reply-To: <3ae091ce-6f6c-3ec6-abd3-4490239a707f@suse.com>
While moving the implementation, also rename it to match strcasecmp(),
allowing the similar use of a compiler builting in this case as well.
Allow the function to be individually linkable, discardable, and
overridable.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1224,8 +1224,8 @@ static int __init map_range_to_domain(co
* They are not MMIO and therefore a domain should not be able to
* manage them via the IOMEM interface.
*/
- if ( strnicmp(dt_node_full_name(dev), "/reserved-memory/",
- strlen("/reserved-memory/")) != 0 )
+ if ( strncasecmp(dt_node_full_name(dev), "/reserved-memory/",
+ strlen("/reserved-memory/")) != 0 )
{
res = iomem_permit_access(d, paddr_to_pfn(addr),
paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
--- a/xen/common/string.c
+++ b/xen/common/string.c
@@ -8,39 +8,6 @@
#include <xen/string.h>
#include <xen/ctype.h>
-#ifndef __HAVE_ARCH_STRNICMP
-/**
- * strnicmp - 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)
-{
- /* Yes, Virginia, it had better be unsigned */
- unsigned char c1, c2;
-
- c1 = 0; c2 = 0;
- if (len) {
- do {
- c1 = *s1; c2 = *s2;
- s1++; s2++;
- if (!c1)
- break;
- if (!c2)
- break;
- if (c1 == c2)
- continue;
- c1 = tolower(c1);
- c2 = tolower(c2);
- if (c1 != c2)
- break;
- } while (--len);
- }
- return (int)c1 - (int)c2;
-}
-#endif
-
#ifndef __HAVE_ARCH_STRSPN
/**
* strspn - Calculate the length of the initial substring of @s which only
--- a/xen/drivers/acpi/pmstat.c
+++ b/xen/drivers/acpi/pmstat.c
@@ -275,14 +275,14 @@ static int get_cpufreq_para(struct xen_s
strlcpy(op->u.get_para.scaling_governor, "Unknown", CPUFREQ_NAME_LEN);
/* governor specific para */
- if ( !strnicmp(op->u.get_para.scaling_governor,
- "userspace", CPUFREQ_NAME_LEN) )
+ if ( !strncasecmp(op->u.get_para.scaling_governor,
+ "userspace", CPUFREQ_NAME_LEN) )
{
op->u.get_para.u.userspace.scaling_setspeed = policy->cur;
}
- if ( !strnicmp(op->u.get_para.scaling_governor,
- "ondemand", CPUFREQ_NAME_LEN) )
+ if ( !strncasecmp(op->u.get_para.scaling_governor,
+ "ondemand", CPUFREQ_NAME_LEN) )
{
ret = get_cpufreq_ondemand_para(
&op->u.get_para.u.ondemand.sampling_rate_max,
@@ -350,8 +350,8 @@ static int set_cpufreq_para(struct xen_s
{
unsigned int freq =op->u.set_para.ctrl_value;
- if ( !strnicmp(policy->governor->name,
- "userspace", CPUFREQ_NAME_LEN) )
+ if ( !strncasecmp(policy->governor->name,
+ "userspace", CPUFREQ_NAME_LEN) )
ret = write_userspace_scaling_setspeed(op->cpuid, freq);
else
ret = -EINVAL;
@@ -363,8 +363,8 @@ static int set_cpufreq_para(struct xen_s
{
unsigned int sampling_rate = op->u.set_para.ctrl_value;
- if ( !strnicmp(policy->governor->name,
- "ondemand", CPUFREQ_NAME_LEN) )
+ if ( !strncasecmp(policy->governor->name,
+ "ondemand", CPUFREQ_NAME_LEN) )
ret = write_ondemand_sampling_rate(sampling_rate);
else
ret = -EINVAL;
@@ -376,8 +376,8 @@ static int set_cpufreq_para(struct xen_s
{
unsigned int up_threshold = op->u.set_para.ctrl_value;
- if ( !strnicmp(policy->governor->name,
- "ondemand", CPUFREQ_NAME_LEN) )
+ if ( !strncasecmp(policy->governor->name,
+ "ondemand", CPUFREQ_NAME_LEN) )
ret = write_ondemand_up_threshold(up_threshold);
else
ret = -EINVAL;
--- a/xen/drivers/cpufreq/cpufreq.c
+++ b/xen/drivers/cpufreq/cpufreq.c
@@ -111,7 +111,7 @@ struct cpufreq_governor *__find_governor
return NULL;
list_for_each_entry(t, &cpufreq_governor_list, governor_list)
- if (!strnicmp(governor, t->name, CPUFREQ_NAME_LEN))
+ if (!strncasecmp(governor, t->name, CPUFREQ_NAME_LEN))
return t;
return NULL;
--- a/xen/include/xen/string.h
+++ b/xen/include/xen/string.h
@@ -16,8 +16,8 @@ size_t strlcpy(char *, const char *, siz
size_t strlcat(char *, const char *, size_t);
int strcmp(const char *, const char *);
int strncmp(const char *, const char *, size_t);
-int strnicmp(const char *, const char *, size_t);
int strcasecmp(const char *, const char *);
+int strncasecmp(const char *, const char *, size_t);
char *strchr(const char *, int);
char *strrchr(const char *, int);
char *strstr(const char *, const char *);
@@ -48,6 +48,10 @@ void *memchr_inv(const void *, int, size
#define strcasecmp(s1, s2) __builtin_strcasecmp(s1, s2)
#endif
+#ifndef __HAVE_ARCH_STRCASECMP
+#define strncasecmp(s1, s2, n) __builtin_strncasecmp(s1, s2, n)
+#endif
+
#ifndef __HAVE_ARCH_STRCHR
#define strchr(s1, c) __builtin_strchr(s1, c)
#endif
--- a/xen/lib/Makefile
+++ b/xen/lib/Makefile
@@ -20,6 +20,7 @@ lib-y += strcmp.o
lib-y += strlcat.o
lib-y += strlcpy.o
lib-y += strlen.o
+lib-y += strncasecmp.o
lib-y += strncmp.o
lib-y += strnlen.o
lib-y += strrchr.o
--- /dev/null
+++ b/xen/lib/strncasecmp.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 1991, 1992 Linus Torvalds
+ */
+
+#include <xen/string.h>
+#include <xen/ctype.h>
+
+/**
+ * strncasecmp - Case insensitive, length-limited string comparison
+ * @s1: One string
+ * @s2: The other string
+ * @len: the maximum number of characters to compare
+ */
+int (strncasecmp)(const char *s1, const char *s2, size_t len)
+{
+ /* Yes, Virginia, it had better be unsigned */
+ unsigned char c1, c2;
+
+ c1 = 0; c2 = 0;
+ if (len) {
+ do {
+ c1 = *s1; c2 = *s2;
+ s1++; s2++;
+ if (!c1)
+ break;
+ if (!c2)
+ break;
+ if (c1 == c2)
+ continue;
+ c1 = tolower(c1);
+ c2 = tolower(c2);
+ if (c1 != c2)
+ break;
+ } while (--len);
+ }
+ return (int)c1 - (int)c2;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ */
next prev parent reply other threads:[~2021-04-21 14:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-21 14:15 [PATCH v2 00/20] further population of xen/lib/ Jan Beulich
2021-04-21 14:18 ` [PATCH v2 01/20] lib: move memset() Jan Beulich
2021-04-21 14:18 ` [PATCH v2 02/20] lib: move memcpy() Jan Beulich
2021-04-21 14:19 ` [PATCH v2 03/20] lib: move memmove() Jan Beulich
2021-04-21 14:19 ` [PATCH v2 04/20] lib: move memcmp() Jan Beulich
2021-04-21 14:20 ` [PATCH v2 05/20] lib: move memchr() Jan Beulich
2021-04-21 14:20 ` [PATCH v2 06/20] lib: move memchr_inv() Jan Beulich
2021-04-21 14:22 ` [PATCH v2 07/20] lib: move strlen() Jan Beulich
2021-04-21 14:22 ` [PATCH v2 08/20] lib: move strnlen() Jan Beulich
2021-04-21 14:22 ` [PATCH v2 09/20] lib: move strcmp() Jan Beulich
2021-04-21 14:23 ` [PATCH v2 10/20] lib: move strncmp() Jan Beulich
2021-04-21 14:23 ` [PATCH v2 11/20] lib: move strlcpy() Jan Beulich
2021-04-21 14:24 ` [PATCH v2 12/20] lib: move strlcat() Jan Beulich
2021-04-21 14:24 ` [PATCH v2 13/20] lib: move strchr() Jan Beulich
2021-04-21 14:24 ` [PATCH v2 14/20] lib: move strrchr() Jan Beulich
2021-04-21 14:25 ` [PATCH v2 15/20] lib: move strstr() Jan Beulich
2021-04-21 14:25 ` [PATCH v2 16/20] lib: move strcasecmp() Jan Beulich
2021-04-21 14:25 ` Jan Beulich [this message]
2021-04-21 19:20 ` [PATCH v2 17/20] lib: move/rename strnicmp() to strncasecmp() Julien Grall
2021-04-21 14:26 ` [PATCH v2 18/20] lib: move strspn() Jan Beulich
2021-04-21 14:26 ` [PATCH v2 19/20] lib: move strpbrk() Jan Beulich
2021-04-21 14:26 ` [PATCH v2 20/20] lib: move strsep() Jan Beulich
2021-04-21 19:21 ` [PATCH v2 00/20] further population of xen/lib/ Julien Grall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1fab1400-9bb5-f9e8-0f7f-3213afc0ad92@suse.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=iwj@xenproject.org \
--cc=julien@xen.org \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).