feat: initial version
This commit is contained in:
parent
5cad2db883
commit
6428ed06b0
16 changed files with 263 additions and 0 deletions
37
srcs/ft_memset32.c
Normal file
37
srcs/ft_memset32.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void *ft_memset32(void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *ptr = (unsigned char *)s;
|
||||
uint32_t pattern;
|
||||
uint32_t *long_ptr;
|
||||
|
||||
unsigned char byte = (unsigned char)c;
|
||||
|
||||
while (n > 0 && ((uintptr_t)ptr % 4 != 0))
|
||||
{
|
||||
*ptr++ = byte;
|
||||
n--;
|
||||
}
|
||||
|
||||
if (n >= 4)
|
||||
{
|
||||
pattern = byte;
|
||||
pattern |= pattern << 8;
|
||||
pattern |= pattern << 16;
|
||||
|
||||
long_ptr = (uint32_t *)ptr;
|
||||
while (n >= 4)
|
||||
{
|
||||
*long_ptr++ = pattern;
|
||||
n -= 4;
|
||||
}
|
||||
ptr = (unsigned char *)long_ptr;
|
||||
}
|
||||
|
||||
while (n--)
|
||||
*ptr++ = byte;
|
||||
|
||||
return s;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue