From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: [RFC 06/24] xen: Add new string functions Date: Fri, 16 Aug 2013 22:05:38 +0100 Message-ID: <1376687156-6737-7-git-send-email-julien.grall@linaro.org> References: <1376687156-6737-1-git-send-email-julien.grall@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1376687156-6737-1-git-send-email-julien.grall@linaro.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com Cc: xen-devel@lists.xen.org, Julien Grall , andre.przywara@linaro.org, patches@linaro.org List-Id: xen-devel@lists.xenproject.org Add kbasename and strcasecmp. The code is copied from Linux. Signed-off-by: Julien Grall --- xen/common/string.c | 15 +++++++++++++++ xen/include/xen/string.h | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/xen/common/string.c b/xen/common/string.c index db9d9d5..9a5a4ba 100644 --- a/xen/common/string.c +++ b/xen/common/string.c @@ -41,6 +41,21 @@ int strnicmp(const char *s1, const char *s2, size_t len) } #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; +} +#endif + #ifndef __HAVE_ARCH_STRLCPY /** * strlcpy - Copy a %NUL terminated string into a sized buffer diff --git a/xen/include/xen/string.h b/xen/include/xen/string.h index f26b994..9b7511e 100644 --- a/xen/include/xen/string.h +++ b/xen/include/xen/string.h @@ -43,6 +43,9 @@ extern int strncmp(const char *,const char *,__kernel_size_t); #ifndef __HAVE_ARCH_STRNICMP extern int strnicmp(const char *, const char *, __kernel_size_t); #endif +#ifndef __HAVE_ARCH_STRCASECMP +extern int strcasecmp(const char *, const char *); +#endif #ifndef __HAVE_ARCH_STRCHR extern char * strchr(const char *,int); #endif @@ -94,4 +97,15 @@ extern void * memchr(const void *,int,__kernel_size_t); (strlcat(d, s, sizeof(d)) >= sizeof(d)); \ }) +/** + * kbasename - return the last part of a pathname. + * + * @path: path to extract the filename from. + */ +static inline const char *kbasename(const char *path) +{ + const char *tail = strrchr(path, '/'); + return tail ? tail + 1 : path; +} + #endif /* _LINUX_STRING_H_ */ -- 1.7.10.4