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>
#define LOWS(x) (((x)*0-1) / 255)
void *memset(void *d, int c, size_t n)
{
unsigned char *cd = (unsigned char *)d;
const size_t wc = LOWS(wc) * (unsigned char)c;
size_t *wd;
c = (unsigned char)c;
if (n < sizeof(size_t)) goto bytewise;
for (; (uintptr_t)d % sizeof(size_t); *cd++ = c, n--);
for (wd = (size_t *)cd
; n >= sizeof(size_t)
; *wd++ = wc, n -= sizeof(size_t));
cd = (unsigned char *)wd;
bytewise:
for (; n; *cd++ = c, n--);
return d;
}
|