diff options
author | Mattias Andrée <maandree@kth.se> | 2018-10-20 22:12:59 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-10-20 22:12:59 +0200 |
commit | 24f9649c1f4692dd0cea64170a015a214197c926 (patch) | |
tree | 686e5c5c5bea6e69ff5894f10e6dc5fb0124b97f /mempsetelem.c | |
parent | Add man pages for memeq, mempcpy and mempset (diff) | |
download | libsimple-24f9649c1f4692dd0cea64170a015a214197c926.tar.gz libsimple-24f9649c1f4692dd0cea64170a015a214197c926.tar.bz2 libsimple-24f9649c1f4692dd0cea64170a015a214197c926.tar.xz |
Add mempsetelem and memsetelem and add fix and tests for memelem and memrelem
Signed-off-by: Mattias Andrée <maandree@kth.se>
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 |