ft_strace/libft/ft_memset.c

42 lines
1.4 KiB
C
Executable file

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 15:40:57 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:13 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
char *str;
unsigned long long *str_packed;
unsigned long long cccccccc;
size_t i;
str = (char *)s;
while (n % sizeof(unsigned long long))
{
*str++ = (unsigned char)c;
n--;
}
str_packed = (unsigned long long *)str;
cccccccc = 0;
i = 0;
while (i < sizeof(unsigned long long))
{
cccccccc |= ((unsigned long long)(unsigned char)c) << (i * 8);
i++;
}
while (n >= sizeof(unsigned long long))
{
*str_packed++ = cccccccc;
n -= sizeof(unsigned long long);
}
return (s);
}