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
From: Ross Lagerwall <ross.lagerwall@citrix.com>
This will be used by future patches.
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Kevin Lampis <kevin.lampis@cloud.com>
---
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
diff --git a/xen/include/xen/string.h b/xen/include/xen/string.h
index bd4a8f48e9..0ad65303da 100644
--- a/xen/include/xen/string.h
+++ b/xen/include/xen/string.h
@@ -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
diff --git a/xen/lib/Makefile b/xen/lib/Makefile
index 76dc86fab0..5ccb1e5241 100644
--- a/xen/lib/Makefile
+++ b/xen/lib/Makefile
@@ -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
diff --git a/xen/lib/strcspn.c b/xen/lib/strcspn.c
new file mode 100644
index 0000000000..d572931f54
--- /dev/null
+++ b/xen/lib/strcspn.c
@@ -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;
+}
--
2.42.0
On 07/05/2025 3:45 pm, Kevin Lampis wrote: > From: Ross Lagerwall <ross.lagerwall@citrix.com> > > This will be used by future patches. > > Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com> > Signed-off-by: Kevin Lampis <kevin.lampis@cloud.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
On 08.05.2025 11:43, Andrew Cooper wrote: > On 07/05/2025 3:45 pm, Kevin Lampis wrote: >> From: Ross Lagerwall <ross.lagerwall@citrix.com> >> >> This will be used by future patches. >> >> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com> >> Signed-off-by: Kevin Lampis <kevin.lampis@cloud.com> > > Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> 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
© 2016 - 2025 Red Hat, Inc.