aboutsummaryrefslogtreecommitdiffstats
path: root/mempsetelem.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-10-20 22:12:59 +0200
committerMattias Andrée <maandree@kth.se>2018-10-20 22:12:59 +0200
commit24f9649c1f4692dd0cea64170a015a214197c926 (patch)
tree686e5c5c5bea6e69ff5894f10e6dc5fb0124b97f /mempsetelem.c
parentAdd man pages for memeq, mempcpy and mempset (diff)
downloadlibsimple-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.c58
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