further population of xen/lib/
v2 cover further population of xen/lib/
This is to dissolve / move xen/common/string.c. One benefit of moving these functions into an archive is that we can drop some of the related __HAVE_ARCH_* #define-s: By living in an archive, the per-arch functions will preempt any loading of the respective functions (objects) from the archive. (Down the road we may want to move the per-arch functions into archives as well, at which point the per-arch archive(s) would need to be specified ahead of the common one(s) to the linker.)
The only change in v2 is adjustment to all of the commit messages.
01: lib: move memset()
02: lib: move memcpy()
03: lib: move memmove()
04: lib: move memcmp()
05: lib: move memchr()
06: lib: move memchr_inv()
07: lib: move strlen()
08: lib: move strnlen()
09: lib: move strcmp()
10: lib: move strncmp()
11: lib: move strlcpy()
12: lib: move strlcat()
13: lib: move strchr()
14: lib: move strrchr()
15: lib: move strstr()
16: lib: move strcasecmp()
17: lib: move/rename strnicmp() to strncasecmp()
18: lib: move strspn()
19: lib: move strpbrk()
20: lib: move strsep()
Jan
PATCH v2 1/20 lib: move memset()
By moving the function into an archive, x86 doesn't need to announce anymore that is has its own implementation - symbol resolution by the linker will now guarantee that the generic function remains unused, and the forwarding to the compiler built-in gets done by the common header anyway.
Allow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -20
@@ -311,26 +311,6 @@ char *(strstr)(const char *s1, const cha }#endif -#ifndef __HAVE_ARCH_MEMSET -/** -* memset - Fill a region of memory with the given value -* @s: Pointer to the start of the area. -* @c: The byte to fill the area with -* @count: The size of the area. -* -* Do not use memset() to access IO space, use memset_io() instead. -*/ -void *(memset)(void *s,int c,size_t count) -{ -char *xs = (char *) s; - -while (count--) - *xs++ = c; - -return s; -} -#endif -#ifndef __HAVE_ARCH_MEMCPY/** * memcpy - Copy one area of memory to another
xen/include/asm-x86/string.h +0 -3
@@ -7,9 +7,6 @@#define __HAVE_ARCH_MEMMOVE#define memmove (d, s, n) __builtin_memmove(d, s, n) -#define __HAVE_ARCH_MEMSET -#define memset (s, c, n) __builtin_memset(s, c, n) -#endif /* __X86_STRING_H__ */ /* * Local variables:
xen/lib/Makefile +1 -0
@@ -4,6 +4,7 @@ lib-y += bsearch.o lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o +lib-y += memset.o lib-y += muldiv64.o lib-y += parse-size.o lib-y += rbtree.o
xen/lib/memset.c new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* memset - Fill a region of memory with the given value +* @s: Pointer to the start of the area. +* @c: The byte to fill the area with +* @count: The size of the area. +* +* Do not use memset() to access IO space, use memset_io() instead. +*/ +void *(memset)(void *s,int c,size_t count) +{ +char *xs = (char *) s; + +while (count--) + *xs++ = c; + +return s; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 2/20 lib: move memcpy()
In reply to Jan BeulichBy moving the function into an archive, x86 doesn't need to announce anymore that is has its own implementation - symbol resolution by the linker will now guarantee that the generic function remains unused, and the forwarding to the compiler built-in gets done by the common header anyway.
Allow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -21
@@ -311,27 +311,6 @@ char *(strstr)(const char *s1, const cha }#endif -#ifndef __HAVE_ARCH_MEMCPY -/** -* memcpy - Copy one area of memory to another -* @dest: Where to copy to -* @src: Where to copy from -* @count: The size of the area. -* -* You should not use this function to access IO space, use memcpy_toio() -* or memcpy_fromio() instead. -*/ -void *(memcpy)(void *dest,const void *src,size_t count) -{ -char *tmp = (char *) dest, *s = (char *) src; - -while (count--) - *tmp++ = *s++; - -return dest; -} -#endif -#ifndef __HAVE_ARCH_MEMMOVE/** * memmove - Copy one area of memory to another
xen/include/asm-x86/string.h +0 -3
@@ -1,9 +1,6 @@#ifndef __X86_STRING_H__#define __X86_STRING_H__ -#define __HAVE_ARCH_MEMCPY -#define memcpy (d, s, n) __builtin_memcpy(d, s, n) -#define __HAVE_ARCH_MEMMOVE#define memmove (d, s, n) __builtin_memmove(d, s, n)
xen/lib/Makefile +1 -0
@@ -4,6 +4,7 @@ lib-y += bsearch.o lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o +lib-y += memcpy.o lib-y += memset.o lib-y += muldiv64.o lib-y += parse-size.o
xen/lib/memcpy.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* memcpy - Copy one area of memory to another +* @dest: Where to copy to +* @src: Where to copy from +* @count: The size of the area. +* +* You should not use this function to access IO space, use memcpy_toio() +* or memcpy_fromio() instead. +*/ +void *(memcpy)(void *dest,const void *src,size_t count) +{ +char *tmp = (char *) dest, *s = (char *) src; + +while (count--) + *tmp++ = *s++; + +return dest; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 3/20 lib: move memmove()
In reply to Jan BeulichBy moving the function into an archive, x86 doesn't need to announce anymore that is has its own implementation - symbol resolution by the linker will now guarantee that the generic function remains unused, and the forwarding to the compiler built-in gets done by the common header anyway.
Allow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -30
@@ -311,36 +311,6 @@ char *(strstr)(const char *s1, const cha }#endif -#ifndef __HAVE_ARCH_MEMMOVE -/** -* memmove - Copy one area of memory to another -* @dest: Where to copy to -* @src: Where to copy from -* @count: The size of the area. -* -* Unlike memcpy(), memmove() copes with overlapping areas. -*/ -void *(memmove)(void *dest,const void *src,size_t count) -{ -char *tmp, *s; - -if (dest <= src) { - tmp = (char *) dest; - s = (char *) src; -while (count--) - *tmp++ = *s++; - } -else { - tmp = (char *) dest + count; - s = (char *) src + count; -while (count--) - *--tmp = *--s; - } - -return dest; -} -#endif -#ifndef __HAVE_ARCH_MEMCMP/** * memcmp - Compare two areas of memory
xen/include/asm-x86/string.h +0 -3
@@ -1,9 +1,6 @@#ifndef __X86_STRING_H__#define __X86_STRING_H__ -#define __HAVE_ARCH_MEMMOVE -#define memmove (d, s, n) __builtin_memmove(d, s, n) -#endif /* __X86_STRING_H__ */ /* * Local variables:
xen/lib/Makefile +1 -0
@@ -5,6 +5,7 @@ lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o lib-y += memcpy.o +lib-y += memmove.o lib-y += memset.o lib-y += muldiv64.o lib-y += parse-size.o
xen/lib/memmove.c new file +42 -0
42 lines not on this page · raw message
PATCH v2 4/20 lib: move memcmp()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -19
@@ -311,25 +311,6 @@ char *(strstr)(const char *s1, const cha }#endif -#ifndef __HAVE_ARCH_MEMCMP -/** -* memcmp - Compare two areas of memory -* @cs: One area of memory -* @ct: Another area of memory -* @count: The size of the area. -*/ -int (memcmp)(const void *cs,const void *ct,size_t count) -{ -const unsigned char *su1, *su2; -int res =0 ; - -for ( su1 = cs, su2 = ct;0 < count; ++su1, ++su2, count--) -if ((res = *su1 - *su2) !=0 ) -break ; -return res; -} -#endif -#ifndef __HAVE_ARCH_MEMCHR/** * memchr - Find a character in an area of memory.
xen/lib/Makefile +1 -0
@@ -4,6 +4,7 @@ lib-y += bsearch.o lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o +lib-y += memcmp.o lib-y += memcpy.o lib-y += memmove.o lib-y += memset.o
xen/lib/memcmp.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* memcmp - Compare two areas of memory +* @cs: One area of memory +* @ct: Another area of memory +* @count: The size of the area. +*/ +int (memcmp)(const void *cs,const void *ct,size_t count) +{ +const unsigned char *su1, *su2; +int res =0 ; + +for ( su1 = cs, su2 = ct;0 < count; ++su1, ++su2, count--) +if ((res = *su1 - *su2) !=0 ) +break ; +return res; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 5/20 lib: move memchr()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -22
@@ -311,28 +311,6 @@ char *(strstr)(const char *s1, const cha }#endif -#ifndef __HAVE_ARCH_MEMCHR -/** -* memchr - Find a character in an area of memory. -* @s: The memory area -* @c: The byte to search for -* @n: The size of the area. -* -* returns the address of the first occurrence of @c, or %NULL -* if @c is not found -*/ -void *(memchr)(const void *s,int c,size_t n) -{ -const unsigned char *p = s; - -while (n--) -if ((unsigned char )c == *p++) -return (void *)(p -1 ); - -return NULL ; -} -#endif -/** * memchr_inv - Find an unmatching character in an area of memory. * @s: The memory area
xen/lib/Makefile +1 -0
@@ -4,6 +4,7 @@ lib-y += bsearch.o lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o +lib-y += memchr.o lib-y += memcmp.o lib-y += memcpy.o lib-y += memmove.o
xen/lib/memchr.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* memchr - Find a character in an area of memory. +* @s: The memory area +* @c: The byte to search for +* @n: The size of the area. +* +* returns the address of the first occurrence of @c, or %NULL +* if @c is not found +*/ +void *(memchr)(const void *s,int c,size_t n) +{ +const unsigned char *p = s; + +while (n--) +if ((unsigned char )c == *p++) +return (void *)(p -1 ); + +return NULL ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 6/20 lib: move memchr_inv()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -20
@@ -311,26 +311,6 @@ char *(strstr)(const char *s1, const cha }#endif -/** -* memchr_inv - Find an unmatching character in an area of memory. -* @s: The memory area -* @c: The byte that is expected -* @n: The size of the area. -* -* returns the address of the first occurrence of a character other than @c, -* or %NULL if the whole buffer contains just @c. -*/ -void *memchr_inv (const void *s,int c,size_t n) -{ -const unsigned char *p = s; - -while (n--) -if ((unsigned char )c != *p++) -return (void *)(p -1 ); - -return NULL ; -} -/* * Local variables: * mode: C
xen/lib/Makefile +1 -0
@@ -5,6 +5,7 @@ lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o lib-y += memchr.o +lib-y += memchr_inv.o lib-y += memcmp.o lib-y += memcpy.o lib-y += memmove.o
xen/lib/memchr_inv.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* memchr_inv - Find an unmatching character in an area of memory. +* @s: The memory area +* @c: The byte that is expected +* @n: The size of the area. +* +* returns the address of the first occurrence of a character other than @c, +* or %NULL if the whole buffer contains just @c. +*/ +void *memchr_inv (const void *s,int c,size_t n) +{ +const unsigned char *p = s; + +while (n--) +if ((unsigned char )c != *p++) +return (void *)(p -1 ); + +return NULL ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 7/20 lib: move strlen()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -15
@@ -184,21 +184,6 @@ char *(strrchr)(const char *s, int c) }#endif -#ifndef __HAVE_ARCH_STRLEN -/** -* strlen - Find the length of a string -* @s: The string to be sized -*/ -size_t (strlen)(const char * s) -{ -const char *sc; - -for (sc = s; *sc !='\0' ; ++sc) -/* nothing */ ; -return sc - s; -} -#endif -#ifndef __HAVE_ARCH_STRNLEN/** * strnlen - Find the length of a length-limited string
xen/lib/Makefile +1 -0
@@ -14,6 +14,7 @@ lib-y += muldiv64.o lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o +lib-y += strlen.o lib-$(CONFIG_X86) += xxhash32.o lib-$(CONFIG_X86) += xxhash64.o
xen/lib/strlen.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strlen - Find the length of a string +* @s: The string to be sized +*/ +size_t (strlen)(const char * s) +{ +const char *sc; + +for (sc = s; *sc !='\0' ; ++sc) +/* nothing */ ; +return sc - s; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 8/20 lib: move strnlen()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -16
@@ -184,22 +184,6 @@ char *(strrchr)(const char *s, int c) }#endif -#ifndef __HAVE_ARCH_STRNLEN -/** -* strnlen - Find the length of a length-limited string -* @s: The string to be sized -* @count: The maximum number of bytes to search -*/ -size_t strnlen (const char * s,size_t count) -{ -const char *sc; - -for (sc = s; count-- && *sc !='\0' ; ++sc) -/* nothing */ ; -return sc - s; -} -#endif -#ifndef __HAVE_ARCH_STRSPN/** * strspn - Calculate the length of the initial substring of @s which only
xen/lib/Makefile +1 -0
@@ -15,6 +15,7 @@ lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o lib-y += strlen.o +lib-y += strnlen.o lib-$(CONFIG_X86) += xxhash32.o lib-$(CONFIG_X86) += xxhash64.o
xen/lib/strnlen.c new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strnlen - Find the length of a length-limited string +* @s: The string to be sized +* @count: The maximum number of bytes to search +*/ +size_t strnlen (const char * s,size_t count) +{ +const char *sc; + +for (sc = s; count-- && *sc !='\0' ; ++sc) +/* nothing */ ; +return sc - s; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 9/20 lib: move strcmp()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -19
@@ -111,25 +111,6 @@ size_t strlcat(char *dest, const char *sEXPORT_SYMBOL (strlcat);#endif -#ifndef __HAVE_ARCH_STRCMP -/** -* strcmp - Compare two strings -* @cs: One string -* @ct: Another string -*/ -int (strcmp)(const char *cs,const char *ct) -{ - registersigned char __res; - -while (1 ) { -if ((__res = *cs - *ct++) !=0 || !*cs++) -break ; - } - -return __res; -} -#endif -#ifndef __HAVE_ARCH_STRNCMP/** * strncmp - Compare two length-limited strings
xen/lib/Makefile +1 -0
@@ -14,6 +14,7 @@ lib-y += muldiv64.o lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o +lib-y += strcmp.o lib-y += strlen.o lib-y += strnlen.o lib-$(CONFIG_X86) += xxhash32.o
xen/lib/strcmp.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strcmp - Compare two strings +* @cs: One string +* @ct: Another string +*/ +int (strcmp)(const char *cs,const char *ct) +{ + registersigned char __res; + +while (1 ) { +if ((__res = *cs - *ct++) !=0 || !*cs++) +break ; + } + +return __res; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 10/20 lib: move strncmp()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -21
@@ -111,27 +111,6 @@ size_t strlcat(char *dest, const char *sEXPORT_SYMBOL (strlcat);#endif -#ifndef __HAVE_ARCH_STRNCMP -/** -* strncmp - Compare two length-limited strings -* @cs: One string -* @ct: Another string -* @count: The maximum number of bytes to compare -*/ -int (strncmp)(const char *cs,const char *ct,size_t count) -{ - registersigned char __res =0 ; - -while (count) { -if ((__res = *cs - *ct++) !=0 || !*cs++) -break ; - count--; - } - -return __res; -} -#endif -#ifndef __HAVE_ARCH_STRCHR/** * strchr - Find the first occurrence of a character in a string
xen/lib/Makefile +1 -0
@@ -16,6 +16,7 @@ lib-y += rbtree.o lib-y += sort.o lib-y += strcmp.o lib-y += strlen.o +lib-y += strncmp.o lib-y += strnlen.o lib-$(CONFIG_X86) += xxhash32.o lib-$(CONFIG_X86) += xxhash64.o
xen/lib/strncmp.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strncmp - Compare two length-limited strings +* @cs: One string +* @ct: Another string +* @count: The maximum number of bytes to compare +*/ +int (strncmp)(const char *cs,const char *ct,size_t count) +{ + registersigned char __res =0 ; + +while (count) { +if ((__res = *cs - *ct++) !=0 || !*cs++) +break ; + count--; + } + +return __res; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 11/20 lib: move strlcpy()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -26
@@ -56,32 +56,6 @@ int (strcasecmp)(const char *s1, const c }#endif -#ifndef __HAVE_ARCH_STRLCPY -/** -* strlcpy - Copy a %NUL terminated string into a sized buffer -* @dest: Where to copy the string to -* @src: Where to copy the string from -* @size: size of destination buffer -* -* Compatible with *BSD: the result is always a valid -* NUL-terminated string that fits in the buffer (unless, -* of course, the buffer size is zero). It does not pad -* out the result like strncpy() does. -*/ -size_t strlcpy (char *dest,const char *src,size_t size) -{ -size_t ret =strlen (src); - -if (size) { -size_t len = (ret >= size) ? size-1 : ret; -memcpy (dest, src, len); - dest[len] ='\0' ; - } -return ret; -} -EXPORT_SYMBOL (strlcpy); -#endif -#ifndef __HAVE_ARCH_STRLCAT/** * strlcat - Append a %NUL terminated string into a sized buffer
xen/lib/Makefile +1 -0
@@ -15,6 +15,7 @@ lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o lib-y += strcmp.o +lib-y += strlcpy.o lib-y += strlen.o lib-y += strncmp.o lib-y += strnlen.o
xen/lib/strlcpy.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strlcpy - Copy a %NUL terminated string into a sized buffer +* @dest: Where to copy the string to +* @src: Where to copy the string from +* @size: size of destination buffer +* +* Compatible with *BSD: the result is always a valid +* NUL-terminated string that fits in the buffer (unless, +* of course, the buffer size is zero). It does not pad +* out the result like strncpy() does. +*/ +size_t strlcpy (char *dest,const char *src,size_t size) +{ +size_t ret =strlen (src); + +if (size) { +size_t len = (ret >= size) ? size-1 : ret; +memcpy (dest, src, len); + dest[len] ='\0' ; + } +return ret; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 12/20 lib: move strlcat()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -29
@@ -56,35 +56,6 @@ int (strcasecmp)(const char *s1, const c }#endif -#ifndef __HAVE_ARCH_STRLCAT -/** -* strlcat - Append a %NUL terminated string into a sized buffer -* @dest: Where to copy the string to -* @src: Where to copy the string from -* @size: size of destination buffer -* -* Compatible with *BSD: the result is always a valid -* NUL-terminated string that fits in the buffer (unless, -* of course, the buffer size is zero). -*/ -size_t strlcat (char *dest,const char *src,size_t size) -{ -size_t slen =strlen (src); -size_t dlen =strnlen (dest, size); -char *p = dest + dlen; - -while ((p - dest) < size) -if ((*p++ = *src++) =='\0' ) -break ; - -if (dlen < size) - *(p-1 ) ='\0' ; - -return slen + dlen; -} -EXPORT_SYMBOL (strlcat); -#endif -#ifndef __HAVE_ARCH_STRCHR/** * strchr - Find the first occurrence of a character in a string
xen/lib/Makefile +1 -0
@@ -15,6 +15,7 @@ lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o lib-y += strcmp.o +lib-y += strlcat.o lib-y += strlcpy.o lib-y += strlen.o lib-y += strncmp.o
xen/lib/strlcat.c new file +41 -0
41 lines not on this page · raw message
PATCH v2 13/20 lib: move strchr()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -15
@@ -56,21 +56,6 @@ int (strcasecmp)(const char *s1, const c }#endif -#ifndef __HAVE_ARCH_STRCHR -/** -* strchr - Find the first occurrence of a character in a string -* @s: The string to be searched -* @c: The character to search for -*/ -char *(strchr)(const char *s,int c) -{ -for (; *s != (char ) c; ++s) -if (*s =='\0' ) -return NULL ; -return (char *) s; -} -#endif -#ifndef __HAVE_ARCH_STRRCHR/** * strrchr - Find the last occurrence of a character in a string
xen/lib/Makefile +1 -0
@@ -14,6 +14,7 @@ lib-y += muldiv64.o lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o +lib-y += strchr.o lib-y += strcmp.o lib-y += strlcat.o lib-y += strlcpy.o
xen/lib/strchr.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strchr - Find the first occurrence of a character in a string +* @s: The string to be searched +* @c: The character to search for +*/ +char *(strchr)(const char *s,int c) +{ +for (; *s != (char ) c; ++s) +if (*s =='\0' ) +return NULL ; +return (char *) s; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 14/20 lib: move strrchr()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -18
@@ -56,24 +56,6 @@ int (strcasecmp)(const char *s1, const c }#endif -#ifndef __HAVE_ARCH_STRRCHR -/** -* strrchr - Find the last occurrence of a character in a string -* @s: The string to be searched -* @c: The character to search for -*/ -char *(strrchr)(const char *s,int c) -{ -const char *p = s +strlen (s); - -for (; *p != (char )c; --p) -if (p == s) -return NULL ; - -return (char *)p; -} -#endif -#ifndef __HAVE_ARCH_STRSPN/** * strspn - Calculate the length of the initial substring of @s which only
xen/lib/Makefile +1 -0
@@ -21,6 +21,7 @@ lib-y += strlcpy.o lib-y += strlen.o lib-y += strncmp.o lib-y += strnlen.o +lib-y += strrchr.o lib-$(CONFIG_X86) += xxhash32.o lib-$(CONFIG_X86) += xxhash64.o
xen/lib/strrchr.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strrchr - Find the last occurrence of a character in a string +* @s: The string to be searched +* @c: The character to search for +*/ +char *(strrchr)(const char *s,int c) +{ +const char *p = s +strlen (s); + +for (; *p != (char )c; --p) +if (p == s) +return NULL ; + +return (char *)p; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 15/20 lib: move strstr()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -21
@@ -131,27 +131,6 @@ char * strsep(char **s, const char *ct) }#endif -#ifndef __HAVE_ARCH_STRSTR -/** -* strstr - Find the first substring in a %NUL terminated string -* @s1: The string to be searched -* @s2: The string to search for -*/ -char *(strstr)(const char *s1,const char *s2) -{ -size_t l1, l2 =strlen (s2); - -if (!l2) -return (char *)s1; - -for (l1 =strlen (s1); l1 >= l2; --l1, ++s1) -if (!memcmp (s1, s2, l2)) -return (char *)s1; - -return NULL ; -} -#endif -/* * Local variables: * mode: C
xen/lib/Makefile +1 -0
@@ -22,6 +22,7 @@ lib-y += strlen.o lib-y += strncmp.o lib-y += strnlen.o lib-y += strrchr.o +lib-y += strstr.o lib-$(CONFIG_X86) += xxhash32.o lib-$(CONFIG_X86) += xxhash64.o
xen/lib/strstr.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strstr - Find the first substring in a %NUL terminated string +* @s1: The string to be searched +* @s2: The string to search for +*/ +char *(strstr)(const char *s1,const char *s2) +{ +size_t l1, l2 =strlen (s2); + +if (!l2) +return (char *)s1; + +for (l1 =strlen (s1); l1 >= l2; --l1, ++s1) +if (!memcmp (s1, s2, l2)) +return (char *)s1; + +return NULL ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 16/20 lib: move strcasecmp()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -15
@@ -41,21 +41,6 @@ int strnicmp(const char *s1, const char }#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_STRSPN/** * strspn - Calculate the length of the initial substring of @s which only
xen/lib/Makefile +1 -0
@@ -14,6 +14,7 @@ lib-y += muldiv64.o lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o +lib-y += strcasecmp.o lib-y += strchr.o lib-y += strcmp.o lib-y += strlcat.o
xen/lib/strcasecmp.c new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> +#include <xen/ctype.h> + +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; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 17/20 lib: move/rename strnicmp() to strncasecmp()
In reply to Jan BeulichWhile 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.
xen/arch/arm/domain_build.c +2 -2
@@ -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 )));
xen/common/string.c +0 -33
@@ -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
xen/drivers/acpi/pmstat.c +10 -10
@@ -275,14 +275,14 @@ static int get_cpufreq_para(struct xen_sstrlcpy (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 ;
xen/drivers/cpufreq/cpufreq.c +1 -1
@@ -111,7 +111,7 @@ struct cpufreq_governor *__find_governorreturn 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 ;
xen/include/xen/string.h +5 -1
@@ -16,8 +16,8 @@ size_t strlcpy(char *, const char *, sizsize_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
xen/lib/Makefile +1 -0
@@ -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
xen/lib/strncasecmp.c new file +47 -0
47 lines not on this page · raw message
Re: [PATCH v2 17/20] lib: move/rename strnicmp() to strncasecmp()
Hi Jan,
Quoted 2 lines · Jan Beulich
While moving the implementation, also rename it to match
strcasecmp(), allowing the similar use of a compiler builting in this case as well.
NIT: I think you meant builtin here.
Cheers,
Signature · 1 line
Julien Grall
PATCH v2 18/20 lib: move strspn()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable. In fact the function is unused at present, and hence will now get omitted from the final binaries.
xen/common/string.c +0 -27
@@ -8,33 +8,6 @@#include <xen/string.h> #include <xen/ctype.h> -#ifndef __HAVE_ARCH_STRSPN -/** -* strspn - Calculate the length of the initial substring of @s which only -* contain letters in @accept -* @s: The string to be searched -* @accept: The string to search for -*/ -size_t strspn (const char *s,const char *accept) -{ -const char *p; -const char *a; -size_t count =0 ; - -for (p = s; *p !='\0' ; ++p) { -for (a = accept; *a !='\0' ; ++a) { -if (*p == *a) -break ; - } -if (*a =='\0' ) -return count; - ++count; - } - -return count; -} -#endif -#ifndef __HAVE_ARCH_STRPBRK/** * strpbrk - Find the first occurrence of a set of characters
xen/lib/Makefile +1 -0
@@ -24,6 +24,7 @@ lib-y += strncasecmp.o lib-y += strncmp.o lib-y += strnlen.o lib-y += strrchr.o +lib-y += strspn.o lib-y += strstr.o lib-$(CONFIG_X86) += xxhash32.o lib-$(CONFIG_X86) += xxhash64.o
xen/lib/strspn.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strspn - Calculate the length of the initial substring of @s which only +* contain letters in @accept +* @s: The string to be searched +* @accept: The string to search for +*/ +size_t strspn (const char *s,const char *accept) +{ +const char *p; +const char *a; +size_t count =0 ; + +for (p = s; *p !='\0' ; ++p) { +for (a = accept; *a !='\0' ; ++a) { +if (*p == *a) +break ; + } +if (*a =='\0' ) +return count; + ++count; + } + +return count; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 19/20 lib: move strpbrk()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/string.c +0 -20
@@ -8,26 +8,6 @@#include <xen/string.h> #include <xen/ctype.h> -#ifndef __HAVE_ARCH_STRPBRK -/** -* strpbrk - Find the first occurrence of a set of characters -* @cs: The string to be searched -* @ct: The characters to search for -*/ -char *strpbrk (const char * cs,const char * ct) -{ -const char *sc1,*sc2; - -for ( sc1 = cs; *sc1 !='\0' ; ++sc1) { -for ( sc2 = ct; *sc2 !='\0' ; ++sc2) { -if (*sc1 == *sc2) -return (char *) sc1; - } - } -return NULL ; -} -#endif -#ifndef __HAVE_ARCH_STRSEP/** * strsep - Split a string into tokens
xen/lib/Makefile +1 -0
@@ -23,6 +23,7 @@ lib-y += strlen.o lib-y += strncasecmp.o lib-y += strncmp.o lib-y += strnlen.o +lib-y += strpbrk.o lib-y += strrchr.o lib-y += strspn.o lib-y += strstr.o
xen/lib/strpbrk.c new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strpbrk - Find the first occurrence of a set of characters +* @cs: The string to be searched +* @ct: The characters to search for +*/ +char *strpbrk (const char * cs,const char * ct) +{ +const char *sc1,*sc2; + +for ( sc1 = cs; *sc1 !='\0' ; ++sc1) { +for ( sc2 = ct; *sc2 !='\0' ; ++sc2) { +if (*sc1 == *sc2) +return (char *) sc1; + } + } +return NULL ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 8 +* tab-width: 8 +* indent-tabs-mode: t +* End: +*/
PATCH v2 20/20 lib: move strsep()
In reply to Jan BeulichAllow the function to be individually linkable, discardable, and overridable.
xen/common/Makefile +0 -1
@@ -40,7 +40,6 @@ obj-y += softirq.o obj-y += smp.o obj-y += spinlock.o obj-y += stop_machine.o -obj-y += string.o obj-y += symbols.o obj-y += tasklet.o obj-y += time.o
xen/common/string.c deleted +0 -47
47 lines not on this page · raw message
xen/lib/Makefile +1 -0
@@ -25,6 +25,7 @@ lib-y += strncmp.o lib-y += strnlen.o lib-y += strpbrk.o lib-y += strrchr.o +lib-y += strsep.o lib-y += strspn.o lib-y += strstr.o lib-$(CONFIG_X86) += xxhash32.o
xen/lib/strsep.c new file +41 -0
41 lines not on this page · raw message
Hi Jan,
Quoted 22 lines · Jan Beulich
This is to dissolve / move
xen/common/string.c. One benefit of moving these functions into an archive is that we can drop some of the related __HAVE_ARCH_* #define-s: By living in an archive, the per-arch functions will preempt any loading of the respective functions (objects) from the archive. (Down the road we may want to move the per-arch functions into archives as well, at which point the per-arch archive(s) would need to be specified ahead of the common one(s) to the linker.)The only change in v2 is adjustment to all of the commit messages.
01: lib: move
memset()
02: lib: movememcpy()
03: lib: movememmove()
04: lib: movememcmp()
05: lib: movememchr()
06: lib: movememchr_inv()
07: lib: movestrlen()
08: lib: movestrnlen()
09: lib: movestrcmp()
10: lib: movestrncmp()
11: lib: movestrlcpy()
12: lib: movestrlcat()
Quoted 8 lines
13: lib: move
strchr()
14: lib: movestrrchr()
15: lib: movestrstr()
16: lib: movestrcasecmp()
17: lib: move/renamestrnicmp()tostrncasecmp()
18: lib: movestrspn()
19: lib: movestrpbrk()
20: lib: movestrsep()
From the series:
Cheers,
Signature · 1 line
Julien Grall