[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/4] lib: Add strcspn function



This will be used by future patches.

Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
Signed-off-by: Kevin Lampis <kevin.lampis@xxxxxxxxx>
---
 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

diff --git a/xen/include/xen/string.h b/xen/include/xen/string.h
index bd4a8f48e9..70c231b690 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);
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..42e3308dac
--- /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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.