#include "src/string/memccpy.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/null_check.h"
#include <stddef.h>
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void *, memccpy,
(void *__restrict dest, const void *__restrict src, int c,
size_t count)) {
if (count) {
LIBC_CRASH_ON_NULLPTR(dest);
LIBC_CRASH_ON_NULLPTR(src);
}
unsigned char end = static_cast<unsigned char>(c);
const unsigned char *uc_src = static_cast<const unsigned char *>(src);
unsigned char *uc_dest = static_cast<unsigned char *>(dest);
size_t i = 0;
for (; i < count && uc_src[i] != end; ++i)
uc_dest[i] = uc_src[i];
if (i < count) {
uc_dest[i] = uc_src[i];
return uc_dest + i + 1;
}
return nullptr;
}
}