From 24f9649c1f4692dd0cea64170a015a214197c926 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 20 Oct 2018 22:12:59 +0200 Subject: Add mempsetelem and memsetelem and add fix and tests for memelem and memrelem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- mempsetelem.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 mempsetelem.c (limited to 'mempsetelem.c') 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 -- cgit v1.2.3-70-g09d2