lib: Add strcspn function
PATCH 1/4 lib: Add strcspn function
This will be used by future patches.
--- xen/include/xen/string.h | 1 + xen/lib/Makefile | 1 + xen/lib/strcspn.c | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 xen/lib/strcspn.c
xen/include/xen/string.h +1 -0
@@ -26,6 +26,7 @@ size_t strnlen(const char *s, size_t count);char *strpbrk (const char *cs,const char *ct);char *strsep (char **s,const char *ct);size_t strspn (const char *s,const char *accept); +size_t strcspn (const char *s,const char *reject);void *memset (void *s,int c,size_t n);void *memcpy (void *dest,const void *src,size_t n);
xen/lib/Makefile +1 -0
@@ -22,6 +22,7 @@ lib-y += sort.o lib-y += strcasecmp.o lib-y += strchr.o lib-y += strcmp.o +lib-y += strcspn.o lib-y += strlcat.o lib-y += strlcpy.o lib-y += strlen.o
xen/lib/strcspn.c new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strcspn - Calculate the length of the initial substring of @s which does not contain letters in @reject +* @s: The string to be searched +* @reject: The string to avoid +*/ +size_t strcspn (const char *s,const char *reject) +{ +const char *p; + +for (p = s; *p !='\0' ; ++p) { +if (strchr (reject, *p)) +break ; + } +return p - s; +}
Signature · 1 line
2.42.0
xen/include/xen/string.h size_t strnlen(const char *s, size_t count); · line 32
Quoted 12 lines · Kevin Lampis
xen/include/xen/string.h +1
-0@@ -26,6 +26,7 @@ size_t strnlen(const char *s, size_t count);char *strpbrk (const char *cs,const char *ct);char *strsep (char **s,const char *ct);size_t strspn (const char *s,const char *accept); +size_t strcspn (const char *s,const char *reject);void *memset (void *s,int c,size_t n);void *memcpy (void *dest,const void *src,size_t n);
Lower down in this file, you also want a define aliasing to __builtin_strcspn() in the style of the others you'll see. In turn, you'll need to...
Quoted 9 lines
xen/lib/strcspn.c new file +3
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 1991, 1992 Linus Torvalds
xen/lib/strcspn.c line 13
Quoted 10 lines
xen/lib/strcspn.c new file +10
-0+*/ + +#include <xen/string.h> + +/** +* strcspn - Calculate the length of the initial substring of @s which does not contain letters in @reject +* @s: The string to be searched +* @reject: The string to avoid +*/ +size_t strcspn (const char *s,const char *reject)
... write this as "size_t (strcspn)(const ..."
to avoid the macro expansion in this one place.
~Andrew
PATCH v2 1/1 lib: Add strcspn function
From: Ross Lagerwall <[email protected]>
This will be used by future patches.
---
Changes in v2:
- Add alias to __builtin_strcspn
--- xen/include/xen/string.h | 5 +++++ xen/lib/Makefile | 1 + xen/lib/strcspn.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 xen/lib/strcspn.c
xen/include/xen/string.h +5 -0
@@ -26,6 +26,7 @@ size_t strnlen(const char *s, size_t count);char *strpbrk (const char *cs,const char *ct);char *strsep (char **s,const char *ct);size_t strspn (const char *s,const char *accept); +size_t strcspn (const char *s,const char *reject);void *memset (void *s,int c,size_t n);void *memcpy (void *dest,const void *src,size_t n);
@@ -68,6 +69,10 @@ void *memchr_inv(const void *s, int c, size_t n);#define strlen (s1) __builtin_strlen(s1)#endif +#ifndef __HAVE_ARCH_STRCSPN +#define strcspn (s, r) __builtin_strcspn(s, r) +#endif +#ifndef __HAVE_ARCH_MEMSET#define memset (s, c, n) __builtin_memset(s, c, n)#endif
xen/lib/Makefile +1 -0
@@ -22,6 +22,7 @@ lib-y += sort.o lib-y += strcasecmp.o lib-y += strchr.o lib-y += strcmp.o +lib-y += strcspn.o lib-y += strlcat.o lib-y += strlcpy.o lib-y += strlen.o
xen/lib/strcspn.c new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <xen/string.h> + +/** +* strcspn - Calculate the length of the initial substring of @s which does not contain letters in @reject +* @s: The string to be searched +* @reject: The string to avoid +*/ +size_t (strcspn)(const char *s,const char *reject) +{ +const char *p; + +for (p = s; *p !='\0' ; ++p) { +if (strchr (reject, *p)) +break ; + } +return p - s; +}
Signature · 1 line
2.42.0
Quoted 6 lines · Kevin Lampis
From: Ross Lagerwall <[email protected]>
This will be used by future patches.
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Kevin Lampis <[email protected]>
Quoted 9 lines · Andrew Cooper
Quoted 6 lines · Kevin Lampis
From: Ross Lagerwall <[email protected]>
This will be used by future patches.
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Kevin Lampis <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
Like for the sha256 change - isn't this introducing a new Misra violation until a caller appears? Or are we deeming this okay here (unlike in the sha256 case) because the CU will only be included in the final image if a caller actually exists?
Jan