1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| | #include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "word.h"
/**
* memset - Word sized c standard memset.
* @d: Destination
* @c: Charater to set
* @n: Max size to set to @c in @d
*/
void *memset(void *d, int c, size_t n)
{
unsigned char *cd = (unsigned char *)d;
const size_t wc = WORD_LSB_ONE * (unsigned char)c;
size_t *wd;
c = (unsigned char)c;
for (; (uintptr_t)cd % sizeof(size_t); *cd++ = c, n--)
if (!n) return d;
for (wd = (size_t *)cd; n >= sizeof(size_t)
; *wd++ = wc, n -= sizeof(size_t));
for (cd = (unsigned char *)wd; n; *cd++ = c, n--);
return d;
}
|