#include #include #include #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; }