lib: move memchr()

Allow the function to be individually linkable, discardable, and
overridable.

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:45:21 +02:00
1 parent 880d89fbfe
commit ff2e37e64c
3 files changed
+36 -22

No files matched your search

-22
View File
@@ -311,28 +311,6 @@ char *(strstr)(const char *s1, const char *s2)
}
#endif
#ifndef __HAVE_ARCH_MEMCHR
/**
* memchr - Find a character in an area of memory.
* @s: The memory area
* @c: The byte to search for
* @n: The size of the area.
*
* returns the address of the first occurrence of @c, or %NULL
* if @c is not found
*/
void *(memchr)(const void *s, int c, size_t n)
{
const unsigned char *p = s;
while (n--)
if ((unsigned char)c == *p++)
return (void *)(p - 1);
return NULL;
}
#endif
/**
* memchr_inv - Find an unmatching character in an area of memory.
* @s: The memory area
+1
View File
@@ -4,6 +4,7 @@ lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o
lib-y += list-sort.o
lib-y += memchr.o
lib-y += memcmp.o
lib-y += memcpy.o
lib-y += memmove.o
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (C) 1991, 1992 Linus Torvalds
*/
#include <xen/string.h>
/**
* memchr - Find a character in an area of memory.
* @s: The memory area
* @c: The byte to search for
* @n: The size of the area.
*
* returns the address of the first occurrence of @c, or %NULL
* if @c is not found
*/
void *(memchr)(const void *s, int c, size_t n)
{
const unsigned char *p = s;
while (n--)
if ((unsigned char)c == *p++)
return (void *)(p - 1);
return NULL;
}
/*
* 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.