1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:34:57 +00:00

LibC: Implement memccpy

This commit is contained in:
René Hickersberger 2023-06-24 11:56:09 +02:00 committed by Tim Schumacher
parent ad560cff0f
commit f2bd3904da
2 changed files with 14 additions and 0 deletions

View file

@ -151,6 +151,19 @@ void* memcpy(void* dest_ptr, void const* src_ptr, size_t n)
#endif
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/memccpy.html
void* memccpy(void* dest_ptr, void const* src_ptr, int c, size_t n)
{
u8* pd = static_cast<u8*>(dest_ptr);
u8 const* ps = static_cast<u8 const*>(src_ptr);
for (; n--; pd++, ps++) {
*pd = *ps;
if (*pd == static_cast<u8>(c))
return pd + 1;
}
return nullptr;
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/memset.html
// For x86-64, an optimized ASM implementation is found in ./arch/x86_64/memset.S
#if ARCH(X86_64)

View file

@ -34,6 +34,7 @@ int strncmp(char const*, char const*, size_t);
int memcmp(void const*, void const*, size_t);
int timingsafe_memcmp(void const*, void const*, size_t);
void* memcpy(void*, void const*, size_t);
void* memccpy(void*, void const*, int, size_t);
void* memmove(void*, void const*, size_t);
void* memchr(void const*, int c, size_t);
void* memmem(void const* haystack, size_t, void const* needle, size_t);