|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2] lib: Add strcspn function
From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
This will be used by future patches.
Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
Signed-off-by: Kevin Lampis <kevin.lampis@xxxxxxxxx>
---
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
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |