Newer
Older
Scratch / lockwasher / src / lib / libc / string / memset.c
@Christopher W. Olsen Christopher W. Olsen on 25 Oct 2019 389 bytes Scratch
#include <sys/types.h>
#include <string.h>

void * memset(void * dst, int c, size_t length)
{
    size_t x = length >> 2;
    size_t y = length & 0xf;
    size_t i;
    
    unsigned int newC = (c << 24) | (c << 16) | (c << 8) | (c);
     
    for (i = 0; i < x; i++)
	((unsigned long *)dst)[i] = newC;

    for (i = 0; i < y; i++)
	((char *) dst)[length-y+i] = c;
    
    return dst;
}