lib: move strspn()

Allow 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.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
This commit is contained in:
Jan Beulich committed 2021-04-22 14:52:57 +02:00
1 parent 3acd02a50b
commit b3573bbd2e
3 files changed
+41 -27

No files matched your search

-27
View File
@@ -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
+1
View File
@@ -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
+40
View File
@@ -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:
*/
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.