[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] lib: move/rename strnicmp() to strncasecmp()
commit 3acd02a50b3b271284d2a37227c658b2cdae8231 Author: Jan Beulich <jbeulich@xxxxxxxx> AuthorDate: Thu Apr 22 14:51:47 2021 +0200 Commit: Jan Beulich <jbeulich@xxxxxxxx> CommitDate: Thu Apr 22 14:51:47 2021 +0200 lib: move/rename strnicmp() to strncasecmp() While moving the implementation, also rename it to match strcasecmp(), allowing the similar use of a compiler builtin in this case as well. Allow the function to be individually linkable, discardable, and overridable. Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> Acked-by: Julien Grall <jgrall@xxxxxxxxxx> --- xen/arch/arm/domain_build.c | 4 ++-- xen/common/string.c | 33 ------------------------------ xen/drivers/acpi/pmstat.c | 20 +++++++++--------- xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/string.h | 6 +++++- xen/lib/Makefile | 1 + xen/lib/strncasecmp.c | 47 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 47 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index b1d7b9849f..282416e74d 100644 --- 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(const struct dt_device_node *dev, * 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))); diff --git a/xen/common/string.c b/xen/common/string.c index 2b81daef89..f373f82171 100644 --- 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 diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 2f528f9ca3..1bae635101 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -275,14 +275,14 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) 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_sysctl_pm_op *op) { 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_sysctl_pm_op *op) { 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_sysctl_pm_op *op) { 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; diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index e630a47419..419aae83ee 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -111,7 +111,7 @@ struct cpufreq_governor *__find_governor(const char *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; diff --git a/xen/include/xen/string.h b/xen/include/xen/string.h index 4f438b018a..b4d2217a96 100644 --- a/xen/include/xen/string.h +++ b/xen/include/xen/string.h @@ -16,8 +16,8 @@ size_t strlcpy(char *, const char *, size_t); 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_t); #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 diff --git a/xen/lib/Makefile b/xen/lib/Makefile index 6264b3aae3..02240831e0 100644 --- 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 diff --git a/xen/lib/strncasecmp.c b/xen/lib/strncasecmp.c new file mode 100644 index 0000000000..407cf2a40e --- /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: + */ -- generated by git-patchbot for /home/xen/git/xen.git#staging
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |