diff options
Diffstat (limited to 'mempsetelem.c')
-rw-r--r-- | mempsetelem.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/mempsetelem.c b/mempsetelem.c new file mode 100644 index 0000000..d431604 --- /dev/null +++ b/mempsetelem.c @@ -0,0 +1,58 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" +#ifndef TEST + + +void * +libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems) +{ + switch (size) { + case 0: + return buf_; + case 1: + return &((char *)memset(buf_, *(char *)item, nitems))[nitems]; + case 2: + { + uint16_t *buf = buf_, e = *(uint16_t *)item; + uint16_t *end = &buf[nitems]; + for (; buf != end; buf++) + *buf = e; + return buf; + } + case 4: + { + uint32_t *buf = buf_, e = *(uint32_t *)item; + uint32_t *end = &buf[nitems]; + for (; buf != end; buf++) + *buf = e; + return buf; + } + case 8: + { + uint64_t *buf = buf_, e = *(uint64_t *)item; + uint64_t *end = &buf[nitems]; + for (; buf != end; buf++) + *buf = e; + return buf; + } + default: + { + char *buf = buf_; + for (; nitems--; buf += size) + memcpy(buf, item, size); + return buf; + } + } +} + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif |